11use aligned:: { send_proof_to_be_verified_on_aligned, wait_until_proof_is_aggregated} ;
2+ use alloy:: hex:: hex;
23use db:: { generate_random_transfers, DB } ;
4+ use eth:: send_state_transition_to_chain;
5+ use lambdaworks_crypto:: merkle_tree:: merkle:: MerkleTree ;
36use primitive_types:: U256 ;
47use sp1_state_transition_program:: ProgramOutput ;
58use zk:: { prove_state_transition, PROGRAM_ELF } ;
69
710mod aligned;
811mod db;
12+ mod eth;
913mod zk;
1014
1115pub async fn start_l2 (
@@ -21,11 +25,13 @@ pub async fn start_l2(
2125 let transfers = generate_random_transfers ( & db, 10 ) ;
2226
2327 // 2. Call zkvm and pass (MerkleTree, Updates to perform)
28+ println ! ( "Staring prover" ) ;
2429 let ( mut proof, vk) = prove_state_transition ( & db, transfers. clone ( ) ) ;
2530 let ProgramOutput {
2631 initial_state_merkle_root,
2732 post_state_merkle_root,
2833 } = proof. public_values . read :: < ProgramOutput > ( ) ;
34+ println ! ( "Prover finish" ) ;
2935
3036 // 3. If the proving went alright, update the db and verify that the merkle root matches
3137 assert ! ( db. commitment( ) == initial_state_merkle_root) ;
@@ -56,22 +62,37 @@ pub async fn start_l2(
5662 // Once aligned aggregates the proof we will be notified and we'll send the new state commitment on chain
5763
5864 // 4. Send the proof to aligned and wait for verification
65+ println ! ( "Sending proof to aligned batcher" ) ;
5966 let _ =
6067 send_proof_to_be_verified_on_aligned ( & proof, PROGRAM_ELF . to_vec ( ) , network. clone ( ) , wallet)
6168 . await ;
69+ println ! ( "Proof submitted" ) ;
6270
71+ println ! ( "Waiting until is proof is aggregated" ) ;
6372 // 5. Wait until proof is aggregated
6473 let merkle_path = wait_until_proof_is_aggregated (
6574 network. clone ( ) ,
66- eth_rpc_url,
75+ eth_rpc_url. clone ( ) ,
6776 beacon_client_url,
6877 & proof,
6978 & vk,
7079 )
71- . await ;
80+ . await
81+ . expect ( "To get merkle path in last aggregated proofs" ) ;
82+
83+ println ! ( "Proof has been aggregated on aligned, about to send update to chain." ) ;
7284
7385 // 6. Send updateState transaction to Ethereum
74- // let receipt = update_state_on_chain();
86+ let receipt = send_state_transition_to_chain (
87+ proof. public_values . to_vec ( ) ,
88+ merkle_path,
89+ eth_rpc_url. clone ( ) ,
90+ "0xdC62Bf47Da2a2afD8Eb838C7004337613Af5C3b9" . into ( ) ,
91+ "" . into ( ) ,
92+ )
93+ . await ;
94+
95+ println ! ( "State update in contracts tx receipt {:?}" , receipt) ;
7596
7697 // Finally save the db to a file to be retrieved later
7798 db. save ( ) . unwrap ( ) ;
0 commit comments