1- use crate :: aligned:: { check_proof_proof_aggregation_status, send_proof_to_be_verified_on_aligned} ;
21use crate :: config:: Config ;
32use crate :: db:: { generate_random_transfers, DB } ;
43use crate :: eth:: send_state_transition_to_chain;
54use crate :: prover:: { self , prove_state_transition, PROGRAM_ELF } ;
5+ use agg_mode_sdk:: blockchain:: provider:: ProofAggregationServiceProvider ;
6+ use agg_mode_sdk:: blockchain:: { AggregationModeVerificationData , ProofStatus } ;
7+ use agg_mode_sdk:: gateway:: provider:: AggregationModeGatewayProvider ;
68use alloy:: hex;
9+ use alloy:: signers:: k256:: ecdsa:: SigningKey ;
10+ use alloy:: signers:: local:: LocalSigner ;
711use primitive_types:: U256 ;
8- use sp1_sdk:: SP1ProofWithPublicValues ;
12+ use sp1_sdk:: { HashableKey , SP1ProofWithPublicValues } ;
913use sp1_state_transition_program:: ProgramOutput ;
1014use tracing:: info;
1115
1216pub struct L2 {
17+ aligned_agg_mode_gateway_provider : AggregationModeGatewayProvider < LocalSigner < SigningKey > > ,
18+ aligned_proof_agg_service : ProofAggregationServiceProvider ,
1319 config : Config ,
1420 db : DB ,
1521}
1622
1723impl L2 {
1824 pub fn new ( config : Config ) -> Self {
1925 let db_path = config. db_path . clone ( ) . unwrap_or ( "./db" . to_string ( ) ) ;
26+ let signer = LocalSigner :: decrypt_keystore (
27+ config. private_key_store_path . clone ( ) ,
28+ config. private_key_store_password . clone ( ) ,
29+ )
30+ . expect ( "failed to parse private key: {e}" ) ;
31+
32+ let gatewat_provider =
33+ AggregationModeGatewayProvider :: new_with_signer ( config. network . clone ( ) , signer)
34+ . expect ( "to build gateway provider" ) ;
35+
36+ let proof_agg_service = ProofAggregationServiceProvider :: new (
37+ config. network . clone ( ) ,
38+ config. eth_rpc_url . clone ( ) ,
39+ config. beacon_client_url . clone ( ) ,
40+ ) ;
2041
2142 Self {
2243 config,
44+ aligned_agg_mode_gateway_provider : gatewat_provider,
45+ aligned_proof_agg_service : proof_agg_service,
2346 db : DB :: new ( db_path) ,
2447 }
2548 }
@@ -32,7 +55,7 @@ impl L2 {
3255
3356 // 2. Call zkvm and transfer to perform and verify
3457 info ! ( "Starting prover..." ) ;
35- let ( mut proof, _vk ) = prove_state_transition ( & self . db , transfers. clone ( ) ) ;
58+ let ( mut proof, vk ) = prove_state_transition ( & self . db , transfers. clone ( ) ) ;
3659 let ProgramOutput {
3760 initial_state_merkle_root,
3861 post_state_merkle_root,
@@ -71,10 +94,13 @@ impl L2 {
7194 // Once aligned aggregates the proof we will be notified and we'll send the new state commitment on chain
7295
7396 // 4. Send the proof to aligned and wait for verification
74- info ! ( "Sending proof to aligned batcher..." ) ;
75- let _ =
76- send_proof_to_be_verified_on_aligned ( & self . config , & proof, PROGRAM_ELF . to_vec ( ) ) . await ;
77- info ! ( "Proof submitted" ) ;
97+ info ! ( "Sending proof to aligned gateway..." ) ;
98+ let res = self
99+ . aligned_agg_mode_gateway_provider
100+ . submit_sp1_proof ( & proof, & vk)
101+ . await
102+ . expect ( "Failed to send proof to aggregation mode gateway: {e}" ) ;
103+ info ! ( "Response from gateway: {:?}" , res) ;
78104
79105 self . db . save ( ) . unwrap ( ) ;
80106
@@ -85,9 +111,20 @@ impl L2 {
85111 let vk = prover:: vk_from_elf ( PROGRAM_ELF ) ;
86112 // 5. Check if proof has been aggregated
87113 info ! ( "Checking if proof has been aggregated in the last 24 hours..." ) ;
88- let proof_status = check_proof_proof_aggregation_status ( & self . config , & proof, & vk) . await ;
114+ let proof_status = self
115+ . aligned_proof_agg_service
116+ . check_proof_verification (
117+ None ,
118+ AggregationModeVerificationData :: SP1 {
119+ vk : vk. hash_bytes ( ) ,
120+ public_inputs : proof. public_values . to_vec ( ) ,
121+ } ,
122+ )
123+ . await
124+ . expect ( "To be able to check proof status {e}" ) ;
125+
89126 let merkle_path = match proof_status {
90- aligned_sdk :: aggregation_layer :: ProofStatus :: Verified {
127+ ProofStatus :: Verified {
91128 merkle_root,
92129 merkle_path,
93130 } => {
@@ -97,10 +134,10 @@ impl L2 {
97134 ) ;
98135 merkle_path
99136 }
100- aligned_sdk :: aggregation_layer :: ProofStatus :: Invalid => {
137+ ProofStatus :: Invalid => {
101138 panic ! ( "Proof did pass merkle root verification" ) ;
102139 }
103- aligned_sdk :: aggregation_layer :: ProofStatus :: NotFound => {
140+ ProofStatus :: NotFound => {
104141 panic ! ( "Proof not found in the last 24 hours logs" ) ;
105142 }
106143 } ;
0 commit comments