From e9b11af986e1d358a1e2f14d52cc8f4e1f41815f Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Tue, 29 Jul 2025 16:09:21 -0300 Subject: [PATCH] move nonce to public execution input --- common/src/execution_input.rs | 1 + common/src/transaction.rs | 3 --- node_core/src/chain_storage/mod.rs | 1 - node_core/src/lib.rs | 10 ++-------- sc_core/src/transaction_payloads_tools.rs | 2 -- sequencer_core/src/lib.rs | 19 ++++++++++--------- .../src/sequencer_store/block_store.rs | 1 - sequencer_rpc/src/process.rs | 6 ++---- 8 files changed, 15 insertions(+), 28 deletions(-) diff --git a/common/src/execution_input.rs b/common/src/execution_input.rs index d1f282a..c4f2141 100644 --- a/common/src/execution_input.rs +++ b/common/src/execution_input.rs @@ -5,6 +5,7 @@ use crate::merkle_tree_public::TreeHashType; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PublicNativeTokenSend { pub from: TreeHashType, + pub nonce: u64, pub to: TreeHashType, pub balance_to_move: u64, } diff --git a/common/src/transaction.rs b/common/src/transaction.rs index eacc5ca..2ba78e9 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -62,8 +62,6 @@ pub struct TransactionBody { /// /// First value represents vector of changes, second is new length of a state pub state_changes: (serde_json::Value, usize), - - pub nonce: u64, } #[derive(Debug, Serialize, Deserialize)] @@ -328,7 +326,6 @@ mod tests { secret_r: [8; 32], sc_addr: "someAddress".to_string(), state_changes: (serde_json::Value::Null, 10), - nonce: 1, } } diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index bc0e37f..8e36dc5 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -511,7 +511,6 @@ mod tests { secret_r: [0; 32], sc_addr: "sc_addr".to_string(), state_changes: (serde_json::Value::Null, 0), - nonce: 1, }; Transaction::new(body, SignaturePrivateKey::random(&mut rng)) } diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index 581d85f..8f5d10e 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -274,7 +274,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); @@ -371,7 +370,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); @@ -486,7 +484,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); @@ -632,7 +629,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); @@ -761,7 +757,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); @@ -851,7 +846,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); @@ -962,6 +956,7 @@ impl NodeCore { pub async fn send_public_native_token_transfer( &self, from: AccountAddress, + nonce: u64, to: AccountAddress, balance_to_move: u64, ) -> Result { @@ -989,6 +984,7 @@ impl NodeCore { sc_core::transaction_payloads_tools::create_public_transaction_payload( serde_json::to_vec(&PublicNativeTokenSend { from, + nonce, to, balance_to_move, }) @@ -998,7 +994,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - 1, ); tx.log(); @@ -1555,7 +1550,6 @@ impl NodeCore { secret_r, sc_addr, state_changes, - nonce: 1, }; let key_to_sign_transaction = account.key_holder.get_pub_account_signing_key(); diff --git a/sc_core/src/transaction_payloads_tools.rs b/sc_core/src/transaction_payloads_tools.rs index c3aa44a..fa0e28e 100644 --- a/sc_core/src/transaction_payloads_tools.rs +++ b/sc_core/src/transaction_payloads_tools.rs @@ -15,7 +15,6 @@ pub fn create_public_transaction_payload( secret_r: [u8; 32], sc_addr: String, state_changes: (serde_json::Value, usize), - nonce: u64, ) -> TransactionBody { TransactionBody { tx_kind: TxKind::Public, @@ -32,7 +31,6 @@ pub fn create_public_transaction_payload( secret_r, sc_addr, state_changes, - nonce, } } diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 14ced81..80ac760 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -221,22 +221,24 @@ impl SequencerCore { ref utxo_commitments_created_hashes, ref nullifier_created_hashes, execution_input, - nonce, .. } = mempool_tx.auth_tx.transaction().body(); let tx_hash = *mempool_tx.auth_tx.hash(); - // Nonce check - let signer_addres = address::from_public_key(&mempool_tx.auth_tx.transaction().public_key); - if self.store.acc_store.get_account_nonce(&signer_addres) != *nonce { - return Err(TransactionMalformationErrorKind::NonceMismatch { tx: tx_hash }); - } - //Balance move if let Ok(native_transfer_action) = serde_json::from_slice::(execution_input) { + // Nonce check + let signer_addres = + address::from_public_key(&mempool_tx.auth_tx.transaction().public_key); + if self.store.acc_store.get_account_nonce(&signer_addres) + != native_transfer_action.nonce + { + return Err(TransactionMalformationErrorKind::NonceMismatch { tx: tx_hash }); + } + let from_balance = self .store .acc_store @@ -406,7 +408,6 @@ mod tests { secret_r: [0; 32], sc_addr: "sc_addr".to_string(), state_changes: (serde_json::Value::Null, 0), - nonce: 0, }; Transaction::new(body, SignaturePrivateKey::random(&mut rng)) } @@ -422,6 +423,7 @@ mod tests { let native_token_transfer = PublicNativeTokenSend { from, + nonce, to, balance_to_move, }; @@ -441,7 +443,6 @@ mod tests { secret_r: [0; 32], sc_addr: "sc_addr".to_string(), state_changes: (serde_json::Value::Null, 0), - nonce, }; Transaction::new(body, signing_key) } diff --git a/sequencer_core/src/sequencer_store/block_store.rs b/sequencer_core/src/sequencer_store/block_store.rs index be07c9b..dbefdc2 100644 --- a/sequencer_core/src/sequencer_store/block_store.rs +++ b/sequencer_core/src/sequencer_store/block_store.rs @@ -95,7 +95,6 @@ mod tests { secret_r: Default::default(), sc_addr: Default::default(), state_changes: Default::default(), - nonce: 1, }; let tx = Transaction::new(body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap()); ( diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index fa89558..77c6e8b 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -288,7 +288,6 @@ mod tests { secret_r: Default::default(), sc_addr: Default::default(), state_changes: Default::default(), - nonce: 0, }; let tx = Transaction::new(tx_body, SignaturePrivateKey::from_slice(&[1; 32]).unwrap()); @@ -500,7 +499,7 @@ mod tests { let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_transaction_by_hash", - "params": { "hash": "b70b861373b99a509b27a0c61d6340762c9a0c0026520921d92218712efc3bca"}, + "params": { "hash": "a5210ef33912a448cfe6eda43878c144df81f7bdf51d19b5ddf97be11806a6ed"}, "id": 1 }); @@ -524,10 +523,9 @@ mod tests { "tx_kind": "Shielded", "utxo_commitments_created_hashes": [], "utxo_commitments_spent_hashes": [], - "nonce": 0, }, "public_key": "3056301006072A8648CE3D020106052B8104000A034200041B84C5567B126440995D3ED5AABA0565D71E1834604819FF9C17F5E9D5DD078F70BEAF8F588B541507FED6A642C5AB42DFDF8120A7F639DE5122D47A69A8E8D1", - "signature": "50AEACE783026D0B6CE221474A928A05A99E2942246DF1C79162C08175F80744746E4A00D6C7F70BDBCF6D7B3668334396B9378FB0F58DC2E8A9B13F3BF001C4" + "signature": "A4E0D6A25BE829B006124F0DFD766427967AA3BEA96C29219E79BB2CC871891F384748C27E28718A4450AA78709FBF1A57DB33BCD575A2C819D2A439C2D878E6" } } });