@@ -2,17 +2,17 @@ use aligned::{send_proof_to_be_verified_on_aligned, wait_until_proof_is_aggregat
22use db:: { generate_random_transfers, DB } ;
33use eth:: send_state_transition_to_chain;
44use primitive_types:: U256 ;
5+ use prover:: { prove_state_transition, PROGRAM_ELF } ;
56use sp1_state_transition_program:: ProgramOutput ;
67use tracing:: info;
7- use prover:: { prove_state_transition, PROGRAM_ELF } ;
88
99mod aligned;
1010mod db;
1111mod eth;
1212mod prover;
1313
1414pub struct Config {
15- pub network : aligned_sdk:: core :: types:: Network ,
15+ pub network : aligned_sdk:: common :: types:: Network ,
1616 pub eth_rpc_url : String ,
1717 pub ws_eth_rpc_url : String ,
1818 pub beacon_client_url : String ,
@@ -28,7 +28,7 @@ pub async fn start_l2(config: Config) {
2828 loop {
2929 // 1. Create random transfers
3030 let transfers = generate_random_transfers ( & db, 10 ) ;
31-
31+
3232 // 2. Call zkvm and transfer to perform and verify
3333 info ! ( "Starting prover..." ) ;
3434 let ( mut proof, vk) = prove_state_transition ( & db, transfers. clone ( ) ) ;
@@ -37,7 +37,7 @@ pub async fn start_l2(config: Config) {
3737 post_state_merkle_root,
3838 } = proof. public_values . read :: < ProgramOutput > ( ) ;
3939 info ! ( "Prover finish" ) ;
40-
40+
4141 // 3. If the proving went alright, update the db and verify that the merkle root matches
4242 assert ! ( db. commitment( ) == initial_state_merkle_root) ;
4343 // Note: we don't have to verify that the user has enough balance, as the prover already validates it
@@ -47,47 +47,47 @@ pub async fn start_l2(config: Config) {
4747 . get ( & transfer. from )
4848 . expect ( "User must exist in state" )
4949 . clone ( ) ;
50-
50+
5151 let mut user_to = db
5252 . user_states
5353 . get ( & transfer. to )
5454 . expect ( "User must exist in state" )
5555 . clone ( ) ;
56-
56+
5757 user_from. balance -= transfer. amount ;
5858 user_from. nonce += U256 :: one ( ) ;
5959 user_to. balance += transfer. amount ;
60-
60+
6161 db. user_states . insert ( transfer. from , user_from) ;
6262 db. user_states . insert ( transfer. to , user_to) ;
6363 }
6464 assert ! ( db. commitment( ) == post_state_merkle_root) ;
65-
65+
6666 // Fow now, in order for a proof to be aggregated, we first need to submit it via the fast mode or verification layer
6767 // Let's suppose that our L2 would run the prover once every 24hs and submit it on aligned
6868 // Once aligned aggregates the proof we will be notified and we'll send the new state commitment on chain
69-
69+
7070 // 4. Send the proof to aligned and wait for verification
7171 info ! ( "Sending proof to aligned batcher..." ) ;
7272 let _ = send_proof_to_be_verified_on_aligned ( & config, & proof, PROGRAM_ELF . to_vec ( ) ) . await ;
7373 info ! ( "Proof submitted" ) ;
74-
74+
7575 // 5. Wait until proof is aggregated
7676 info ! ( "Waiting until is proof is aggregated..." ) ;
7777 let merkle_path = wait_until_proof_is_aggregated ( & config, & proof, & vk) . await ;
7878 info ! ( "Proof has been aggregated on aligned, about to send update to chain..." ) ;
79-
79+
8080 // 6. Send updateState transaction to Ethereum
8181 let receipt =
82- send_state_transition_to_chain ( & config, proof. public_values . to_vec ( ) , merkle_path) . await ;
83-
82+ send_state_transition_to_chain ( & config, proof. public_values . to_vec ( ) , merkle_path)
83+ . await ;
84+
8485 info ! (
8586 "State update in contracts tx hash: {:?}" ,
8687 receipt. transaction_hash
8788 ) ;
88-
89+
8990 // 7. Finally save the db to a file to be retrieved later
9091 db. save ( ) . unwrap ( ) ;
9192 }
92-
9393}
0 commit comments