Skip to content

Commit d11b0a7

Browse files
committed
feat: verify agg proof command in cli
1 parent b59f572 commit d11b0a7

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

aggregation_mode/cli/src/commands/verify.rs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
use agg_mode_sdk::types::Network;
1+
use agg_mode_sdk::{
2+
blockchain::{
3+
provider::ProofAggregationServiceProvider, AggregationModeVerificationData, ProofStatus,
4+
},
5+
types::Network,
6+
};
7+
use alloy::hex;
28
use clap::{self, Args};
39
use std::path::PathBuf;
410

@@ -18,10 +24,56 @@ pub struct VerifyOnChainArgs {
1824
proving_system: ProvingSystemArg,
1925
#[arg(name = "Program verification key hash", long = "vk", required = true)]
2026
program_vk: PathBuf,
21-
#[arg(long = "vk")]
22-
verifying_key_path: PathBuf,
2327
#[arg(name = "Public input file name", long = "public-input")]
2428
pub_input_file_name: Option<PathBuf>,
2529
}
2630

27-
pub async fn run(args: VerifyOnChainArgs) {}
31+
pub async fn run(args: VerifyOnChainArgs) {
32+
let program_id_key: [u8; 32] = std::fs::read(&args.program_vk)
33+
.expect("to read program vk file")
34+
.try_into()
35+
.expect("Invalid hexadecimal encoded vk hash");
36+
37+
let Some(pub_inputs_file_name) = args.pub_input_file_name else {
38+
tracing::error!("Public input file not provided");
39+
return;
40+
};
41+
let public_inputs =
42+
std::fs::read(&pub_inputs_file_name).expect("to read program public inputs file");
43+
44+
let provider =
45+
ProofAggregationServiceProvider::new(args.network, args.rpc_url, args.beacon_url);
46+
47+
let verification_data = AggregationModeVerificationData::SP1 {
48+
vk: program_id_key,
49+
public_inputs,
50+
};
51+
52+
let proof_status = match provider
53+
.check_proof_verification(args.from_block, verification_data)
54+
.await
55+
{
56+
Ok(res) => res,
57+
Err(e) => {
58+
tracing::error!("Error while trying to verify proof {:?}", e);
59+
return;
60+
}
61+
};
62+
63+
match proof_status {
64+
ProofStatus::Verified { merkle_root, .. } => {
65+
tracing::info!(
66+
"Your proof has been verified in the aggregated proof with merkle root 0x{}",
67+
hex::encode(merkle_root)
68+
);
69+
}
70+
ProofStatus::Invalid => {
71+
tracing::error!(
72+
"Your proof was found in the blob but the Merkle Root verification failed."
73+
)
74+
}
75+
ProofStatus::NotFound => {
76+
tracing::error!("Your proof wasn't found in the logs. Try specifying an earlier `from_block` to search further back in history.")
77+
}
78+
}
79+
}

aggregation_mode/sdk/src/blockchain/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ mod types;
55

66
// Makes only the two types on this use public
77
pub use types::{
8-
AggregationModeProvingSystem, AggregationModeVerificationData, ProofVerificationAggModeError,
8+
AggregationModeProvingSystem, AggregationModeVerificationData, ProofStatus,
9+
ProofVerificationAggModeError,
910
};

crates/sdk/src/aggregation_layer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use helpers::{fetch_verified_proofs_events, get_blob_data_from_verified_proof_ev
1818
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
1919
use types::Hash32;
2020

21+
#[derive(Debug, Clone)]
2122
pub enum ProofStatus {
2223
Verified {
2324
merkle_root: [u8; 32],

0 commit comments

Comments
 (0)