diff --git a/Cargo.lock b/Cargo.lock index e67d9770..4664b8ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9459,7 +9459,9 @@ dependencies = [ "borsh", "common", "lee", + "programs", "rocksdb", + "system_accounts", "tempfile", "thiserror 2.0.18", ] diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index 48f69559..07212251 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -10,7 +10,7 @@ use log::info; pub use test_fixtures::*; /// Maximum time to wait for the indexer to catch up to the sequencer. -pub const L2_TO_L1_TIMEOUT: Duration = Duration::from_mins(6); +pub const L2_TO_L1_TIMEOUT: Duration = Duration::from_mins(7); /// Poll the indexer until its last finalized block id reaches the sequencer's /// current last block id or until [`L2_TO_L1_TIMEOUT`] elapses. diff --git a/integration_tests/tests/program_deployment.rs b/integration_tests/tests/program_deployment.rs index b941b5d1..ec01c3c8 100644 --- a/integration_tests/tests/program_deployment.rs +++ b/integration_tests/tests/program_deployment.rs @@ -68,9 +68,10 @@ async fn deploy_and_execute_program() -> Result<()> { let post_state_account = ctx.sequencer_client().get_account(account_id).await?; + let expected_data: &[u8] = &[]; assert_eq!(post_state_account.program_owner, claimer.id()); assert_eq!(post_state_account.balance, 0); - assert_eq!(post_state_account.data.as_ref(), &[0]); + assert_eq!(post_state_account.data.as_ref(), expected_data); assert_eq!(post_state_account.nonce.0, 1); info!("Successfully deployed and executed program"); diff --git a/integration_tests/tests/wallet_ffi.rs b/integration_tests/tests/wallet_ffi.rs index ec0329a4..0ef53592 100644 --- a/integration_tests/tests/wallet_ffi.rs +++ b/integration_tests/tests/wallet_ffi.rs @@ -1585,8 +1585,7 @@ fn test_wallet_ffi_transfer_generic_public() -> Result<()> { let instruction_words_size = instruction_data.len(); let instruction_words = Box::into_raw(instruction_data.into_boxed_slice()) as *const u32; - let program: ProgramWithDependencies = programs::authenticated_transfer().into(); - let program_with_dependencies: FfiProgramWithDependencies = program.into(); + let program_id = programs::authenticated_transfer().id(); unsafe { wallet_ffi_send_generic_public_transaction( diff --git a/lee/state_machine/src/privacy_preserving_transaction/circuit.rs b/lee/state_machine/src/privacy_preserving_transaction/circuit.rs index d4f6c0aa..489ee373 100644 --- a/lee/state_machine/src/privacy_preserving_transaction/circuit.rs +++ b/lee/state_machine/src/privacy_preserving_transaction/circuit.rs @@ -667,7 +667,7 @@ mod tests { /// to `PrivateAccountKind::Regular` carrying the correct identifier. #[test] fn private_authorized_init_encrypts_regular_kind_with_identifier() { - let program = crate::test_methods::simple_balance_transfer(); + let program = crate::test_methods::claimer(); let keys = test_private_account_keys_1(); let identifier: u128 = 99; let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &[0_u8; 32], 0).0; @@ -676,7 +676,7 @@ mod tests { let (output, _) = execute_and_prove( vec![pre], - Program::serialize_instruction(0).unwrap(), + Program::serialize_instruction(()).unwrap(), vec![InputAccountIdentity::PrivateAuthorizedInit { epk: EphemeralPublicKey(Vec::new()), view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()), @@ -698,36 +698,23 @@ mod tests { /// to `PrivateAccountKind::Regular` carrying the correct identifier. #[test] fn private_unauthorized_init_encrypts_regular_kind_with_identifier() { - let program = crate::test_methods::simple_balance_transfer(); + let program = crate::test_methods::claimer(); let keys = test_private_account_keys_1(); let identifier: u128 = 99; let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &[0_u8; 32], 0).0; - - let sender = AccountWithMetadata::new( - Account { - program_owner: program.id(), - balance: 1, - ..Account::default() - }, - true, - AccountId::new([0; 32]), - ); let recipient_id = AccountId::for_regular_private_account(&keys.npk(), identifier); let recipient = AccountWithMetadata::new(Account::default(), false, recipient_id); let (output, _) = execute_and_prove( - vec![sender, recipient], - Program::serialize_instruction(1).unwrap(), - vec![ - InputAccountIdentity::Public, - InputAccountIdentity::PrivateUnauthorized { - epk: EphemeralPublicKey(Vec::new()), - view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()), - npk: keys.npk(), - ssk, - identifier, - }, - ], + vec![recipient], + Program::serialize_instruction(()).unwrap(), + vec![InputAccountIdentity::PrivateUnauthorized { + epk: EphemeralPublicKey(Vec::new()), + view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()), + npk: keys.npk(), + ssk, + identifier, + }], &program.into(), ) .unwrap(); @@ -742,7 +729,7 @@ mod tests { /// to `PrivateAccountKind::Regular` carrying the correct identifier. #[test] fn private_authorized_update_encrypts_regular_kind_with_identifier() { - let program = crate::test_methods::simple_balance_transfer(); + let program = crate::test_methods::noop(); let keys = test_private_account_keys_1(); let identifier: u128 = 99; let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &[0_u8; 32], 0).0; @@ -757,22 +744,18 @@ mod tests { commitment_set.extend(std::slice::from_ref(&commitment)); let sender = AccountWithMetadata::new(account, true, account_id); - let recipient = AccountWithMetadata::new(Account::default(), true, AccountId::new([0; 32])); let (output, _) = execute_and_prove( - vec![sender, recipient], - Program::serialize_instruction(1).unwrap(), - vec![ - InputAccountIdentity::PrivateAuthorizedUpdate { - epk: EphemeralPublicKey(Vec::new()), - view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()), - ssk, - nsk: keys.nsk, - membership_proof: commitment_set.get_proof_for(&commitment).unwrap(), - identifier, - }, - InputAccountIdentity::Public, - ], + vec![sender], + Program::serialize_instruction(()).unwrap(), + vec![InputAccountIdentity::PrivateAuthorizedUpdate { + epk: EphemeralPublicKey(Vec::new()), + view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()), + ssk, + nsk: keys.nsk, + membership_proof: commitment_set.get_proof_for(&commitment).unwrap(), + identifier, + }], &program.into(), ) .unwrap(); diff --git a/lee/state_machine/src/state.rs b/lee/state_machine/src/state.rs index 9c8c40b5..c399cea1 100644 --- a/lee/state_machine/src/state.rs +++ b/lee/state_machine/src/state.rs @@ -364,6 +364,27 @@ pub mod tests { self.insert_program(crate::test_methods::data_changer()); self.insert_program(crate::test_methods::minter()); self.insert_program(crate::test_methods::burner()); + self.insert_program(crate::test_methods::auth_asserting_noop()); + self.insert_program(crate::test_methods::private_pda_delegator()); + self.insert_program(crate::test_methods::pda_claimer()); + self.insert_program(crate::test_methods::two_pda_claimer()); + self.insert_program(crate::test_methods::noop()); + self.insert_program(crate::test_methods::chain_caller()); + self.insert_program(crate::test_methods::modified_transfer_program()); + self.insert_program(crate::test_methods::malicious_authorization_changer()); + self.insert_program(crate::test_methods::validity_window()); + self.insert_program(crate::test_methods::flash_swap_initiator()); + self.insert_program(crate::test_methods::flash_swap_callback()); + self.insert_program(crate::test_methods::malicious_self_program_id()); + self.insert_program(crate::test_methods::malicious_caller_program_id()); + self.insert_program(crate::test_methods::pda_spend_proxy()); + self.insert_program(crate::test_methods::claimer()); + self.insert_program(crate::test_methods::changer_claimer()); + self.insert_program(crate::test_methods::validity_window_chain_caller()); + self.insert_program(crate::test_methods::simple_transfer_proxy()); + self.insert_program(crate::test_methods::malicious_injector()); + self.insert_program(crate::test_methods::malicious_launderer()); + self.insert_program(crate::test_methods::modified_transfer_program()); self } @@ -474,6 +495,7 @@ pub mod tests { ( account_id, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance, ..Account::default() }, @@ -599,6 +621,7 @@ pub mod tests { let initial_data = [( account_id, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance: 100, ..Account::default() }, @@ -638,6 +661,7 @@ pub mod tests { let initial_data = [( account_id, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance: 100, ..Account::default() }, @@ -694,6 +718,7 @@ pub mod tests { ( account_id1, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance: 100, ..Account::default() }, @@ -701,6 +726,7 @@ pub mod tests { ( account_id2, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance: 200, ..Account::default() }, @@ -734,6 +760,7 @@ pub mod tests { let initial_data = [( account_id1, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance: 100, ..Account::default() }, @@ -1504,6 +1531,7 @@ pub mod tests { .with_public_accounts([( recipient_keys.account_id(), Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance: recipient_initial_balance, ..Account::default() }, @@ -2667,7 +2695,7 @@ pub mod tests { assert_eq!(state.get_account_by_id(account_id), Account::default()); let message = - public_transaction::Message::try_new(program.id(), vec![account_id], vec![], 0) + public_transaction::Message::try_new(program.id(), vec![account_id], vec![], 0_u128) .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[]); let tx = PublicTransaction::new(message, witness_set); @@ -2687,9 +2715,13 @@ pub mod tests { assert_eq!(state.get_account_by_id(account_id), Account::default()); - let message = - public_transaction::Message::try_new(program.id(), vec![account_id], vec![Nonce(0)], 0) - .unwrap(); + let message = public_transaction::Message::try_new( + program.id(), + vec![account_id], + vec![Nonce(0)], + 0_u128, + ) + .unwrap(); let witness_set = public_transaction::WitnessSet::for_message(&message, &[&account_key]); let tx = PublicTransaction::new(message, witness_set); @@ -2899,7 +2931,7 @@ pub mod tests { let result = execute_and_prove( vec![public_account], - Program::serialize_instruction(0).unwrap(), + Program::serialize_instruction(0_u128).unwrap(), vec![InputAccountIdentity::Public], &program.into(), ); @@ -3190,7 +3222,7 @@ pub mod tests { AccountWithMetadata::new(state.get_account_by_id(recipient_id), false, sender_id); let message = public_transaction::Message::try_new( - crate::test_methods::modified_transfer_program().id(), + modified_transfer_id, vec![sender_id, recipient_id], vec![sender_nonce], balance_to_move, @@ -3255,7 +3287,7 @@ pub mod tests { let (shared_secret, epk) = SharedSecretKey::encapsulate_deterministic(&private_keys.vpk(), &[0_u8; 32], 0); - let instruction = 0; + let instruction: u128 = 0; // Execute and prove the circuit with the authorized account but no commitment proof let (output, proof) = execute_and_prove( @@ -3307,7 +3339,7 @@ pub mod tests { let (output, proof) = execute_and_prove( vec![unauthorized_account], - Program::serialize_instruction(0_u128).unwrap(), + Program::serialize_instruction(()).unwrap(), vec![InputAccountIdentity::PrivateUnauthorized { epk, view_tag: EncryptedAccountData::compute_view_tag( @@ -3353,7 +3385,7 @@ pub mod tests { let (shared_secret, epk) = SharedSecretKey::encapsulate_deterministic(&private_keys.vpk(), &[0_u8; 32], 0); - let instruction = 0; + let instruction = (); // Step 2: Execute claimer program to claim the account with authentication let (output, proof) = execute_and_prove( diff --git a/lee/state_machine/src/validated_state_diff.rs b/lee/state_machine/src/validated_state_diff.rs index ac034a8e..b0a09314 100644 --- a/lee/state_machine/src/validated_state_diff.rs +++ b/lee/state_machine/src/validated_state_diff.rs @@ -533,6 +533,7 @@ mod tests { ( account_id, Account { + program_owner: crate::test_methods::simple_balance_transfer().id(), balance, ..Account::default() }, @@ -558,7 +559,7 @@ mod tests { )); let program_id = crate::test_methods::simple_balance_transfer().id(); let message = - Message::try_new(program_id, vec![from, to], vec![Nonce(0), Nonce(0)], 5).unwrap(); + Message::try_new(program_id, vec![from, to], vec![Nonce(0), Nonce(0)], 5_u128).unwrap(); let witness_set = WitnessSet::for_message(&message, &[&from_key, &to_key]); let tx = crate::PublicTransaction::new(message, witness_set); diff --git a/lee/state_machine/test_methods/guest/src/bin/simple_balance_transfer.rs b/lee/state_machine/test_methods/guest/src/bin/simple_balance_transfer.rs index 29149272..addc4a19 100644 --- a/lee/state_machine/test_methods/guest/src/bin/simple_balance_transfer.rs +++ b/lee/state_machine/test_methods/guest/src/bin/simple_balance_transfer.rs @@ -1,4 +1,4 @@ -use lee_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_lee_inputs}; +use lee_core::program::{AccountPostState, Claim, ProgramInput, ProgramOutput, read_lee_inputs}; type Instruction = u128; @@ -13,6 +13,21 @@ fn main() { instruction_words, ) = read_lee_inputs::(); + if let Ok([account_pre]) = <[_; 1]>::try_from(pre_states.clone()) { + let account_post = + AccountPostState::new_claimed_if_default(account_pre.account, Claim::Authorized); + + ProgramOutput::new( + self_program_id, + caller_program_id, + instruction_words, + pre_states, + vec![account_post], + ) + .write(); + return; + } + let Ok([sender_pre, receiver_pre]) = <[_; 2]>::try_from(pre_states) else { return; }; @@ -34,8 +49,8 @@ fn main() { instruction_words, vec![sender_pre, receiver_pre], vec![ - AccountPostState::new(sender_post), - AccountPostState::new(receiver_post), + AccountPostState::new_claimed_if_default(sender_post, Claim::Authorized), + AccountPostState::new_claimed_if_default(receiver_post, Claim::Authorized), ], ) .write(); diff --git a/lez/sequencer/core/src/lib.rs b/lez/sequencer/core/src/lib.rs index a95c4761..b140fda8 100644 --- a/lez/sequencer/core/src/lib.rs +++ b/lez/sequencer/core/src/lib.rs @@ -1609,6 +1609,7 @@ mod tests { nonce: Nonce(0xdead_beef), data: Data::default(), }; + let bridge_account_id = system_accounts::bridge_account_id(); let mut state = V03State::new() .with_public_accounts([(bridge_account_id, system_accounts::bridge_account())]) @@ -1618,7 +1619,6 @@ mod tests { )]); let sender_commitment = Commitment::new(&sender_account_id, &sender_private_account); - let bridge_account_id = system_accounts::bridge_account_id(); let sender_pre = AccountWithMetadata::new( sender_private_account, diff --git a/lez/storage/Cargo.toml b/lez/storage/Cargo.toml index 4588aab3..8767b525 100644 --- a/lez/storage/Cargo.toml +++ b/lez/storage/Cargo.toml @@ -15,3 +15,7 @@ thiserror.workspace = true borsh.workspace = true rocksdb.workspace = true tempfile.workspace = true + +[dev-dependencies] +programs.workspace = true +system_accounts.workspace = true diff --git a/lez/storage/src/indexer/mod.rs b/lez/storage/src/indexer/mod.rs index 743038cf..a753a71a 100644 --- a/lez/storage/src/indexer/mod.rs +++ b/lez/storage/src/indexer/mod.rs @@ -295,6 +295,7 @@ mod tests { ( id, Account { + program_owner: programs::authenticated_transfer().id(), balance, ..Account::default() }, diff --git a/lez/testnet_initial_state/src/lib.rs b/lez/testnet_initial_state/src/lib.rs index bb3bc7cd..423d6eda 100644 --- a/lez/testnet_initial_state/src/lib.rs +++ b/lez/testnet_initial_state/src/lib.rs @@ -233,6 +233,7 @@ fn initial_public_accounts() -> HashMap { ( acc_data.account_id, Account { + program_owner: programs::authenticated_transfer().id(), balance: acc_data.balance, ..Default::default() },