1- use aligned_sdk:: core :: {
2- constants :: INSTANT_MAX_FEE_BATCH_SIZE ,
3- types :: { AlignedVerificationData , Signer , SigningKey , VerificationData , Wallet } ,
1+ use aligned_sdk:: {
2+ core :: types :: { AlignedVerificationData , Signer , SigningKey , VerificationData , Wallet } ,
3+ sdk :: estimate_fee ,
44} ;
5- use primitive_types:: U256 ;
5+ use alloy:: {
6+ eips:: BlockNumberOrTag ,
7+ primitives:: Address ,
8+ providers:: { Provider , ProviderBuilder , WsConnect } ,
9+ rpc:: types:: Filter ,
10+ } ;
11+ use futures_util:: StreamExt ;
12+ use sp1_sdk:: { HashableKey , SP1VerifyingKey } ;
613
714pub async fn send_proof_to_be_verified_on_aligned (
815 proof : & sp1_sdk:: SP1ProofWithPublicValues ,
@@ -25,41 +32,62 @@ pub async fn send_proof_to_be_verified_on_aligned(
2532 . await
2633 . expect ( "Retrieve nonce from aligned batcher" ) ;
2734
28- let aligned_verification_data = aligned_sdk:: sdk:: submit (
29- network,
30- & verification_data,
31- U256 :: from ( INSTANT_MAX_FEE_BATCH_SIZE as u64 ) ,
32- wallet,
33- nonce,
35+ let max_fee = estimate_fee (
36+ "https://ethereum-holesky-rpc.publicnode.com" . into ( ) ,
37+ aligned_sdk:: core:: types:: FeeEstimationType :: Instant ,
3438 )
3539 . await
36- . expect ( "Proof to be sent" ) ;
40+ . expect ( "Max fee to be retrieved" ) ;
41+
42+ let aligned_verification_data =
43+ aligned_sdk:: sdk:: submit ( network, & verification_data, max_fee, wallet, 0 . into ( ) )
44+ . await
45+ . expect ( "Proof to be sent" ) ;
3746
3847 aligned_verification_data
3948}
4049
41- pub async fn wait_until_proof_is_aggregated ( ) -> u64 {
42- // let rpc_url = "wss://eth-mainnet.g.alchemy.com/v2/your-api-key";
43- // let ws = WsConnect::new(rpc_url);
44- // let provider = ProviderBuilder::new().on_ws(ws).await.unwrap();
50+ pub async fn wait_until_proof_is_aggregated (
51+ network : aligned_sdk:: core:: types:: Network ,
52+ eth_rpc_url : String ,
53+ beacon_client_url : String ,
54+ proof : & sp1_sdk:: SP1ProofWithPublicValues ,
55+ vk : & SP1VerifyingKey ,
56+ ) -> Option < Vec < [ u8 ; 32 ] > > {
57+ let rpc_url = "" ;
58+ let ws = WsConnect :: new ( rpc_url) ;
59+ let provider = ProviderBuilder :: new ( ) . on_ws ( ws) . await . unwrap ( ) ;
60+
61+ let aligned_proof_agg_address =
62+ Address :: from ( network. get_aligned_proof_agg_service_address ( ) . 0 ) ;
63+
64+ let filter = Filter :: new ( )
65+ . address ( aligned_proof_agg_address)
66+ . event ( "AggregatedProofVerified(bytes32,bytes32)" )
67+ . from_block ( BlockNumberOrTag :: Latest ) ;
4568
46- // let uniswap_token_address =
47- // Address::from_str("1f9840a85d5aF5bf1D1762F925BDADdC4201F984").unwrap();
69+ // Subscribe to logs.
70+ let sub = provider. subscribe_logs ( & filter) . await . unwrap ( ) ;
71+ let mut stream = sub. into_stream ( ) ;
4872
49- // let filter = Filter::new()
50- // .address(uniswap_token_address)
51- // // By specifying an `event` or `event_signature` we listen for a specific event of the
52- // // contract. In this case the `Transfer(address,address,uint256)` event.
53- // .event("Transfer(address,address,uint256)")
54- // .from_block(BlockNumberOrTag::Latest);
73+ let verification_data = aligned_sdk:: sdk:: aggregation:: AggregationModeVerificationData :: SP1 {
74+ vk : vk. hash_bytes ( ) ,
75+ public_inputs : proof. public_values . to_vec ( ) ,
76+ } ;
5577
56- // // Subscribe to logs.
57- // let sub = provider.subscribe_logs(&filter).await.unwrap();
58- // let mut stream = sub.into_stream();
78+ let mut merkle_path = None ;
5979
60- // while let Some(log) = stream.next().await {
61- // println!("Uniswap token logs: {log:?}");
62- // }
80+ while let Some ( _) = stream. next ( ) . await {
81+ merkle_path = aligned_sdk:: sdk:: aggregation:: get_merkle_path_for_proof (
82+ network. clone ( ) ,
83+ eth_rpc_url. clone ( ) ,
84+ beacon_client_url. clone ( ) ,
85+ None ,
86+ & verification_data,
87+ )
88+ . await
89+ . unwrap ( ) ;
90+ }
6391
64- 0
92+ merkle_path
6593}
0 commit comments