From a7c60a56b7a3c96566b40605a85685abc4cfb922 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 24 Sep 2025 14:29:56 +0300 Subject: [PATCH] fix: try unify program id --- ci_scripts/test-ubuntu.sh | 2 +- .../debug/sequencer/sequencer_config.json | 142 +++++++++++++++++- .../configs/debug/wallet/wallet_config.json | 32 ++-- nssa/core/src/program.rs | 10 ++ sequencer_core/src/config.rs | 9 +- sequencer_core/src/lib.rs | 16 +- wallet/src/token_transfers/private.rs | 19 ++- 7 files changed, 200 insertions(+), 30 deletions(-) diff --git a/ci_scripts/test-ubuntu.sh b/ci_scripts/test-ubuntu.sh index 6a1710b..d85b6c5 100644 --- a/ci_scripts/test-ubuntu.sh +++ b/ci_scripts/test-ubuntu.sh @@ -8,4 +8,4 @@ RISC0_DEV_MODE=1 cargo test --release cd integration_tests export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/wallet/ export RUST_LOG=info -cargo run $(pwd)/configs/debug all +cargo run $(pwd)/configs/debug test_success_private_transfer_to_another_owned_account diff --git a/integration_tests/configs/debug/sequencer/sequencer_config.json b/integration_tests/configs/debug/sequencer/sequencer_config.json index 984a7c2..f40e731 100644 --- a/integration_tests/configs/debug/sequencer/sequencer_config.json +++ b/integration_tests/configs/debug/sequencer/sequencer_config.json @@ -17,9 +17,141 @@ } ], "initial_commitments": [ - [180, 94, 202, 138, 152, 13, 198, 85, 53, 34, 255, 86, 236, 7, 221, 33, 122, 36, 153, 139, 78, 195, 176, 14, 75, 126, 237, 137, 97, 120, 122, 112], - [24, 182, 41, 27, 99, 75, 199, 242, 219, 65, 169, 113, 177, 133, 128, 230, 217, 250, 159, 47, 36, 57, 27, 163, 42, 99, 181, 16, 224, 135, 53, 24] + { + "npk": [ + 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 + ], + "account": { + "program_owner": [ + 2357946808, + 1250390931, + 1946783766, + 2395930623, + 2256469211, + 3226409911, + 3251831113, + 2343238083 + ], + "balance": 10000, + "data": [], + "nonce": 0 + } + }, + { + "npk": [ + 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 + ], + "account": { + "program_owner": [ + 2357946808, + 1250390931, + 1946783766, + 2395930623, + 2256469211, + 3226409911, + 3251831113, + 2343238083 + ], + "balance": 20000, + "data": [], + "nonce": 0 + } + } ], - "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] -} + "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 + ] +} \ No newline at end of file diff --git a/integration_tests/configs/debug/wallet/wallet_config.json b/integration_tests/configs/debug/wallet/wallet_config.json index fb1b7e5..17e7f4d 100644 --- a/integration_tests/configs/debug/wallet/wallet_config.json +++ b/integration_tests/configs/debug/wallet/wallet_config.json @@ -90,14 +90,14 @@ "address": "6ffe0893c4b2c956fdb769b11fe4e3b2dd36ac4bd0ad90c810844051747c8c04", "account": { "program_owner": [ - 1793544791, - 852173979, - 3315478100, - 4158236927, - 146723505, - 3793635251, - 999304864, - 2535706995 + 2357946808, + 1250390931, + 1946783766, + 2395930623, + 2256469211, + 3226409911, + 3251831113, + 2343238083 ], "balance": 10000, "data": [], @@ -319,14 +319,14 @@ "address": "4ee9de60e33da96fd72929f1485fb365bcc9c1634dd44e4ba55b1ab96692674b", "account": { "program_owner": [ - 1793544791, - 852173979, - 3315478100, - 4158236927, - 146723505, - 3793635251, - 999304864, - 2535706995 + 2357946808, + 1250390931, + 1946783766, + 2395930623, + 2256469211, + 3226409911, + 3251831113, + 2343238083 ], "balance": 20000, "data": [], diff --git a/nssa/core/src/program.rs b/nssa/core/src/program.rs index d284bbc..046eb1e 100644 --- a/nssa/core/src/program.rs +++ b/nssa/core/src/program.rs @@ -53,22 +53,30 @@ pub fn validate_execution( return false; } + println!("HELLO 1"); + for (pre, post) in pre_states.iter().zip(post_states) { // 2. Nonce must remain unchanged if pre.account.nonce != post.nonce { return false; } + println!("HELLO 2"); + // 3. Ownership change only allowed from default accounts if pre.account.program_owner != post.program_owner && pre.account != Account::default() { return false; } + println!("HELLO 3"); + // 4. Decreasing balance only allowed if owned by executing program if post.balance < pre.account.balance && pre.account.program_owner != executing_program_id { return false; } + println!("HELLO 4"); + // 5. Data changes only allowed if owned by executing program if pre.account.data != post.data && (executing_program_id != pre.account.program_owner @@ -76,6 +84,8 @@ pub fn validate_execution( { return false; } + + println!("HELLO 5"); } // 6. Total balance is preserved diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 3ac52da..2f57f72 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -9,6 +9,13 @@ pub struct AccountInitialData { pub balance: u128, } +#[derive(Debug, Serialize, Deserialize, Clone)] +///Helperstruct to initialize commitments +pub struct CommitmentsInitialData { + pub npk: nssa_core::NullifierPublicKey, + pub account: nssa_core::account::Account, +} + #[derive(Clone, Serialize, Deserialize)] pub struct SequencerConfig { ///Home dir of sequencer storage @@ -28,7 +35,7 @@ pub struct SequencerConfig { ///List of initial accounts data pub initial_accounts: Vec, ///List of initial commitments - pub initial_commitments: Vec, + 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 ddb2a2f..6c54a50 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -49,13 +49,27 @@ impl std::error::Error for TransactionMalformationErrorKind {} impl SequencerCore { pub fn start_from_config(config: SequencerConfig) -> Self { + let mut initial_commitments = vec![]; + + for init_comm_data in config.initial_commitments.clone() { + let npk = init_comm_data.npk; + + let mut acc = init_comm_data.account; + + acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); + + let comm = nssa_core::Commitment::new(&npk, &acc); + + initial_commitments.push(comm); + } + Self { store: SequecerChainStore::new_with_genesis( &config.home, config.genesis_id, config.is_genesis_random, &config.initial_accounts, - &config.initial_commitments, + &initial_commitments, nssa::PrivateKey::try_new(config.signing_key).unwrap(), ), mempool: MemPool::default(), diff --git a/wallet/src/token_transfers/private.rs b/wallet/src/token_transfers/private.rs index 12a16dd..3d2eaf8 100644 --- a/wallet/src/token_transfers/private.rs +++ b/wallet/src/token_transfers/private.rs @@ -110,14 +110,14 @@ impl WalletCore { to: Address, balance_to_move: u128, ) -> Result<(SendTxResponse, nssa_core::SharedSecretKey), ExecutionFailureKind> { - let from_data = self.storage.user_data.get_private_account(&from); - let to_data = self.storage.user_data.get_private_account(&to); + let from_data = self.storage.user_data.get_private_account(&from).cloned(); + let to_data = self.storage.user_data.get_private_account(&to).cloned(); - let Some((from_keys, from_acc)) = from_data else { + let Some((from_keys, mut from_acc)) = from_data else { return Err(ExecutionFailureKind::KeyNotFoundError); }; - let Some((to_keys, to_acc)) = to_data else { + let Some((to_keys, mut to_acc)) = to_data else { return Err(ExecutionFailureKind::KeyNotFoundError); }; @@ -126,10 +126,17 @@ impl WalletCore { if from_acc.balance >= balance_to_move { let program = nssa::program::Program::authenticated_transfer_program(); + + //Kind of hacky solution + //The issue is that we don't have deterministic builds + //and native_token_transfer at different machine may be different + from_acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); + to_acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); + let sender_commitment = - nssa_core::Commitment::new(&from_keys.nullifer_public_key, from_acc); + nssa_core::Commitment::new(&from_keys.nullifer_public_key, &from_acc); let receiver_commitment = - nssa_core::Commitment::new(&to_keys.nullifer_public_key, to_acc); + nssa_core::Commitment::new(&to_keys.nullifer_public_key, &to_acc); let sender_pre = nssa_core::account::AccountWithMetadata { account: from_acc.clone(),