11use aligned_sdk:: {
2- core:: types:: { AlignedVerificationData , Signer , SigningKey , VerificationData , Wallet } ,
3- sdk:: estimate_fee,
2+ core:: types:: { AlignedVerificationData , Signer , VerificationData , Wallet } ,
3+ sdk:: { estimate_fee, get_chain_id } ,
44} ;
55use alloy:: {
66 eips:: BlockNumberOrTag ,
7- hex,
87 primitives:: Address ,
98 providers:: { Provider , ProviderBuilder , WsConnect } ,
109 rpc:: types:: Filter ,
1110} ;
1211use futures_util:: StreamExt ;
1312use sp1_sdk:: { HashableKey , SP1VerifyingKey } ;
1413
14+ use crate :: Config ;
15+
1516pub async fn send_proof_to_be_verified_on_aligned (
17+ config : & Config ,
1618 proof : & sp1_sdk:: SP1ProofWithPublicValues ,
1719 vm_program_code : Vec < u8 > ,
18- network : aligned_sdk:: core:: types:: Network ,
19- wallet : Wallet < SigningKey > ,
2020) -> AlignedVerificationData {
2121 let proof = bincode:: serialize ( proof) . expect ( "Serialize sp1 proof to binary" ) ;
22+ let chain_id = get_chain_id ( & config. eth_rpc_url ) . await . unwrap ( ) ;
23+ let wallet = Wallet :: decrypt_keystore (
24+ & config. private_key_store_path ,
25+ & config. private_key_store_password ,
26+ )
27+ . expect ( "Keystore to be `cast wallet` compliant" )
28+ . with_chain_id ( chain_id) ;
2229
2330 let verification_data = VerificationData {
2431 proof_generator_addr : wallet. address ( ) ,
@@ -29,38 +36,41 @@ pub async fn send_proof_to_be_verified_on_aligned(
2936 verification_key : None ,
3037 } ;
3138
32- let nonce = aligned_sdk:: sdk:: get_nonce_from_batcher ( network. clone ( ) , wallet. address ( ) )
39+ let nonce = aligned_sdk:: sdk:: get_nonce_from_batcher ( config . network . clone ( ) , wallet. address ( ) )
3340 . await
3441 . expect ( "Retrieve nonce from aligned batcher" ) ;
3542
3643 let max_fee = estimate_fee (
37- "https://ethereum-holesky-rpc.publicnode.com" . into ( ) ,
44+ & config . eth_rpc_url ,
3845 aligned_sdk:: core:: types:: FeeEstimationType :: Instant ,
3946 )
4047 . await
4148 . expect ( "Max fee to be retrieved" ) ;
4249
43- let aligned_verification_data =
44- aligned_sdk:: sdk:: submit ( network, & verification_data, max_fee, wallet, nonce. into ( ) )
45- . await
46- . expect ( "Proof to be sent" ) ;
50+ let aligned_verification_data = aligned_sdk:: sdk:: submit (
51+ config. network . clone ( ) ,
52+ & verification_data,
53+ max_fee,
54+ wallet,
55+ nonce. into ( ) ,
56+ )
57+ . await
58+ . expect ( "Proof to be sent" ) ;
4759
4860 aligned_verification_data
4961}
5062
5163pub async fn wait_until_proof_is_aggregated (
52- network : aligned_sdk:: core:: types:: Network ,
53- eth_rpc_url : String ,
54- beacon_client_url : String ,
64+ config : & Config ,
5565 proof : & sp1_sdk:: SP1ProofWithPublicValues ,
5666 vk : & SP1VerifyingKey ,
57- ) -> Option < Vec < [ u8 ; 32 ] > > {
58- let ws_rpc_url = "wss://ethereum-holesky-rpc.publicnode.com" ;
67+ ) -> Vec < [ u8 ; 32 ] > {
68+ let ws_rpc_url = & config . ws_eth_rpc_url ;
5969 let ws = WsConnect :: new ( ws_rpc_url) ;
6070 let provider = ProviderBuilder :: new ( ) . on_ws ( ws) . await . unwrap ( ) ;
6171
6272 let aligned_proof_agg_address =
63- Address :: from ( network. get_aligned_proof_agg_service_address ( ) . 0 ) ;
73+ Address :: from ( config . network . get_aligned_proof_agg_service_address ( ) . 0 ) ;
6474
6575 let filter = Filter :: new ( )
6676 . address ( aligned_proof_agg_address)
@@ -75,21 +85,21 @@ pub async fn wait_until_proof_is_aggregated(
7585 vk : vk. hash_bytes ( ) ,
7686 public_inputs : proof. public_values . to_vec ( ) ,
7787 } ;
78-
79- let mut merkle_path = None ;
88+
89+ let mut merkle_path = vec ! [ ] ;
8090
8191 while let Some ( _) = stream. next ( ) . await {
8292 if let Some ( merkle_proof) = aligned_sdk:: sdk:: aggregation:: get_merkle_path_for_proof (
83- network. clone ( ) ,
84- eth_rpc_url. clone ( ) ,
85- beacon_client_url. clone ( ) ,
93+ config . network . clone ( ) ,
94+ config . eth_rpc_url . clone ( ) ,
95+ config . beacon_client_url . clone ( ) ,
8696 None ,
8797 & verification_data,
8898 )
8999 . await
90- . unwrap ( )
100+ . expect ( "Get merkle path for proof" )
91101 {
92- merkle_path = Some ( merkle_proof) ;
102+ merkle_path = merkle_proof;
93103 break ;
94104 } ;
95105 }
0 commit comments