From 0e720dd9d3290cf9e1738de7b0566bf8bce13970 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Thu, 18 Sep 2025 15:59:17 +0300 Subject: [PATCH] fix: configs and tests updates --- Cargo.lock | 1 + .../debug/sequencer/sequencer_config.json | 4 + .../configs/debug/wallet/wallet_config.json | 465 +++++++++++++++++- .../privacy_preserving_transaction/circuit.rs | 2 +- nssa/src/public_transaction/transaction.rs | 2 +- nssa/src/state.rs | 69 +-- sequencer_core/Cargo.toml | 1 + sequencer_core/src/config.rs | 2 + sequencer_core/src/lib.rs | 2 + sequencer_core/src/sequencer_store/mod.rs | 3 +- sequencer_rpc/src/process.rs | 1 + wallet/src/config.rs | 6 + 12 files changed, 523 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b663f8d..e3f2a74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3919,6 +3919,7 @@ dependencies = [ "log", "mempool", "nssa", + "nssa-core", "rand 0.8.5", "serde", "storage", diff --git a/integration_tests/configs/debug/sequencer/sequencer_config.json b/integration_tests/configs/debug/sequencer/sequencer_config.json index 3317a11..5ff989f 100644 --- a/integration_tests/configs/debug/sequencer/sequencer_config.json +++ b/integration_tests/configs/debug/sequencer/sequencer_config.json @@ -16,6 +16,10 @@ "balance": 20000 } ], + "initial_commitments": [ + [35, 0, 179, 15, 181, 120, 158, 46, 231, 74, 28, 4, 110, 236, 183, 84, 149, 28, 183, 15, 187, 169, 209, 117, 163, 111, 196, 223, 142, 121, 183, 113], + [108, 161, 161, 147, 255, 252, 193, 27, 3, 122, 147, 112, 219, 15, 106, 73, 151, 176, 204, 223, 255, 183, 20, 8, 86, 134, 96, 59, 208, 251, 116, 101] + ], "signing_key": [37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37] } diff --git a/integration_tests/configs/debug/wallet/wallet_config.json b/integration_tests/configs/debug/wallet/wallet_config.json index 56c5d0e..f30c9a5 100644 --- a/integration_tests/configs/debug/wallet/wallet_config.json +++ b/integration_tests/configs/debug/wallet/wallet_config.json @@ -7,7 +7,7 @@ "seq_poll_max_retries": 5, "seq_poll_retry_delay_millis": 500, "initial_accounts": [ - { + { "Public": { "address": "1b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f", "pub_sign_key": [ @@ -46,7 +46,7 @@ ] } }, - { + { "Public": { "address": "4d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766", "pub_sign_key": [ @@ -84,7 +84,464 @@ 2 ] } + }, + { + "Private": { + "address": "6ffe0893c4b2c956fdb769b11fe4e3b2dd36ac4bd0ad90c810844051747c8c04", + "account": { + "program_owner": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "balance": 10000, + "data": [], + "nonce": 0 + }, + "key_chain": { + "secret_spending_key": [ + 10, + 125, + 171, + 38, + 201, + 35, + 164, + 43, + 7, + 80, + 7, + 215, + 97, + 42, + 48, + 229, + 101, + 216, + 140, + 21, + 170, + 214, + 82, + 53, + 116, + 22, + 62, + 79, + 61, + 76, + 71, + 79 + ], + "private_key_holder": { + "nullifier_secret_key": [ + 228, + 136, + 4, + 156, + 33, + 40, + 194, + 172, + 95, + 168, + 201, + 33, + 24, + 30, + 126, + 197, + 156, + 113, + 64, + 162, + 131, + 210, + 110, + 60, + 24, + 154, + 86, + 59, + 184, + 95, + 245, + 176 + ], + "incoming_viewing_secret_key": [ + 197, + 33, + 51, + 200, + 1, + 121, + 60, + 52, + 233, + 234, + 12, + 166, + 196, + 227, + 187, + 1, + 10, + 101, + 183, + 105, + 140, + 28, + 152, + 217, + 109, + 220, + 112, + 103, + 253, + 110, + 98, + 6 + ], + "outgoing_viewing_secret_key": [ + 147, + 34, + 193, + 29, + 39, + 173, + 222, + 30, + 118, + 199, + 44, + 204, + 43, + 232, + 107, + 223, + 249, + 207, + 245, + 183, + 63, + 209, + 129, + 48, + 254, + 66, + 22, + 199, + 81, + 145, + 126, + 92 + ] + }, + "nullifer_public_key": [ + 193, + 209, + 150, + 113, + 47, + 241, + 48, + 145, + 250, + 79, + 235, + 51, + 119, + 40, + 184, + 232, + 5, + 221, + 36, + 21, + 201, + 106, + 90, + 210, + 129, + 106, + 71, + 99, + 208, + 153, + 75, + 215 + ], + "incoming_viewing_public_key": [ + 3, + 78, + 177, + 87, + 193, + 219, + 230, + 160, + 222, + 38, + 182, + 100, + 101, + 223, + 204, + 223, + 198, + 140, + 253, + 94, + 16, + 98, + 77, + 79, + 114, + 30, + 158, + 104, + 34, + 152, + 189, + 31, + 95 + ] + } + } + }, + { + "Private": { + "address": "4ee9de60e33da96fd72929f1485fb365bcc9c1634dd44e4ba55b1ab96692674b", + "account": { + "program_owner": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "balance": 20000, + "data": [], + "nonce": 0 + }, + "key_chain": { + "secret_spending_key": [ + 153, + 109, + 202, + 226, + 97, + 212, + 77, + 147, + 75, + 107, + 153, + 106, + 89, + 167, + 49, + 230, + 122, + 78, + 167, + 146, + 14, + 180, + 206, + 107, + 96, + 193, + 255, + 122, + 207, + 30, + 142, + 99 + ], + "private_key_holder": { + "nullifier_secret_key": [ + 128, + 215, + 147, + 175, + 119, + 16, + 140, + 219, + 155, + 134, + 27, + 81, + 64, + 40, + 196, + 240, + 61, + 144, + 232, + 164, + 181, + 57, + 139, + 96, + 137, + 121, + 140, + 29, + 169, + 68, + 187, + 65 + ], + "incoming_viewing_secret_key": [ + 185, + 121, + 146, + 213, + 13, + 3, + 93, + 206, + 25, + 127, + 155, + 21, + 155, + 115, + 130, + 27, + 57, + 5, + 116, + 80, + 62, + 214, + 67, + 228, + 147, + 189, + 28, + 200, + 62, + 152, + 178, + 103 + ], + "outgoing_viewing_secret_key": [ + 163, + 58, + 118, + 160, + 175, + 86, + 72, + 91, + 81, + 69, + 150, + 154, + 113, + 211, + 118, + 110, + 25, + 156, + 250, + 67, + 212, + 198, + 147, + 231, + 213, + 136, + 212, + 198, + 192, + 255, + 126, + 122 + ] + }, + "nullifer_public_key": [ + 27, + 250, + 136, + 142, + 88, + 128, + 138, + 21, + 49, + 183, + 118, + 160, + 117, + 114, + 110, + 47, + 136, + 87, + 60, + 70, + 59, + 60, + 18, + 223, + 23, + 147, + 241, + 5, + 184, + 103, + 225, + 105 + ], + "incoming_viewing_public_key": [ + 2, + 56, + 160, + 1, + 22, + 197, + 187, + 214, + 204, + 221, + 84, + 87, + 12, + 204, + 0, + 119, + 116, + 176, + 6, + 149, + 145, + 100, + 211, + 162, + 19, + 158, + 197, + 112, + 142, + 172, + 1, + 98, + 226 + ] + } + } } ] -} - +} \ No newline at end of file diff --git a/nssa/src/privacy_preserving_transaction/circuit.rs b/nssa/src/privacy_preserving_transaction/circuit.rs index fef44bc..1421f62 100644 --- a/nssa/src/privacy_preserving_transaction/circuit.rs +++ b/nssa/src/privacy_preserving_transaction/circuit.rs @@ -220,7 +220,7 @@ mod tests { Commitment::new(&recipient_keys.npk(), &expected_private_account_2), ]; - let esk_1 = [3; 32].into(); + let esk_1 = [3; 32]; let shared_secret_1 = SharedSecretKey::new(&esk_1, &sender_keys.ivk()); let esk_2 = [5; 32]; diff --git a/nssa/src/public_transaction/transaction.rs b/nssa/src/public_transaction/transaction.rs index 20b2729..0b1a1c3 100644 --- a/nssa/src/public_transaction/transaction.rs +++ b/nssa/src/public_transaction/transaction.rs @@ -138,7 +138,7 @@ pub mod tests { fn state_for_tests() -> V01State { let (_, _, addr1, addr2) = keys_for_tests(); let initial_data = [(addr1, 10000), (addr2, 20000)]; - V01State::new_with_genesis_accounts(&initial_data) + V01State::new_with_genesis_accounts(&initial_data, &[]) } fn transaction_for_tests() -> PublicTransaction { diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 7922bad..9ca3a19 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -64,7 +64,10 @@ pub struct V01State { } impl V01State { - pub fn new_with_genesis_accounts(initial_data: &[(Address, u128)]) -> Self { + pub fn new_with_genesis_accounts( + initial_data: &[(Address, u128)], + initial_commitments: &[nssa_core::Commitment], + ) -> Self { let authenticated_transfer_program = Program::authenticated_transfer_program(); let public_state = initial_data .iter() @@ -79,9 +82,12 @@ impl V01State { }) .collect(); + let mut private_state = CommitmentSet::with_capacity(32); + private_state.extend(initial_commitments); + let mut this = Self { public_state, - private_state: (CommitmentSet::with_capacity(32), NullifierSet::new()), + private_state: (private_state, NullifierSet::new()), builtin_programs: HashMap::new(), }; @@ -283,7 +289,7 @@ pub mod tests { this }; - let state = V01State::new_with_genesis_accounts(&initial_data); + let state = V01State::new_with_genesis_accounts(&initial_data, &[]); assert_eq!(state.public_state, expected_public_state); assert_eq!(state.builtin_programs, expected_builtin_programs); @@ -291,7 +297,7 @@ pub mod tests { #[test] fn test_insert_program() { - let mut state = V01State::new_with_genesis_accounts(&[]); + let mut state = V01State::new_with_genesis_accounts(&[], &[]); let program_to_insert = Program::simple_balance_transfer(); let program_id = program_to_insert.id(); assert!(!state.builtin_programs.contains_key(&program_id)); @@ -306,7 +312,7 @@ pub mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); let addr = Address::from(&PublicKey::new_from_private_key(&key)); let initial_data = [(addr, 100u128)]; - let state = V01State::new_with_genesis_accounts(&initial_data); + let state = V01State::new_with_genesis_accounts(&initial_data, &[]); let expected_account = state.public_state.get(&addr).unwrap(); let account = state.get_account_by_address(&addr); @@ -317,7 +323,7 @@ pub mod tests { #[test] fn test_get_account_by_address_default_account() { let addr2 = Address::new([0; 32]); - let state = V01State::new_with_genesis_accounts(&[]); + let state = V01State::new_with_genesis_accounts(&[], &[]); let expected_account = Account::default(); let account = state.get_account_by_address(&addr2); @@ -327,7 +333,7 @@ pub mod tests { #[test] fn test_builtin_programs_getter() { - let state = V01State::new_with_genesis_accounts(&[]); + let state = V01State::new_with_genesis_accounts(&[], &[]); let builtin_programs = state.builtin_programs(); @@ -339,7 +345,7 @@ pub mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); let address = Address::from(&PublicKey::new_from_private_key(&key)); let initial_data = [(address, 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data); + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]); let from = address; let to = Address::new([2; 32]); assert_eq!(state.get_account_by_address(&to), Account::default()); @@ -359,7 +365,7 @@ pub mod tests { let key = PrivateKey::try_new([1; 32]).unwrap(); let address = Address::from(&PublicKey::new_from_private_key(&key)); let initial_data = [(address, 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data); + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]); let from = address; let from_key = key; let to = Address::new([2; 32]); @@ -383,7 +389,7 @@ pub mod tests { let address1 = Address::from(&PublicKey::new_from_private_key(&key1)); let address2 = Address::from(&PublicKey::new_from_private_key(&key2)); let initial_data = [(address1, 100), (address2, 200)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data); + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]); let from = address2; let from_key = key2; let to = address1; @@ -406,7 +412,7 @@ pub mod tests { let key2 = PrivateKey::try_new([2; 32]).unwrap(); let address2 = Address::from(&PublicKey::new_from_private_key(&key2)); let initial_data = [(address1, 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data); + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]); let address3 = Address::new([3; 32]); let balance_to_move = 5; @@ -490,7 +496,8 @@ pub mod tests { #[test] fn test_program_should_fail_if_modifies_nonces() { let initial_data = [(Address::new([1; 32]), 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let addresses = vec![Address::new([1; 32])]; let program_id = Program::nonce_changer_program().id(); let message = @@ -506,7 +513,8 @@ pub mod tests { #[test] fn test_program_should_fail_if_output_accounts_exceed_inputs() { let initial_data = [(Address::new([1; 32]), 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let addresses = vec![Address::new([1; 32])]; let program_id = Program::extra_output_program().id(); let message = @@ -522,7 +530,8 @@ pub mod tests { #[test] fn test_program_should_fail_with_missing_output_accounts() { let initial_data = [(Address::new([1; 32]), 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let addresses = vec![Address::new([1; 32]), Address::new([2; 32])]; let program_id = Program::missing_output_program().id(); let message = @@ -538,7 +547,8 @@ pub mod tests { #[test] fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_program_owner() { let initial_data = [(Address::new([1; 32]), 0)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let address = Address::new([1; 32]); let account = state.get_account_by_address(&address); // Assert the target account only differs from the default account in the program owner field @@ -560,7 +570,7 @@ pub mod tests { #[test] fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_balance() { let initial_data = []; - let mut state = V01State::new_with_genesis_accounts(&initial_data) + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let address = Address::new([255; 32]); @@ -584,7 +594,7 @@ pub mod tests { #[test] fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_nonce() { let initial_data = []; - let mut state = V01State::new_with_genesis_accounts(&initial_data) + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let address = Address::new([254; 32]); @@ -608,7 +618,7 @@ pub mod tests { #[test] fn test_program_should_fail_if_modifies_program_owner_with_only_non_default_data() { let initial_data = []; - let mut state = V01State::new_with_genesis_accounts(&initial_data) + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_non_default_accounts_but_default_program_owners(); let address = Address::new([253; 32]); @@ -632,7 +642,8 @@ pub mod tests { #[test] fn test_program_should_fail_if_transfers_balance_from_non_owned_account() { let initial_data = [(Address::new([1; 32]), 100)]; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let sender_address = Address::new([1; 32]); let receiver_address = Address::new([2; 32]); let balance_to_move: u128 = 1; @@ -659,7 +670,8 @@ pub mod tests { #[test] fn test_program_should_fail_if_modifies_data_of_non_owned_account() { let initial_data = []; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let address = Address::new([1; 32]); let program_id = Program::data_changer().id(); @@ -682,7 +694,8 @@ pub mod tests { #[test] fn test_program_should_fail_if_does_not_preserve_total_balance_by_minting() { let initial_data = []; - let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs(); + let mut state = + V01State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs(); let address = Address::new([1; 32]); let program_id = Program::minter().id(); @@ -699,7 +712,7 @@ pub mod tests { #[test] fn test_program_should_fail_if_does_not_preserve_total_balance_by_burning() { let initial_data = []; - let mut state = V01State::new_with_genesis_accounts(&initial_data) + let mut state = V01State::new_with_genesis_accounts(&initial_data, &[]) .with_test_programs() .with_account_owned_by_burner_program(); let program_id = Program::burner().id(); @@ -930,7 +943,7 @@ pub mod tests { let sender_keys = test_public_account_keys_1(); let recipient_keys = test_private_account_keys_1(); - let mut state = V01State::new_with_genesis_accounts(&[(sender_keys.address(), 200)]); + let mut state = V01State::new_with_genesis_accounts(&[(sender_keys.address(), 200)], &[]); let balance_to_move = 37; @@ -967,7 +980,7 @@ pub mod tests { }; let recipient_keys = test_private_account_keys_2(); - let mut state = V01State::new_with_genesis_accounts(&[]) + let mut state = V01State::new_with_genesis_accounts(&[], &[]) .with_private_account(&sender_keys, &sender_private_account); let balance_to_move = 37; @@ -1032,10 +1045,10 @@ pub mod tests { }; let recipient_keys = test_public_account_keys_1(); let recipient_initial_balance = 400; - let mut state = V01State::new_with_genesis_accounts(&[( - recipient_keys.address(), - recipient_initial_balance, - )]) + let mut state = V01State::new_with_genesis_accounts( + &[(recipient_keys.address(), recipient_initial_balance)], + &[], + ) .with_private_account(&sender_keys, &sender_private_account); let balance_to_move = 37; diff --git a/sequencer_core/Cargo.toml b/sequencer_core/Cargo.toml index 40e420a..52074cc 100644 --- a/sequencer_core/Cargo.toml +++ b/sequencer_core/Cargo.toml @@ -11,6 +11,7 @@ rand.workspace = true tempfile.workspace = true chrono.workspace = true log.workspace = true +nssa-core = { path = "../nssa/core", features = ["host"] } [dependencies.storage] path = "../storage" diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index cdf79a3..3ac52da 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -27,6 +27,8 @@ pub struct SequencerConfig { pub port: u16, ///List of initial accounts data pub initial_accounts: Vec, + ///List of initial commitments + pub initial_commitments: Vec, ///Sequencer own signing key pub signing_key: [u8; 32], } diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 59b787e..ddb2a2f 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -55,6 +55,7 @@ impl SequencerCore { config.genesis_id, config.is_genesis_random, &config.initial_accounts, + &config.initial_commitments, nssa::PrivateKey::try_new(config.signing_key).unwrap(), ), mempool: MemPool::default(), @@ -209,6 +210,7 @@ mod tests { block_create_timeout_millis: 1000, port: 8080, initial_accounts, + initial_commitments: vec![], signing_key: *sequencer_sign_key_for_testing().value(), } } diff --git a/sequencer_core/src/sequencer_store/mod.rs b/sequencer_core/src/sequencer_store/mod.rs index 366c9e2..efbf7c9 100644 --- a/sequencer_core/src/sequencer_store/mod.rs +++ b/sequencer_core/src/sequencer_store/mod.rs @@ -20,6 +20,7 @@ impl SequecerChainStore { genesis_id: u64, is_genesis_random: bool, initial_accounts: &[AccountInitialData], + initial_commitments: &[nssa_core::Commitment], signing_key: nssa::PrivateKey, ) -> Self { let init_accs: Vec<(Address, u128)> = initial_accounts @@ -27,7 +28,7 @@ impl SequecerChainStore { .map(|acc_data| (acc_data.addr.parse().unwrap(), acc_data.balance)) .collect(); - let state = nssa::V01State::new_with_genesis_accounts(&init_accs); + let state = nssa::V01State::new_with_genesis_accounts(&init_accs, initial_commitments); let mut data = [0; 32]; let mut prev_block_hash = [0; 32]; diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index 6a9494f..4ebb293 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -338,6 +338,7 @@ mod tests { block_create_timeout_millis: 1000, port: 8080, initial_accounts, + initial_commitments: vec![], signing_key: *sequencer_sign_key_for_testing().value(), } } diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 2231b11..b5d861c 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -28,12 +28,18 @@ pub struct PersistentAccountDataPrivate { pub key_chain: KeyChain, } +//Big difference in enum variants sizes +//however it is improbable, that we will have that much accounts, that it will substantialy affect memory +#[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, Serialize, Deserialize)] pub enum InitialAccountData { Public(InitialAccountDataPublic), Private(InitialAccountDataPrivate), } +//Big difference in enum variants sizes +//however it is improbable, that we will have that much accounts, that it will substantialy affect memory +#[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, Serialize, Deserialize)] pub enum PersistentAccountData { Public(PersistentAccountDataPublic),