@@ -5,13 +5,23 @@ use agg_mode_sdk::{
55 types:: Network ,
66} ;
77use alloy:: hex;
8- use clap:: { self , Args } ;
8+ use clap:: { command , Args , Subcommand } ;
99use std:: path:: PathBuf ;
1010
11- use crate :: commands:: helpers:: { parse_network, ProvingSystemArg } ;
11+ use crate :: commands:: helpers:: parse_network;
12+
13+ #[ derive( Debug , Subcommand ) ]
14+ pub enum VerifyCommand {
15+ #[ command( name = "sp1" ) ]
16+ SP1 ( VerifySP1Args ) ,
17+ #[ command( name = "risc0" ) ]
18+ Risc0 ( VerifyRisc0Args ) ,
19+ #[ command( name = "zisk" ) ]
20+ Zisk ( VerifyZiskArgs ) ,
21+ }
1222
1323#[ derive( Debug , Clone , Args ) ]
14- pub struct VerifyOnChainArgs {
24+ pub struct VerifySP1Args {
1525 #[ arg( short = 'n' , long = "network" , default_value = "devnet" , value_parser = parse_network) ]
1626 network : Network ,
1727 #[ arg( long = "rpc-url" ) ]
@@ -20,41 +30,93 @@ pub struct VerifyOnChainArgs {
2030 beacon_url : String ,
2131 #[ arg( long = "from-block" ) ]
2232 from_block : Option < u64 > ,
23- #[ arg( long = "proving-system" ) ]
24- proving_system : ProvingSystemArg ,
25- #[ arg(
26- name = "Program verification key hash" ,
27- long = "vk-hash" ,
28- required = true
29- ) ]
30- program_vk : PathBuf ,
31- #[ arg( name = "Public input file name" , long = "public-inputs" ) ]
32- pub_input_file_name : Option < PathBuf > ,
33+ #[ arg( long = "vk-hash" ) ]
34+ vk_hash : PathBuf ,
35+ #[ arg( long = "public-inputs" ) ]
36+ public_inputs : PathBuf ,
3337}
3438
35- pub async fn run ( args : VerifyOnChainArgs ) {
36- let program_id_key: [ u8 ; 32 ] = std:: fs:: read ( & args. program_vk )
37- . expect ( "to read program vk file" )
39+ #[ derive( Debug , Clone , Args ) ]
40+ pub struct VerifyRisc0Args {
41+ #[ arg( short = 'n' , long = "network" , default_value = "devnet" , value_parser = parse_network) ]
42+ network : Network ,
43+ #[ arg( long = "rpc-url" ) ]
44+ rpc_url : String ,
45+ #[ arg( long = "beacon-url" ) ]
46+ beacon_url : String ,
47+ #[ arg( long = "from-block" ) ]
48+ from_block : Option < u64 > ,
49+ #[ arg( long = "image-id" ) ]
50+ image_id : PathBuf ,
51+ #[ arg( long = "public-inputs" ) ]
52+ public_inputs : PathBuf ,
53+ }
54+
55+ #[ derive( Debug , Clone , Args ) ]
56+ pub struct VerifyZiskArgs {
57+ #[ arg( short = 'n' , long = "network" , default_value = "devnet" , value_parser = parse_network) ]
58+ network : Network ,
59+ #[ arg( long = "rpc-url" ) ]
60+ rpc_url : String ,
61+ #[ arg( long = "beacon-url" ) ]
62+ beacon_url : String ,
63+ #[ arg( long = "from-block" ) ]
64+ from_block : Option < u64 > ,
65+ #[ arg( short = 'p' , long = "proof" ) ]
66+ proof : PathBuf ,
67+ }
68+
69+ pub async fn run_sp1 ( args : VerifySP1Args ) {
70+ tracing:: info!( "Verifying SP1 proof on {:?}..." , args. network) ;
71+
72+ let vk: [ u8 ; 32 ] = std:: fs:: read ( & args. vk_hash )
73+ . expect ( "to read vk hash file" )
3874 . try_into ( )
39- . expect ( "Invalid hexadecimal encoded vk hash" ) ;
75+ . expect ( "Invalid vk hash (expected 32 bytes) " ) ;
4076
41- let Some ( pub_inputs_file_name) = args. pub_input_file_name else {
42- tracing:: error!( "Public input file not provided" ) ;
43- return ;
44- } ;
45- let public_inputs =
46- std:: fs:: read ( & pub_inputs_file_name) . expect ( "to read program public inputs file" ) ;
77+ let public_inputs = std:: fs:: read ( & args. public_inputs ) . expect ( "to read public inputs file" ) ;
4778
48- let provider =
49- ProofAggregationServiceProvider :: new ( args. network , args. rpc_url , args. beacon_url ) ;
79+ let verification_data = AggregationModeVerificationData :: SP1 { vk, public_inputs } ;
5080
51- let verification_data = AggregationModeVerificationData :: SP1 {
52- vk : program_id_key,
53- public_inputs,
54- } ;
81+ verify_proof ( args. network , args. rpc_url , args. beacon_url , args. from_block , verification_data) . await ;
82+ }
83+
84+ pub async fn run_risc0 ( args : VerifyRisc0Args ) {
85+ tracing:: info!( "Verifying Risc0 proof on {:?}..." , args. network) ;
86+
87+ let image_id: [ u8 ; 32 ] = std:: fs:: read ( & args. image_id )
88+ . expect ( "to read image id file" )
89+ . try_into ( )
90+ . expect ( "Invalid image id (expected 32 bytes)" ) ;
91+
92+ let public_inputs = std:: fs:: read ( & args. public_inputs ) . expect ( "to read public inputs file" ) ;
93+
94+ let verification_data = AggregationModeVerificationData :: Risc0 { image_id, public_inputs } ;
95+
96+ verify_proof ( args. network , args. rpc_url , args. beacon_url , args. from_block , verification_data) . await ;
97+ }
98+
99+ pub async fn run_zisk ( args : VerifyZiskArgs ) {
100+ tracing:: info!( "Verifying Zisk proof on {:?}..." , args. network) ;
101+
102+ let proof = std:: fs:: read ( & args. proof ) . expect ( "to read proof file" ) ;
103+
104+ let verification_data = AggregationModeVerificationData :: Zisk { proof } ;
105+
106+ verify_proof ( args. network , args. rpc_url , args. beacon_url , args. from_block , verification_data) . await ;
107+ }
108+
109+ async fn verify_proof (
110+ network : Network ,
111+ rpc_url : String ,
112+ beacon_url : String ,
113+ from_block : Option < u64 > ,
114+ verification_data : AggregationModeVerificationData ,
115+ ) {
116+ let provider = ProofAggregationServiceProvider :: new ( network, rpc_url, beacon_url) ;
55117
56118 let proof_status = match provider
57- . check_proof_verification ( args . from_block , verification_data)
119+ . check_proof_verification ( from_block, verification_data)
58120 . await
59121 {
60122 Ok ( res) => res,
0 commit comments