From f8c925c265cfc0b38be16b38005a362bc44a7e14 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Sat, 17 May 2025 17:53:12 -0300 Subject: [PATCH 01/18] add clippy to CI --- ci_scripts/lint-ubuntu.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci_scripts/lint-ubuntu.sh b/ci_scripts/lint-ubuntu.sh index d30ef67..7def8fa 100644 --- a/ci_scripts/lint-ubuntu.sh +++ b/ci_scripts/lint-ubuntu.sh @@ -6,4 +6,7 @@ source env.sh cargo install taplo-cli --locked cargo fmt -- --check -taplo fmt --check \ No newline at end of file +taplo fmt --check + +export RISC0_SKIP_BUILD=1 +cargo clippy --workspace --all-targets -- -D warnings \ No newline at end of file From cdd1bdbfbdb6531d6ee18a33c1fb856fda70194f Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 18 Jun 2025 13:56:09 +0300 Subject: [PATCH 02/18] fix: lints fix --- accounts/src/key_management/mod.rs | 12 ++-- common/src/rpc_primitives/message.rs | 2 +- common/src/transaction.rs | 6 +- node_core/src/chain_storage/accounts_store.rs | 8 +-- node_core/src/chain_storage/block_store.rs | 6 +- node_core/src/chain_storage/mod.rs | 11 ++-- node_core/src/chain_storage/public_context.rs | 13 ++-- node_core/src/lib.rs | 60 +++++++------------ node_core/src/pre_start.rs | 12 ++-- node_rpc/src/process.rs | 10 ++-- sc_core/src/proofs_circuits.rs | 15 ++--- sc_core/src/transaction_payloads_tools.rs | 8 +-- sequencer_core/src/lib.rs | 6 +- storage/src/lib.rs | 10 ++-- storage/src/sc_db_utils.rs | 43 +++++++------ utxo/src/utxo_core.rs | 2 +- zkvm/src/lib.rs | 12 ++-- 17 files changed, 105 insertions(+), 131 deletions(-) diff --git a/accounts/src/key_management/mod.rs b/accounts/src/key_management/mod.rs index 69b8ce0..5862967 100644 --- a/accounts/src/key_management/mod.rs +++ b/accounts/src/key_management/mod.rs @@ -136,7 +136,7 @@ mod tests { // Generate a random ephemeral public key sender let scalar = Scalar::random(&mut OsRng); - let ephemeral_public_key_sender = (ProjectivePoint::generator() * scalar).to_affine(); + let ephemeral_public_key_sender = (ProjectivePoint::GENERATOR * scalar).to_affine(); // Calculate shared secret let shared_secret = @@ -170,7 +170,7 @@ mod tests { .decrypt_data( ephemeral_public_key_sender, CipherText::from(ciphertext), - nonce.clone(), + *nonce, ) .unwrap(); @@ -190,7 +190,7 @@ mod tests { assert!(!Into::::into( address_key_holder.viewing_public_key.is_identity() )); - assert!(address_key_holder.address.as_slice().len() > 0); // Assume TreeHashType has non-zero length for a valid address + assert!(!address_key_holder.address.as_slice().is_empty()); // Assume TreeHashType has non-zero length for a valid address } #[test] @@ -232,7 +232,7 @@ mod tests { .decrypt_data( ephemeral_public_key_sender, CipherText::from(ciphertext.clone()), - incorrect_nonce.clone(), + *incorrect_nonce, ) .unwrap(); @@ -268,7 +268,7 @@ mod tests { .decrypt_data( ephemeral_public_key_sender, CipherText::from(corrupted_ciphertext), - nonce.clone(), + *nonce, ) .unwrap(); @@ -301,7 +301,7 @@ mod tests { .decrypt_data( ephemeral_public_key_sender, CipherText::from(ciphertext), - nonce.clone(), + *nonce, ) .unwrap(); diff --git a/common/src/rpc_primitives/message.rs b/common/src/rpc_primitives/message.rs index 9378b60..c6bdc58 100644 --- a/common/src/rpc_primitives/message.rs +++ b/common/src/rpc_primitives/message.rs @@ -447,7 +447,7 @@ mod tests { /// A helper for the `broken` test. /// /// Check that the given JSON string parses, but is not recognized as a valid RPC message. - + /// /// Test things that are almost but not entirely JSONRPC are rejected /// /// The reject is done by returning it as Unmatched. diff --git a/common/src/transaction.rs b/common/src/transaction.rs index 1a95fe3..efd54f3 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -237,21 +237,21 @@ impl Transaction { "Transaction utxo_commitments_spent_hashes is {:?}", self.utxo_commitments_spent_hashes .iter() - .map(|val| hex::encode(val.clone())) + .map(|val| hex::encode(*val)) .collect::>() ); info!( "Transaction utxo_commitments_created_hashes is {:?}", self.utxo_commitments_created_hashes .iter() - .map(|val| hex::encode(val.clone())) + .map(|val| hex::encode(*val)) .collect::>() ); info!( "Transaction nullifier_created_hashes is {:?}", self.nullifier_created_hashes .iter() - .map(|val| hex::encode(val.clone())) + .map(|val| hex::encode(*val)) .collect::>() ); info!( diff --git a/node_core/src/chain_storage/accounts_store.rs b/node_core/src/chain_storage/accounts_store.rs index 6cdb100..1bd6dfc 100644 --- a/node_core/src/chain_storage/accounts_store.rs +++ b/node_core/src/chain_storage/accounts_store.rs @@ -54,7 +54,7 @@ mod tests { let mut store = NodeAccountsStore::new(); let account = create_sample_account(100); - let account_addr = account.address.clone(); + let account_addr = account.address; store.register_account(account); @@ -68,7 +68,7 @@ mod tests { let mut store = NodeAccountsStore::new(); let account = create_sample_account(100); - let account_addr = account.address.clone(); + let account_addr = account.address; store.register_account(account); assert_eq!(store.accounts.len(), 1); @@ -94,8 +94,8 @@ mod tests { let account1 = create_sample_account(100); let account2 = create_sample_account(200); - let address_1 = account1.address.clone(); - let address_2 = account2.address.clone(); + let address_1 = account1.address; + let address_2 = account2.address; store.register_account(account1); store.register_account(account2); diff --git a/node_core/src/chain_storage/block_store.rs b/node_core/src/chain_storage/block_store.rs index 677f426..ba97c3c 100644 --- a/node_core/src/chain_storage/block_store.rs +++ b/node_core/src/chain_storage/block_store.rs @@ -145,8 +145,8 @@ mod tests { fn create_sample_block(block_id: u64, prev_block_id: u64) -> Block { Block { - block_id: block_id, - prev_block_id: prev_block_id, + block_id, + prev_block_id, prev_block_hash: [0; 32], hash: [1; 32], transactions: vec![], @@ -211,7 +211,7 @@ mod tests { // The genesis block should be available on reload let result = node_store.get_block_at_id(0); - assert!(!result.is_err()); + assert!(result.is_ok()); } #[test] diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index f6b1343..2467a6b 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -80,7 +80,7 @@ impl NodeChainStore { Ok(( Self { - acc_map: From::from(acc_map), + acc_map, block_store, nullifier_store, utxo_commitments_store, @@ -324,8 +324,8 @@ mod tests { fn create_sample_block(block_id: u64, prev_block_id: u64) -> Block { Block { - block_id: block_id, - prev_block_id: prev_block_id, + block_id, + prev_block_id, prev_block_hash: [0; 32], hash: [1; 32], transactions: vec![], @@ -434,9 +434,6 @@ mod tests { assert_eq!(block_id, 1); assert_eq!(recovered_store.acc_map.len(), 1); - assert_eq!( - recovered_store.utxo_commitments_store.get_root().is_some(), - true - ); + assert!(recovered_store.utxo_commitments_store.get_root().is_some()); } } diff --git a/node_core/src/chain_storage/public_context.rs b/node_core/src/chain_storage/public_context.rs index 438fa50..87ae86e 100644 --- a/node_core/src/chain_storage/public_context.rs +++ b/node_core/src/chain_storage/public_context.rs @@ -71,16 +71,11 @@ impl PublicSCContext { //`ToDo` Replace with `next_chunk` usage, when feature stabilizes in Rust for i in 0..=(ser_data.len() / 8) { - let next_chunk: Vec; - - if (i + 1) * 8 < ser_data.len() { - next_chunk = ser_data[(i * 8)..((i + 1) * 8)].iter().cloned().collect(); + let next_chunk: Vec = if (i + 1) * 8 < ser_data.len() { + ser_data[(i * 8)..((i + 1) * 8)].to_vec() } else { - next_chunk = ser_data[(i * 8)..(ser_data.len())] - .iter() - .cloned() - .collect(); - } + ser_data[(i * 8)..(ser_data.len())].to_vec() + }; u64_list.push(PublicSCContext::produce_u64_from_fit_vec(next_chunk)); } diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index 49f1285..09c6299 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -204,19 +204,18 @@ impl NodeCore { serde_json::to_vec(&ephm_key_holder.generate_ephemeral_public_key()).unwrap(); let encoded_data = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, account.key_holder.viewing_public_key, &serde_json::to_vec(&utxo).unwrap(), ); let tag = account.make_tag(); - let comm = generate_commitments(&vec![utxo]); + let comm = generate_commitments(&[utxo]); let mint_utxo_addr_bytes: Vec = zkvm::test_methods::MINT_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(mint_utxo_addr_bytes); @@ -297,7 +296,7 @@ impl NodeCore { .map(|utxo| { ( Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, account.key_holder.viewing_public_key, &serde_json::to_vec(&utxo).unwrap(), ), @@ -312,8 +311,7 @@ impl NodeCore { let mint_multiple_utxo_addr_bytes: Vec = zkvm::test_methods::MINT_UTXO_MULTIPLE_ASSETS_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(mint_multiple_utxo_addr_bytes); @@ -386,14 +384,13 @@ impl NodeCore { .key_holder .utxo_secret_key_holder .nullifier_secret_key - .to_bytes() - .to_vec(), + .to_bytes(), ); let (resulting_utxos, receipt) = prove_send_utxo(utxo, receivers)?; let utxo_hashes = resulting_utxos .iter() - .map(|(utxo, addr)| (addr.clone(), utxo.hash)) + .map(|(utxo, addr)| (*addr, utxo.hash)) .collect(); let utxos: Vec = resulting_utxos @@ -413,7 +410,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -428,8 +425,7 @@ impl NodeCore { let send_utxo_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(send_utxo_addr_bytes); @@ -535,7 +531,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -552,7 +548,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -573,8 +569,7 @@ impl NodeCore { let send_multiple_utxo_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_MULTIPLE_ASSETS_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(send_multiple_utxo_addr_bytes); @@ -654,14 +649,13 @@ impl NodeCore { .key_holder .utxo_secret_key_holder .nullifier_secret_key - .to_bytes() - .to_vec(), + .to_bytes(), ); let (resulting_utxos, receipt) = prove_send_utxo_shielded(acc, balance as u128, receivers)?; let utxo_hashes = resulting_utxos .iter() - .map(|(utxo, addr)| (addr.clone(), utxo.hash)) + .map(|(utxo, addr)| (*addr, utxo.hash)) .collect(); let utxos: Vec = resulting_utxos @@ -681,7 +675,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -696,8 +690,7 @@ impl NodeCore { let mint_utxo_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(mint_utxo_addr_bytes); @@ -782,16 +775,14 @@ impl NodeCore { .key_holder .utxo_secret_key_holder .nullifier_secret_key - .to_bytes() - .to_vec(), + .to_bytes(), ); let (resulting_balances, receipt) = prove_send_utxo_deshielded(utxo, receivers)?; let send_utxo_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(send_utxo_addr_bytes); @@ -1372,14 +1363,13 @@ impl NodeCore { .key_holder .utxo_secret_key_holder .nullifier_secret_key - .to_bytes() - .to_vec(), + .to_bytes(), ); let (resulting_utxos, receipt) = prove_send_utxo(utxo, receivers)?; let utxo_hashes = resulting_utxos .iter() - .map(|(utxo, addr)| (addr.clone(), utxo.hash)) + .map(|(utxo, addr)| (*addr, utxo.hash)) .collect(); let utxos: Vec = resulting_utxos @@ -1399,7 +1389,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -1428,8 +1418,7 @@ impl NodeCore { let send_utxo_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let sc_addr = hex::encode(send_utxo_addr_bytes); @@ -1528,10 +1517,7 @@ impl NodeCore { .send_split_tx( utxo.clone(), comm_gen_hash, - addrs_receivers - .clone() - .map(|addr| (utxo.amount / 3, addr)) - .to_vec(), + addrs_receivers.map(|addr| (utxo.amount / 3, addr)).to_vec(), visibility_list, ) .await?; diff --git a/node_core/src/pre_start.rs b/node_core/src/pre_start.rs index fe21e2b..e79dafc 100644 --- a/node_core/src/pre_start.rs +++ b/node_core/src/pre_start.rs @@ -22,8 +22,7 @@ pub async fn setup_empty_sc_states(node: &NodeChainStore) -> Result<()> { let mint_utxo_addr_bytes: Vec = zkvm::test_methods::MINT_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let mint_utxo_addr = hex::encode(mint_utxo_addr_bytes); node.block_store @@ -32,8 +31,7 @@ pub async fn setup_empty_sc_states(node: &NodeChainStore) -> Result<()> { let single_utxo_transfer_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let single_utxo_transfer_addr = hex::encode(single_utxo_transfer_addr_bytes); node.block_store.put_sc_sc_state( @@ -46,8 +44,7 @@ pub async fn setup_empty_sc_states(node: &NodeChainStore) -> Result<()> { let mint_utxo_multiple_assets_addr_bytes: Vec = zkvm::test_methods::MINT_UTXO_MULTIPLE_ASSETS_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let mint_utxo_multiple_assets_addr = hex::encode(mint_utxo_multiple_assets_addr_bytes); node.block_store.put_sc_sc_state( @@ -60,8 +57,7 @@ pub async fn setup_empty_sc_states(node: &NodeChainStore) -> Result<()> { let multiple_assets_utxo_transfer_addr_bytes: Vec = zkvm::test_methods::SEND_UTXO_MULTIPLE_ASSETS_ID .iter() - .map(|num| num.to_le_bytes()) - .flatten() + .flat_map(|num| num.to_le_bytes()) .collect(); let multiple_assets_utxo_transfer_addr = hex::encode(multiple_assets_utxo_transfer_addr_bytes); node.block_store.put_sc_sc_state( diff --git a/node_rpc/src/process.rs b/node_rpc/src/process.rs index f4937e9..bbfb281 100644 --- a/node_rpc/src/process.rs +++ b/node_rpc/src/process.rs @@ -330,17 +330,17 @@ impl JsonHandler { utxo_commitments_created_hashes: tx .utxo_commitments_created_hashes .iter() - .map(|val| hex::encode(val.clone())) + .map(hex::encode) .collect::>(), utxo_commitments_spent_hashes: tx .utxo_commitments_spent_hashes .iter() - .map(|val| hex::encode(val.clone())) + .map(hex::encode) .collect::>(), utxo_nullifiers_created_hashes: tx .nullifier_created_hashes .iter() - .map(|val| hex::encode(val.clone())) + .map(hex::encode) .collect::>(), encoded_data: tx .encoded_data @@ -529,7 +529,7 @@ impl JsonHandler { utxo_result: UTXOShortEssentialStruct { hash: hex::encode(new_utxo_rec.hash), asset: new_utxo_rec.asset.clone(), - commitment_hash: hex::encode(generate_commitments_helper(&vec![new_utxo_rec])[0]), + commitment_hash: hex::encode(generate_commitments_helper(&[new_utxo_rec])[0]), }, }; @@ -582,7 +582,7 @@ impl JsonHandler { utxo_result: UTXOShortEssentialStruct { hash: hex::encode(new_utxo_rec.hash), asset: new_utxo_rec.asset.clone(), - commitment_hash: hex::encode(generate_commitments_helper(&vec![new_utxo_rec])[0]), + commitment_hash: hex::encode(generate_commitments_helper(&[new_utxo_rec])[0]), }, }; diff --git a/sc_core/src/proofs_circuits.rs b/sc_core/src/proofs_circuits.rs index cbebe3e..caaa402 100644 --- a/sc_core/src/proofs_circuits.rs +++ b/sc_core/src/proofs_circuits.rs @@ -38,7 +38,7 @@ pub fn generate_commitments(input_utxos: &[UTXO]) -> Vec> { // takes the in_commitments[i] as a leaf, the root hash root_commitment and the path in_commitments_proofs[i][], // returns True if the in_commitments[i] is in the tree with root hash root_commitment otherwise returns False, as membership proof. pub fn validate_in_commitments_proof( - _in_commitment: &Vec, + _in_commitment: &[u8], _root_commitment: Vec, _in_commitments_proof: &[Vec], ) -> bool { @@ -65,11 +65,11 @@ fn private_kernel( nullifier_secret_key: Scalar, ) -> (Vec, Vec>) { let nullifiers: Vec<_> = input_utxos - .into_iter() - .map(|utxo| generate_nullifiers(&utxo, &nullifier_secret_key.to_bytes())) + .iter() + .map(|utxo| generate_nullifiers(utxo, &nullifier_secret_key.to_bytes())) .collect(); - let in_commitments = generate_commitments(&input_utxos); + let in_commitments = generate_commitments(input_utxos); for in_commitment in in_commitments { validate_in_commitments_proof( @@ -183,11 +183,11 @@ fn de_kernel( check_balances(public_info as u128, input_utxos); let nullifiers: Vec<_> = input_utxos - .into_iter() - .map(|utxo| generate_nullifiers(&utxo, &nullifier_secret_key.to_bytes())) + .iter() + .map(|utxo| generate_nullifiers(utxo, &nullifier_secret_key.to_bytes())) .collect(); - let in_commitments = generate_commitments(&input_utxos); + let in_commitments = generate_commitments(input_utxos); for in_commitment in in_commitments { validate_in_commitments_proof( @@ -235,6 +235,7 @@ pub fn generate_nullifiers_se(pedersen_commitment: &PedersenCommitment, nsk: &[u } #[allow(unused)] +#[allow(clippy::too_many_arguments)] fn se_kernel( root_commitment: &[u8], root_nullifier: [u8; 32], diff --git a/sc_core/src/transaction_payloads_tools.rs b/sc_core/src/transaction_payloads_tools.rs index 24ad8f2..9af9bfa 100644 --- a/sc_core/src/transaction_payloads_tools.rs +++ b/sc_core/src/transaction_payloads_tools.rs @@ -43,7 +43,7 @@ pub fn encode_utxos_to_receivers( let ephm_key_holder = &receiver.produce_ephemeral_key_holder(); let encoded_data = Account::encrypt_data( - &ephm_key_holder, + ephm_key_holder, receiver.key_holder.viewing_public_key, &serde_json::to_vec(&utxo).unwrap(), ); @@ -66,8 +66,7 @@ pub fn generate_nullifiers_spent_utxos(utxos_spent: Vec<(UTXO, &Account)>) -> Ve .key_holder .utxo_secret_key_holder .nullifier_secret_key - .to_bytes() - .to_vec(), + .to_bytes(), ); all_nullifiers.push(nullifier); @@ -91,8 +90,7 @@ pub fn generate_secret_random_commitment( .key_holder .utxo_secret_key_holder .viewing_secret_key - .to_bytes() - .to_vec(), + .to_bytes(), )?, generator_blinding_factor: Tweak::new(&mut thread_rng()), }; diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 7a083f1..16b6ae7 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -306,12 +306,14 @@ mod tests { } } - fn common_setup(mut sequencer: &mut SequencerCore) { + fn common_setup(sequencer: &mut SequencerCore) { let tx = create_dummy_transaction([12; 32], vec![[9; 32]], vec![[7; 32]], vec![[8; 32]]); let tx_mempool = TransactionMempool { tx }; sequencer.mempool.push_item(tx_mempool); - sequencer.produce_new_block_with_mempool_transactions(); + sequencer + .produce_new_block_with_mempool_transactions() + .unwrap(); } #[test] diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 7616842..ac54406 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -316,7 +316,7 @@ impl RocksDBIO { let cf_sc = self.sc_column(); let sc_addr_loc = format!("{sc_addr:?}{SC_LEN_SUFFIX}"); - let sc_len_addr = sc_addr_loc.as_str().as_bytes(); + let sc_len_addr = sc_addr_loc.as_bytes(); self.db .put_cf(&cf_sc, sc_len_addr, length.to_be_bytes()) @@ -360,7 +360,7 @@ impl RocksDBIO { let cf_sc = self.sc_column(); let sc_addr_loc = format!("{sc_addr:?}{SC_LEN_SUFFIX}"); - let sc_len_addr = sc_addr_loc.as_str().as_bytes(); + let sc_len_addr = sc_addr_loc.as_bytes(); let sc_len = self .db @@ -379,11 +379,11 @@ impl RocksDBIO { ///Get full sc state from DB pub fn get_sc_sc_state(&self, sc_addr: &str) -> DbResult> { let cf_sc = self.sc_column(); - let sc_len = self.get_sc_sc_state_len(&sc_addr)?; + let sc_len = self.get_sc_sc_state_len(sc_addr)?; let mut data_blob_list = vec![]; for id in 0..sc_len { - let blob_addr = produce_address_for_data_blob_at_id(&sc_addr, id); + let blob_addr = produce_address_for_data_blob_at_id(sc_addr, id); let blob = self .db @@ -541,7 +541,7 @@ impl RocksDBIO { ///Creates address for sc data blob at corresponding id fn produce_address_for_data_blob_at_id(sc_addr: &str, id: usize) -> Vec { - let mut prefix_bytes: Vec = sc_addr.as_bytes().iter().cloned().collect(); + let mut prefix_bytes: Vec = sc_addr.as_bytes().to_vec(); let id_bytes = id.to_be_bytes(); diff --git a/storage/src/sc_db_utils.rs b/storage/src/sc_db_utils.rs index b059de7..577ceb6 100644 --- a/storage/src/sc_db_utils.rs +++ b/storage/src/sc_db_utils.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use serde::{de::Error, Deserialize, Serialize}; use crate::SC_DATA_BLOB_SIZE; @@ -49,6 +51,7 @@ impl DataBlob { } } +#[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum DataBlobChangeVariant { Created { @@ -95,19 +98,11 @@ pub fn produce_blob_list_from_sc_public_state( //`ToDo` Replace with `next_chunk` usage, when feature stabilizes in Rust for i in 0..=(ser_data.len() / SC_DATA_BLOB_SIZE) { - let next_chunk: Vec; - - if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() { - next_chunk = ser_data[(i * SC_DATA_BLOB_SIZE)..((i + 1) * SC_DATA_BLOB_SIZE)] - .iter() - .cloned() - .collect(); + let next_chunk: Vec = if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() { + ser_data[(i * SC_DATA_BLOB_SIZE)..((i + 1) * SC_DATA_BLOB_SIZE)].to_vec() } else { - next_chunk = ser_data[(i * SC_DATA_BLOB_SIZE)..(ser_data.len())] - .iter() - .cloned() - .collect(); - } + ser_data[(i * SC_DATA_BLOB_SIZE)..(ser_data.len())].to_vec() + }; blob_list.push(produce_blob_from_fit_vec(next_chunk)); } @@ -126,17 +121,21 @@ pub fn compare_blob_lists( let old_len = blob_list_old.len(); let new_len = blob_list_new.len(); - if old_len > new_len { - for id in new_len..old_len { - changed_ids.push(DataBlobChangeVariant::Deleted { id }); + match old_len.cmp(&new_len) { + Ordering::Greater => { + for id in new_len..old_len { + changed_ids.push(DataBlobChangeVariant::Deleted { id }); + } } - } else if new_len > old_len { - for id in old_len..new_len { - changed_ids.push(DataBlobChangeVariant::Created { - id, - blob: blob_list_new[id], - }); + Ordering::Less => { + for (id, blob_item) in blob_list_new.iter().enumerate().take(new_len).skip(old_len) { + changed_ids.push(DataBlobChangeVariant::Created { + id, + blob: *blob_item, + }); + } } + Ordering::Equal => {} } loop { @@ -172,7 +171,7 @@ mod tests { #[test] fn test_produce_blob_from_fit_vec() { - let data = (0..0 + 255).collect(); + let data = (0..255).collect(); let blob = produce_blob_from_fit_vec(data); assert_eq!(blob.0[..4], [0, 1, 2, 3]); } diff --git a/utxo/src/utxo_core.rs b/utxo/src/utxo_core.rs index 4e40ce3..07a8830 100644 --- a/utxo/src/utxo_core.rs +++ b/utxo/src/utxo_core.rs @@ -58,7 +58,7 @@ impl UTXO { } pub fn create_utxo_from_payload(payload_with_asset: UTXOPayload) -> Self { let mut hasher = sha2::Sha256::new(); - hasher.update(&payload_with_asset.to_bytes()); + hasher.update(payload_with_asset.to_bytes()); let hash = ::from(hasher.finalize_fixed()); Self { diff --git a/zkvm/src/lib.rs b/zkvm/src/lib.rs index 7ab1225..cf3620b 100644 --- a/zkvm/src/lib.rs +++ b/zkvm/src/lib.rs @@ -160,12 +160,12 @@ pub fn prove_send_utxo_multiple_assets_one_receiver( digest .0 .into_iter() - .map(|payload| UTXO::create_utxo_from_payload(payload)) + .map(UTXO::create_utxo_from_payload) .collect(), digest .1 .into_iter() - .map(|payload| UTXO::create_utxo_from_payload(payload)) + .map(UTXO::create_utxo_from_payload) .collect(), receipt, )) @@ -432,7 +432,7 @@ mod tests { let (digest, receipt) = prove(vec![message, message_2], SUMMATION_ELF).unwrap(); - verify(receipt, SUMMATION_ID); + let _ = verify(receipt, SUMMATION_ID); assert_eq!(digest, message + message_2); } @@ -443,7 +443,7 @@ mod tests { let (digest, receipt) = prove(vec![message, message_2], SUMMATION_ELF).unwrap(); - verify(receipt, SUMMATION_ID); + let _ = verify(receipt, SUMMATION_ID); assert_eq!(digest, message + message_2); } @@ -454,7 +454,7 @@ mod tests { let (digest, receipt) = prove(vec![message, message_2], MULTIPLICATION_ELF).unwrap(); - verify(receipt, MULTIPLICATION_ID); + let _ = verify(receipt, MULTIPLICATION_ID); assert_eq!(digest, message * message_2); } @@ -465,7 +465,7 @@ mod tests { let (digest, receipt) = prove(vec![message, message_2], MULTIPLICATION_ELF).unwrap(); - verify(receipt, MULTIPLICATION_ID); + let _ = verify(receipt, MULTIPLICATION_ID); assert_eq!(digest, message * message_2); } From f4912661059f20a5f47a6a93dd57559086228912 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 18 Jun 2025 14:32:30 +0300 Subject: [PATCH 03/18] fix: lint fix 2 --- common/src/transaction.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/transaction.rs b/common/src/transaction.rs index efd54f3..bc25abf 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -209,7 +209,7 @@ impl ActionData { .into_iter() .map(|owned_utxo| owned_utxo.into()) .collect(); - format!("Published utxos {:?}", pub_own_utxo) + format!("Published utxos {pub_own_utxo:?}") } } } From f9eee73ef4a85c89513d636900f2f3d7a8e6820c Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 18 Jun 2025 14:52:02 +0300 Subject: [PATCH 04/18] fix: lint fix 3 --- zkvm/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zkvm/src/lib.rs b/zkvm/src/lib.rs index cf3620b..2ad2f14 100644 --- a/zkvm/src/lib.rs +++ b/zkvm/src/lib.rs @@ -9,6 +9,7 @@ pub mod gas_calculator; pub use test_methods; +#[allow(clippy::result_large_err)] pub fn gas_limits_check( input_buffer: INP, elf: &[u8], @@ -31,6 +32,7 @@ pub fn gas_limits_check( Ok(()) } +#[allow(clippy::result_large_err)] pub fn prove_mint_utxo( amount_to_mint: u128, owner: AccountAddress, @@ -66,6 +68,7 @@ pub fn prove_mint_utxo( Ok((UTXO::create_utxo_from_payload(digest), receipt)) } +#[allow(clippy::result_large_err)] pub fn prove_send_utxo( spent_utxo: UTXO, owners_parts: Vec<(u128, AccountAddress)>, @@ -118,6 +121,7 @@ pub fn prove_send_utxo( )) } +#[allow(clippy::result_large_err)] pub fn prove_send_utxo_multiple_assets_one_receiver( spent_utxos: Vec, number_to_send: usize, @@ -171,6 +175,7 @@ pub fn prove_send_utxo_multiple_assets_one_receiver( )) } +#[allow(clippy::result_large_err)] pub fn prove_send_utxo_shielded( owner: AccountAddress, amount: u128, @@ -226,6 +231,7 @@ pub fn prove_send_utxo_shielded( )) } +#[allow(clippy::result_large_err)] pub fn prove_send_utxo_deshielded( spent_utxo: UTXO, owners_parts: Vec<(u128, AccountAddress)>, @@ -278,6 +284,7 @@ pub fn prove_send_utxo_deshielded( )) } +#[allow(clippy::result_large_err)] pub fn prove_mint_utxo_multiple_assets( amount_to_mint: u128, number_of_assets: usize, From 48a43eb268e478525fa939596ec1774a1604773d Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 18 Jun 2025 15:58:15 +0300 Subject: [PATCH 05/18] fix: lint fix 4 --- node_core/src/chain_storage/mod.rs | 3 +-- sequencer_core/src/lib.rs | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index 2467a6b..aaeef44 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -242,8 +242,7 @@ impl NodeChainStore { ); info!( - "Snapshot executed at {:?} with results {snapshot_trace:#?}", - block_id + "Snapshot executed at {block_id:?} with results {snapshot_trace:#?}" ); } } diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 16b6ae7..301c74c 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -131,23 +131,20 @@ impl SequencerCore { //Tree checks let tx_tree_check = self.store.pub_tx_store.get_tx(*hash).is_some(); - let nullifier_tree_check = nullifier_created_hashes - .iter() - .map(|nullifier_hash| { - self.store.nullifier_store.contains(&UTXONullifier { - utxo_hash: *nullifier_hash, - }) + let nullifier_tree_check = nullifier_created_hashes.iter().any(|nullifier_hash| { + self.store.nullifier_store.contains(&UTXONullifier { + utxo_hash: *nullifier_hash, }) - .any(|check| check); - let utxo_commitments_check = utxo_commitments_created_hashes - .iter() - .map(|utxo_commitment_hash| { - self.store - .utxo_commitments_store - .get_tx(*utxo_commitment_hash) - .is_some() - }) - .any(|check| check); + }); + let utxo_commitments_check = + utxo_commitments_created_hashes + .iter() + .any(|utxo_commitment_hash| { + self.store + .utxo_commitments_store + .get_tx(*utxo_commitment_hash) + .is_some() + }); if tx_tree_check { return Err(TransactionMalformationErrorKind::TxHashAlreadyPresentInTree { tx: *hash }); From ac697c0bd88ab8f1bf281504d9f76ebc5eb40e38 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 18 Jun 2025 16:59:29 +0300 Subject: [PATCH 06/18] fix: lint fix 5 --- node_rpc/src/net_utils.rs | 2 +- sequencer_rpc/src/net_utils.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node_rpc/src/net_utils.rs b/node_rpc/src/net_utils.rs index 6d68b26..215106c 100644 --- a/node_rpc/src/net_utils.rs +++ b/node_rpc/src/net_utils.rs @@ -53,7 +53,7 @@ pub fn new_http_server( polling_config, limits_config, } = config; - info!(target:"network", "Starting http server at {}", addr); + info!(target:"network", "Starting http server at {addr}"); let handler = web::Data::new(JsonHandler { polling_config, node_core_config: node_config, diff --git a/sequencer_rpc/src/net_utils.rs b/sequencer_rpc/src/net_utils.rs index 351d09b..b719a8c 100644 --- a/sequencer_rpc/src/net_utils.rs +++ b/sequencer_rpc/src/net_utils.rs @@ -53,7 +53,7 @@ pub fn new_http_server( polling_config, limits_config, } = config; - info!(target:NETWORK, "Starting http server at {}", addr); + info!(target:NETWORK, "Starting http server at {addr}"); let handler = web::Data::new(JsonHandler { polling_config, sequencer_state: seuquencer_core.clone(), From 3f9d671fb1f48d679a0c5c2d11d1ab1ecfa57024 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 18 Jun 2025 17:26:57 +0300 Subject: [PATCH 07/18] fix: lint fix probably latest --- sequencer_core/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 301c74c..9b84982 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -263,7 +263,7 @@ mod tests { let mut rng = rand::thread_rng(); let random_u8: u8 = rng.gen(); - let path_str = format!("/tmp/sequencer_{:?}", random_u8); + let path_str = format!("/tmp/sequencer_{random_u8:?}"); SequencerConfig { home: PathBuf::from(path_str), From b9d3f921e916a703aac75fd6339008b6a4c17f0f Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 18 Jul 2025 11:13:45 +0300 Subject: [PATCH 08/18] fix: latest lint fixes --- node_core/src/lib.rs | 14 ++++++------ sc_core/src/blob_utils.rs | 22 +++++++------------ sc_core/src/proofs_circuits.rs | 8 +++---- sc_core/src/transaction_payloads_tools.rs | 2 +- sequencer_core/src/lib.rs | 8 +++---- .../src/sequencer_store/accounts_store.rs | 13 +++++++++++ storage/src/sc_db_utils.rs | 3 +-- 7 files changed, 38 insertions(+), 32 deletions(-) diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index 6db11b4..a7aa422 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -207,7 +207,7 @@ impl NodeCore { serde_json::to_vec(&ephm_key_holder.generate_ephemeral_public_key()).unwrap(); let encoded_data = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, account.key_holder.viewing_public_key, &serde_json::to_vec(&utxo).unwrap(), ); @@ -299,7 +299,7 @@ impl NodeCore { .map(|utxo| { ( Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, account.key_holder.viewing_public_key, &serde_json::to_vec(&utxo).unwrap(), ), @@ -413,7 +413,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -534,7 +534,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -551,7 +551,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -678,7 +678,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); @@ -1392,7 +1392,7 @@ impl NodeCore { let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap(); let (ciphertext, nonce) = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, accout_enc.key_holder.viewing_public_key, &serde_json::to_vec(&utxo_enc).unwrap(), ); diff --git a/sc_core/src/blob_utils.rs b/sc_core/src/blob_utils.rs index d0a3485..7c5a34c 100644 --- a/sc_core/src/blob_utils.rs +++ b/sc_core/src/blob_utils.rs @@ -16,19 +16,13 @@ pub fn produce_blob_list_from_sc_public_state( //`ToDo` Replace with `next_chunk` usage, when feature stabilizes in Rust for i in 0..=(ser_data.len() / SC_DATA_BLOB_SIZE) { - let next_chunk: Vec; - - if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() { - next_chunk = ser_data[(i * SC_DATA_BLOB_SIZE)..((i + 1) * SC_DATA_BLOB_SIZE)] - .iter() - .cloned() - .collect(); + let next_chunk: Vec = if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() { + ser_data[(i * SC_DATA_BLOB_SIZE)..((i + 1) * SC_DATA_BLOB_SIZE)] + .to_vec() } else { - next_chunk = ser_data[(i * SC_DATA_BLOB_SIZE)..(ser_data.len())] - .iter() - .cloned() - .collect(); - } + ser_data[(i * SC_DATA_BLOB_SIZE)..(ser_data.len())] + .to_vec() + }; blob_list.push(produce_blob_from_fit_vec(next_chunk)); } @@ -52,10 +46,10 @@ pub fn compare_blob_lists( changed_ids.push(DataBlobChangeVariant::Deleted { id }); } } else if new_len > old_len { - for id in old_len..new_len { + for (id, blob) in blob_list_new.iter().enumerate().take(new_len).skip(old_len) { changed_ids.push(DataBlobChangeVariant::Created { id, - blob: blob_list_new[id], + blob: *blob, }); } } diff --git a/sc_core/src/proofs_circuits.rs b/sc_core/src/proofs_circuits.rs index 24e7175..5143922 100644 --- a/sc_core/src/proofs_circuits.rs +++ b/sc_core/src/proofs_circuits.rs @@ -52,10 +52,10 @@ pub fn generate_commitments(input_utxos: &[UTXO]) -> Vec> { /// /// ToDo: Solve it in more scalable way pub fn validate_in_commitments_tree( - in_commitment: &Vec, + in_commitment: &[u8], commitment_tree: &UTXOCommitmentsMerkleTree, ) -> bool { - let alighned_hash: [u8; 32] = in_commitment.clone().try_into().unwrap(); + let alighned_hash: [u8; 32] = in_commitment.try_into().unwrap(); commitment_tree.get_proof(alighned_hash).is_some() } @@ -104,7 +104,7 @@ pub fn private_circuit( assert!(!public_context.nullifiers_set.contains(&nullifier)); } - (in_nullifiers, generate_commitments(&output_utxos)) + (in_nullifiers, generate_commitments(output_utxos)) } /// Check balances DE @@ -124,7 +124,7 @@ pub fn deshielded_circuit( ) -> Vec> { assert!(check_balances_de(input_utxos, output_balance)); - let in_commitments = generate_commitments(&input_utxos); + let in_commitments = generate_commitments(input_utxos); let mut in_nullifiers = vec![]; diff --git a/sc_core/src/transaction_payloads_tools.rs b/sc_core/src/transaction_payloads_tools.rs index fffde71..bf138d4 100644 --- a/sc_core/src/transaction_payloads_tools.rs +++ b/sc_core/src/transaction_payloads_tools.rs @@ -43,7 +43,7 @@ pub fn encode_utxos_to_receivers( let ephm_key_holder = EphemeralKeyHolder::new_os_random(); let encoded_data = Account::encrypt_data( - ephm_key_holder, + &ephm_key_holder, receiver.key_holder.viewing_public_key, &serde_json::to_vec(&utxo).unwrap(), ); diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index d75ce1f..83ee5c7 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -344,13 +344,13 @@ mod tests { assert_eq!(sequencer.sequencer_config.port, 8080); let acc1_addr: [u8; 32] = hex::decode( - "bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117d09a8c".to_string(), + "bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117d09a8c", ) .unwrap() .try_into() .unwrap(); let acc2_addr: [u8; 32] = hex::decode( - "20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1e376f31".to_string(), + "20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1e376f31", ) .unwrap() .try_into() @@ -398,13 +398,13 @@ mod tests { let sequencer = SequencerCore::start_from_config(config.clone()); let acc1_addr: [u8; 32] = hex::decode( - "bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117ffffff".to_string(), + "bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117ffffff", ) .unwrap() .try_into() .unwrap(); let acc2_addr: [u8; 32] = hex::decode( - "20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1effffff".to_string(), + "20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1effffff", ) .unwrap() .try_into() diff --git a/sequencer_core/src/sequencer_store/accounts_store.rs b/sequencer_core/src/sequencer_store/accounts_store.rs index 853247f..8e0d61b 100644 --- a/sequencer_core/src/sequencer_store/accounts_store.rs +++ b/sequencer_core/src/sequencer_store/accounts_store.rs @@ -85,6 +85,11 @@ impl SequencerAccountsStore { pub fn len(&self) -> usize { self.accounts.len() } + + ///Is accounts store empty + pub fn is_empty(&self) -> bool { + self.accounts.is_empty() + } } impl Default for SequencerAccountsStore { @@ -213,4 +218,12 @@ mod tests { assert!(acc_balance.is_none()); } + + #[test] + fn account_sequencer_store_is_empty_test() { + let seq_acc_store = + SequencerAccountsStore::default(); + + assert!(seq_acc_store.is_empty()); + } } diff --git a/storage/src/sc_db_utils.rs b/storage/src/sc_db_utils.rs index 0a682ba..c86828e 100644 --- a/storage/src/sc_db_utils.rs +++ b/storage/src/sc_db_utils.rs @@ -1,5 +1,3 @@ -use std::cmp::Ordering; - use serde::{de::Error, Deserialize, Serialize}; use crate::SC_DATA_BLOB_SIZE; @@ -51,6 +49,7 @@ impl DataBlob { } } +#[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] pub enum DataBlobChangeVariant { Created { From eb16534ad92444908c05f4e89bc48ad3501cf4b7 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 18 Jul 2025 11:25:50 +0300 Subject: [PATCH 09/18] fix: fmt --- sc_core/src/blob_utils.rs | 11 ++--- sequencer_core/src/lib.rs | 44 +++++++++---------- .../src/sequencer_store/accounts_store.rs | 5 +-- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/sc_core/src/blob_utils.rs b/sc_core/src/blob_utils.rs index 7c5a34c..d1210ba 100644 --- a/sc_core/src/blob_utils.rs +++ b/sc_core/src/blob_utils.rs @@ -17,11 +17,9 @@ pub fn produce_blob_list_from_sc_public_state( //`ToDo` Replace with `next_chunk` usage, when feature stabilizes in Rust for i in 0..=(ser_data.len() / SC_DATA_BLOB_SIZE) { let next_chunk: Vec = if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() { - ser_data[(i * SC_DATA_BLOB_SIZE)..((i + 1) * SC_DATA_BLOB_SIZE)] - .to_vec() + ser_data[(i * SC_DATA_BLOB_SIZE)..((i + 1) * SC_DATA_BLOB_SIZE)].to_vec() } else { - ser_data[(i * SC_DATA_BLOB_SIZE)..(ser_data.len())] - .to_vec() + ser_data[(i * SC_DATA_BLOB_SIZE)..(ser_data.len())].to_vec() }; blob_list.push(produce_blob_from_fit_vec(next_chunk)); @@ -47,10 +45,7 @@ pub fn compare_blob_lists( } } else if new_len > old_len { for (id, blob) in blob_list_new.iter().enumerate().take(new_len).skip(old_len) { - changed_ids.push(DataBlobChangeVariant::Created { - id, - blob: *blob, - }); + changed_ids.push(DataBlobChangeVariant::Created { id, blob: *blob }); } } diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 83ee5c7..1129e31 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -343,18 +343,16 @@ mod tests { assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10); assert_eq!(sequencer.sequencer_config.port, 8080); - let acc1_addr: [u8; 32] = hex::decode( - "bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117d09a8c", - ) - .unwrap() - .try_into() - .unwrap(); - let acc2_addr: [u8; 32] = hex::decode( - "20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1e376f31", - ) - .unwrap() - .try_into() - .unwrap(); + let acc1_addr: [u8; 32] = + hex::decode("bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117d09a8c") + .unwrap() + .try_into() + .unwrap(); + let acc2_addr: [u8; 32] = + hex::decode("20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1e376f31") + .unwrap() + .try_into() + .unwrap(); assert!(sequencer.store.acc_store.contains_account(&acc1_addr)); assert!(sequencer.store.acc_store.contains_account(&acc2_addr)); @@ -397,18 +395,16 @@ mod tests { let config = setup_sequencer_config_variable_initial_accounts(initial_accounts); let sequencer = SequencerCore::start_from_config(config.clone()); - let acc1_addr: [u8; 32] = hex::decode( - "bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117ffffff", - ) - .unwrap() - .try_into() - .unwrap(); - let acc2_addr: [u8; 32] = hex::decode( - "20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1effffff", - ) - .unwrap() - .try_into() - .unwrap(); + let acc1_addr: [u8; 32] = + hex::decode("bfd91e6703273a115ad7f099ef32f621243be69369d00ddef5d3a25117ffffff") + .unwrap() + .try_into() + .unwrap(); + let acc2_addr: [u8; 32] = + hex::decode("20573479053979b98d2ad09ef31a0750f22c77709bed51c4e64946bd1effffff") + .unwrap() + .try_into() + .unwrap(); assert!(sequencer.store.acc_store.contains_account(&acc1_addr)); assert!(sequencer.store.acc_store.contains_account(&acc2_addr)); diff --git a/sequencer_core/src/sequencer_store/accounts_store.rs b/sequencer_core/src/sequencer_store/accounts_store.rs index 8e0d61b..7d64491 100644 --- a/sequencer_core/src/sequencer_store/accounts_store.rs +++ b/sequencer_core/src/sequencer_store/accounts_store.rs @@ -89,7 +89,7 @@ impl SequencerAccountsStore { ///Is accounts store empty pub fn is_empty(&self) -> bool { self.accounts.is_empty() - } + } } impl Default for SequencerAccountsStore { @@ -221,8 +221,7 @@ mod tests { #[test] fn account_sequencer_store_is_empty_test() { - let seq_acc_store = - SequencerAccountsStore::default(); + let seq_acc_store = SequencerAccountsStore::default(); assert!(seq_acc_store.is_empty()); } From 3bc2f6aba7b88f489e21b09982598fe42bfd45f1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 18 Jul 2025 12:29:32 +0300 Subject: [PATCH 10/18] fix: refetch --- node_core/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index a7aa422..d18a79a 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -36,6 +36,8 @@ pub mod config; pub mod pre_start; pub mod sequencer_client; +// + fn vec_u8_to_vec_u64(bytes: Vec) -> Vec { // Pad with zeros to make sure it's a multiple of 8 let mut padded = bytes.clone(); From 7d11c95be8519898bd9c79ea558f267cd3665bdd Mon Sep 17 00:00:00 2001 From: Pravdyvy <46261001+Pravdyvy@users.noreply.github.com> Date: Fri, 18 Jul 2025 12:36:53 +0300 Subject: [PATCH 11/18] Update lint-ubuntu.sh --- ci_scripts/lint-ubuntu.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ci_scripts/lint-ubuntu.sh b/ci_scripts/lint-ubuntu.sh index 7def8fa..35a0e4a 100644 --- a/ci_scripts/lint-ubuntu.sh +++ b/ci_scripts/lint-ubuntu.sh @@ -1,7 +1,5 @@ set -e -curl -L https://risczero.com/install | bash -/home/runner/.risc0/bin/rzup install source env.sh cargo install taplo-cli --locked @@ -9,4 +7,4 @@ cargo fmt -- --check taplo fmt --check export RISC0_SKIP_BUILD=1 -cargo clippy --workspace --all-targets -- -D warnings \ No newline at end of file +cargo clippy --workspace --all-targets -- -D warnings From 9646152550115ea873edb09c2bf6e045cd4f5886 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 18 Jul 2025 14:07:06 +0300 Subject: [PATCH 12/18] fix: more lints fix --- node_core/src/chain_storage/mod.rs | 2 +- node_core/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index 38dfa4a..6412ca0 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -209,7 +209,7 @@ impl NodeChainStore { self.block_store.put_block_at_id(block)?; //Snapshot - if block_id % self.node_config.shapshot_frequency_in_blocks == 0 { + if block_id.is_multiple_of(self.node_config.shapshot_frequency_in_blocks) { //Serializing all important data structures //If we fail serialization, it is not the reason to stop running diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index d18a79a..bab62c1 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -41,7 +41,7 @@ pub mod sequencer_client; fn vec_u8_to_vec_u64(bytes: Vec) -> Vec { // Pad with zeros to make sure it's a multiple of 8 let mut padded = bytes.clone(); - while padded.len() % 8 != 0 { + while !padded.len().is_multiple_of(8) { padded.push(0); } From 59501f2ca5312c2b29e8216d68beb97b9c8c5656 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Fri, 18 Jul 2025 15:36:01 +0300 Subject: [PATCH 13/18] fix: run retry --- node_core/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index bab62c1..e76dd43 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -36,8 +36,6 @@ pub mod config; pub mod pre_start; pub mod sequencer_client; -// - fn vec_u8_to_vec_u64(bytes: Vec) -> Vec { // Pad with zeros to make sure it's a multiple of 8 let mut padded = bytes.clone(); From ca3a63a885331f12036957bce9ceb5dc6b848882 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Mon, 21 Jul 2025 11:46:01 +0300 Subject: [PATCH 14/18] fix: ci update test --- .github/workflows/ci.yml | 48 +++++----------------------------------- node_core/src/lib.rs | 2 ++ 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b717c10..9a8a6ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,35 +14,13 @@ on: name: General jobs: - build-ubuntu-latest: + ubuntu-latest-pipeline: runs-on: ubuntu-latest timeout-minutes: 60 - name: build - ubuntu-latest + name: ubuntu-latest-pipeline steps: - uses: actions/checkout@v3 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - name: build - ubuntu-latest - if: success() || failure() - run: chmod 777 ./ci_scripts/build-ubuntu.sh && ./ci_scripts/build-ubuntu.sh - - - lint: - strategy: - matrix: - platform: [ ubuntu-latest ] - runs-on: ${{ matrix.platform }} - timeout-minutes: 60 - - name: lint - ${{ matrix.crate }} - ${{ matrix.platform }} - steps: - - name: Checkout sources - uses: actions/checkout@v3 - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: @@ -53,25 +31,9 @@ jobs: - name: lint - ubuntu-latest if: success() || failure() run: chmod 777 ./ci_scripts/lint-ubuntu.sh && ./ci_scripts/lint-ubuntu.sh - - - test: - strategy: - matrix: - platform: [ ubuntu-latest ] - runs-on: ${{ matrix.platform }} - timeout-minutes: 60 - - name: test - ${{ matrix.crate }} - ${{ matrix.platform }} - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true + - name: build - ubuntu-latest + if: success() || failure() + run: chmod 777 ./ci_scripts/build-ubuntu.sh && ./ci_scripts/build-ubuntu.sh - name: test ubuntu-latest if: success() || failure() run: chmod 777 ./ci_scripts/test-ubuntu.sh && ./ci_scripts/test-ubuntu.sh diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index e76dd43..bab62c1 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -36,6 +36,8 @@ pub mod config; pub mod pre_start; pub mod sequencer_client; +// + fn vec_u8_to_vec_u64(bytes: Vec) -> Vec { // Pad with zeros to make sure it's a multiple of 8 let mut padded = bytes.clone(); From 5e3476673e47129f8643a33dcad5cf2646a9d679 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Mon, 21 Jul 2025 12:48:22 +0300 Subject: [PATCH 15/18] fix: build substraction --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a8a6ff..f7f923d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,9 +31,6 @@ jobs: - name: lint - ubuntu-latest if: success() || failure() run: chmod 777 ./ci_scripts/lint-ubuntu.sh && ./ci_scripts/lint-ubuntu.sh - - name: build - ubuntu-latest - if: success() || failure() - run: chmod 777 ./ci_scripts/build-ubuntu.sh && ./ci_scripts/build-ubuntu.sh - name: test ubuntu-latest if: success() || failure() run: chmod 777 ./ci_scripts/test-ubuntu.sh && ./ci_scripts/test-ubuntu.sh From 8604a672bdeadddbe168cbcc8e016293a62ef2f6 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 23 Jul 2025 15:53:00 +0300 Subject: [PATCH 16/18] fix: merge fix --- node_core/src/chain_storage/mod.rs | 2 -- node_core/src/lib.rs | 24 ++++++++-------------- sequencer_core/src/lib.rs | 32 +++++++++++++----------------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/node_core/src/chain_storage/mod.rs b/node_core/src/chain_storage/mod.rs index 3ee0e0b..21d9da0 100644 --- a/node_core/src/chain_storage/mod.rs +++ b/node_core/src/chain_storage/mod.rs @@ -299,7 +299,6 @@ mod tests { } fn create_dummy_transaction( - hash: TreeHashType, // execution_input: Vec, nullifier_created_hashes: Vec<[u8; 32]>, utxo_commitments_spent_hashes: Vec<[u8; 32]>, @@ -419,7 +418,6 @@ mod tests { .utxo_commitments_store .add_tx_multiple(vec![UTXOCommitment { hash: [3u8; 32] }]); store.pub_tx_store.add_tx(create_dummy_transaction( - [12; 32], vec![[9; 32]], vec![[7; 32]], vec![[8; 32]], diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index b8ea8fe..eab83ba 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -271,8 +271,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into(), + }, result_hash, )) } @@ -367,8 +366,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into(), + }, result_hashes, )) } @@ -481,8 +479,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into(), + }, utxo_hashes, )) } @@ -625,8 +622,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into(), + }, utxo_hashes_receiver, utxo_hashes_not_spent, )) @@ -752,8 +748,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into(), + }, utxo_hashes, )) } @@ -837,8 +832,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into()) + }) } pub async fn send_private_mint_tx( @@ -932,8 +926,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - ) - .into(); + ); tx.log(); Ok(self.sequencer_client.send_tx(tx, tx_roots).await?) @@ -1475,8 +1468,7 @@ impl NodeCore { secret_r, sc_addr, state_changes, - } - .into(), + }, utxo_hashes, )) } diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 1129e31..e5ddef8 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -77,7 +77,6 @@ impl SequencerCore { tx_roots: [[u8; 32]; 2], ) -> Result<(), TransactionMalformationErrorKind> { let Transaction { - hash, tx_kind, ref execution_input, ref execution_output, @@ -85,11 +84,12 @@ impl SequencerCore { ref nullifier_created_hashes, .. } = tx; + let hash = tx.hash(); let mempool_size = self.mempool.len(); if mempool_size >= self.sequencer_config.max_num_tx_in_block { - return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: *hash }); + return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: hash }); } let curr_sequencer_roots = self.get_tree_roots(); @@ -97,7 +97,7 @@ impl SequencerCore { if tx_roots != curr_sequencer_roots { return Err( TransactionMalformationErrorKind::ChainStateFurtherThanTransactionState { - tx: *hash, + tx: hash, }, ); } @@ -111,7 +111,7 @@ impl SequencerCore { //Public transactions can not make private operations. return Err( TransactionMalformationErrorKind::PublicTransactionChangedPrivateData { - tx: *hash, + tx: hash, }, ); } @@ -123,7 +123,7 @@ impl SequencerCore { //between public and private state. return Err( TransactionMalformationErrorKind::PrivateTransactionChangedPublicData { - tx: *hash, + tx: hash, }, ); } @@ -132,7 +132,7 @@ impl SequencerCore { }; //Tree checks - let tx_tree_check = self.store.pub_tx_store.get_tx(*hash).is_some(); + let tx_tree_check = self.store.pub_tx_store.get_tx(hash).is_some(); let nullifier_tree_check = nullifier_created_hashes.iter().any(|nullifier_hash| { self.store.nullifier_store.contains(&UTXONullifier { utxo_hash: *nullifier_hash, @@ -149,18 +149,18 @@ impl SequencerCore { }); if tx_tree_check { - return Err(TransactionMalformationErrorKind::TxHashAlreadyPresentInTree { tx: *hash }); + return Err(TransactionMalformationErrorKind::TxHashAlreadyPresentInTree { tx: hash }); } if nullifier_tree_check { return Err( - TransactionMalformationErrorKind::NullifierAlreadyPresentInTree { tx: *hash }, + TransactionMalformationErrorKind::NullifierAlreadyPresentInTree { tx: hash }, ); } if utxo_commitments_check { return Err( - TransactionMalformationErrorKind::UTXOCommitmentAlreadyPresentInTree { tx: *hash }, + TransactionMalformationErrorKind::UTXOCommitmentAlreadyPresentInTree { tx: hash }, ); } @@ -184,8 +184,6 @@ impl SequencerCore { tx: TransactionMempool, ) -> Result<(), TransactionMalformationErrorKind> { let Transaction { - // ToDo: remove hashing of transactions on node side [Issue #66] - hash: _, ref utxo_commitments_created_hashes, ref nullifier_created_hashes, .. @@ -298,7 +296,6 @@ mod tests { } fn create_dummy_transaction( - hash: TreeHashType, nullifier_created_hashes: Vec<[u8; 32]>, utxo_commitments_spent_hashes: Vec<[u8; 32]>, utxo_commitments_created_hashes: Vec<[u8; 32]>, @@ -306,7 +303,6 @@ mod tests { let mut rng = rand::thread_rng(); Transaction { - hash, tx_kind: TxKind::Private, execution_input: vec![], execution_output: vec![], @@ -325,7 +321,7 @@ mod tests { } fn common_setup(sequencer: &mut SequencerCore) { - let tx = create_dummy_transaction([12; 32], vec![[9; 32]], vec![[7; 32]], vec![[8; 32]]); + let tx = create_dummy_transaction(vec![[9; 32]], vec![[7; 32]], vec![[8; 32]]); let tx_mempool = TransactionMempool { tx }; sequencer.mempool.push_item(tx_mempool); @@ -447,7 +443,7 @@ mod tests { common_setup(&mut sequencer); - let tx = create_dummy_transaction([1; 32], vec![[91; 32]], vec![[71; 32]], vec![[81; 32]]); + let tx = create_dummy_transaction(vec![[91; 32]], vec![[71; 32]], vec![[81; 32]]); let tx_roots = sequencer.get_tree_roots(); let result = sequencer.transaction_pre_check(&tx, tx_roots); @@ -464,7 +460,7 @@ mod tests { common_setup(&mut sequencer); - let tx = create_dummy_transaction([2; 32], vec![[92; 32]], vec![[72; 32]], vec![[82; 32]]); + let tx = create_dummy_transaction(vec![[92; 32]], vec![[72; 32]], vec![[82; 32]]); let tx_roots = sequencer.get_tree_roots(); // Fill the mempool @@ -486,7 +482,7 @@ mod tests { common_setup(&mut sequencer); - let tx = create_dummy_transaction([3; 32], vec![[93; 32]], vec![[73; 32]], vec![[83; 32]]); + let tx = create_dummy_transaction(vec![[93; 32]], vec![[73; 32]], vec![[83; 32]]); let tx_roots = sequencer.get_tree_roots(); let tx_mempool = TransactionMempool { tx }; @@ -500,7 +496,7 @@ mod tests { let config = setup_sequencer_config(); let mut sequencer = SequencerCore::start_from_config(config); - let tx = create_dummy_transaction([4; 32], vec![[94; 32]], vec![[7; 32]], vec![[8; 32]]); + let tx = create_dummy_transaction(vec![[94; 32]], vec![[7; 32]], vec![[8; 32]]); let tx_mempool = TransactionMempool { tx }; sequencer.mempool.push_item(tx_mempool); From dfb28abbe7492ca00f4be019a851dc5c71a19008 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 23 Jul 2025 16:12:37 +0300 Subject: [PATCH 17/18] fix: ci rerun --- node_core/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/node_core/src/lib.rs b/node_core/src/lib.rs index eab83ba..995b723 100644 --- a/node_core/src/lib.rs +++ b/node_core/src/lib.rs @@ -36,8 +36,6 @@ pub mod config; pub mod pre_start; pub mod sequencer_client; -// - fn vec_u8_to_vec_u64(bytes: Vec) -> Vec { // Pad with zeros to make sure it's a multiple of 8 let mut padded = bytes.clone(); From 872986926e03a003e9d8ec9053c9479683478194 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 23 Jul 2025 17:44:40 +0300 Subject: [PATCH 18/18] fix: merge clippy fix --- accounts/src/key_management/mod.rs | 2 +- sequencer_core/src/lib.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/accounts/src/key_management/mod.rs b/accounts/src/key_management/mod.rs index 9b63a36..6fa1462 100644 --- a/accounts/src/key_management/mod.rs +++ b/accounts/src/key_management/mod.rs @@ -61,7 +61,7 @@ impl AddressKeyHolder { pub fn get_pub_account_signing_key(&self) -> SigningKey { let field_bytes = FieldBytes::from_slice(&self.pub_account_signing_key); // TODO: remove unwrap - SigningKey::from_bytes(&field_bytes).unwrap() + SigningKey::from_bytes(field_bytes).unwrap() } pub fn calculate_shared_secret_receiver( diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 5ac482e..bfde1f6 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -92,12 +92,18 @@ impl SequencerCore { let tx_hash = *tx.hash(); + let mempool_size = self.mempool.len(); + + if mempool_size >= self.sequencer_config.max_num_tx_in_block { + return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: tx_hash }); + } + let curr_sequencer_roots = self.get_tree_roots(); if tx_roots != curr_sequencer_roots { return Err( TransactionMalformationErrorKind::ChainStateFurtherThanTransactionState { - tx: hash, + tx: tx_hash, }, ); } @@ -111,7 +117,7 @@ impl SequencerCore { //Public transactions can not make private operations. return Err( TransactionMalformationErrorKind::PublicTransactionChangedPrivateData { - tx: hash, + tx: tx_hash, }, ); } @@ -123,7 +129,7 @@ impl SequencerCore { //between public and private state. return Err( TransactionMalformationErrorKind::PrivateTransactionChangedPublicData { - tx: hash, + tx: tx_hash, }, ); } @@ -132,7 +138,7 @@ impl SequencerCore { }; //Tree checks - let tx_tree_check = self.store.pub_tx_store.get_tx(hash).is_some(); + let tx_tree_check = self.store.pub_tx_store.get_tx(tx_hash).is_some(); let nullifier_tree_check = nullifier_created_hashes.iter().any(|nullifier_hash| { self.store.nullifier_store.contains(&UTXONullifier { utxo_hash: *nullifier_hash, @@ -232,7 +238,7 @@ impl SequencerCore { .pop_size(self.sequencer_config.max_num_tx_in_block); for tx in &transactions { - self.execute_check_transaction_on_state(&tx)?; + self.execute_check_transaction_on_state(tx)?; } let prev_block_hash = self