From aa2abd4b493ae3bbff4d6ad055569b29bdf9542d Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 1 Oct 2024 14:49:17 +0200 Subject: [PATCH 1/5] rusk: change default genesis timestamp to `UNIX_TIME` --- rusk/src/bin/config/chain.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rusk/src/bin/config/chain.rs b/rusk/src/bin/config/chain.rs index beeddeea2e..f9e315225a 100644 --- a/rusk/src/bin/config/chain.rs +++ b/rusk/src/bin/config/chain.rs @@ -14,9 +14,6 @@ use serde::{Deserialize, Serialize}; pub const DEFAULT_BLOCK_GAS_LIMIT: u64 = 5 * 1_000_000_000; -// Tue Sep 10 2024 20:00:00 GMT+0000 -pub const DEFAULT_GENESIS_TIMESTAMP: u64 = 1725998400; - use crate::args::Args; #[derive(Serialize, Deserialize, Clone, Default)] @@ -109,6 +106,6 @@ impl ChainConfig { .map(|n| n.as_secs()) .expect("This is heavy.") }) - .unwrap_or(DEFAULT_GENESIS_TIMESTAMP) + .unwrap_or_default() } } From 12a07943112030ba640adbd4e0f99a03b6acc86a Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 1 Oct 2024 14:49:43 +0200 Subject: [PATCH 2/5] rusk: fix `generation_timeout` optional deserialization --- rusk/src/bin/config/chain.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rusk/src/bin/config/chain.rs b/rusk/src/bin/config/chain.rs index f9e315225a..a4b250833c 100644 --- a/rusk/src/bin/config/chain.rs +++ b/rusk/src/bin/config/chain.rs @@ -23,6 +23,7 @@ pub(crate) struct ChainConfig { consensus_keys_path: Option, #[serde(with = "humantime_serde")] + #[serde(default)] generation_timeout: Option, max_queue_size: Option, From 2b316ba170c347c399db824c3c62cdb62986cf58 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 1 Oct 2024 15:10:41 +0200 Subject: [PATCH 3/5] rusk: check for double nullifiers during tx preverify --- rusk/src/lib/error.rs | 3 +++ rusk/src/lib/node/vm.rs | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/rusk/src/lib/error.rs b/rusk/src/lib/error.rs index 92f316d2ad..96dbccd85f 100644 --- a/rusk/src/lib/error.rs +++ b/rusk/src/lib/error.rs @@ -25,6 +25,8 @@ pub enum Error { OutOfGas, /// Repeated nullifier in transaction verification RepeatingNullifiers(Vec), + /// Repeated nullifier in the same transaction + DoubleNullifiers, /// Repeating a nonce that has already been used RepeatingNonce(Box, u64), /// Wrong inputs and/or outputs in the transaction verification @@ -169,6 +171,7 @@ impl fmt::Display for Error { Error::RepeatingNullifiers(n) => { write!(f, "Nullifiers repeat: {n:?}") } + Error::DoubleNullifiers => write!(f, "Double nullifiers"), Error::RepeatingNonce(account, nonce) => { let encoded_account = bs58::encode(&account.to_bytes()).into_string(); diff --git a/rusk/src/lib/node/vm.rs b/rusk/src/lib/node/vm.rs index 7413885d1e..af782125ea 100644 --- a/rusk/src/lib/node/vm.rs +++ b/rusk/src/lib/node/vm.rs @@ -122,9 +122,9 @@ impl VMExecution for Rusk { match tx { ProtocolTransaction::Phoenix(tx) => { - let existing_nullifiers = self - .existing_nullifiers(&tx.nullifiers().to_vec()) - .map_err(|e| { + let tx_nullifiers = tx.nullifiers().to_vec(); + let existing_nullifiers = + self.existing_nullifiers(&tx_nullifiers).map_err(|e| { anyhow::anyhow!("Cannot check nullifiers: {e}") })?; @@ -134,6 +134,11 @@ impl VMExecution for Rusk { return Err(anyhow::anyhow!("Invalid tx: {err}")); } + if !has_unique_elements(tx_nullifiers) { + let err = crate::Error::DoubleNullifiers; + return Err(anyhow::anyhow!("Invalid tx: {err}")); + } + match crate::verifier::verify_proof(tx) { Ok(true) => Ok(()), Ok(false) => Err(anyhow::anyhow!("Invalid proof")), @@ -228,6 +233,15 @@ impl VMExecution for Rusk { } } +fn has_unique_elements(iter: T) -> bool +where + T: IntoIterator, + T::Item: Eq + std::hash::Hash, +{ + let mut uniq = std::collections::HashSet::new(); + iter.into_iter().all(move |x| uniq.insert(x)) +} + impl Rusk { fn query_provisioners( &self, From 48ae7aa9c941edbea29e0e0168ae3b5a181c1e5e Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 1 Oct 2024 15:11:08 +0200 Subject: [PATCH 4/5] rusk: remove unused errors --- rusk/src/lib/error.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/rusk/src/lib/error.rs b/rusk/src/lib/error.rs index 96dbccd85f..65a85fc0ae 100644 --- a/rusk/src/lib/error.rs +++ b/rusk/src/lib/error.rs @@ -9,7 +9,7 @@ use std::{fmt, io}; use dusk_bytes::Serializable; use execution_core::{ signatures::bls::PublicKey as BlsPublicKey, transfer::phoenix::CoreError, - BlsScalar, Dusk, Error as ExecErr, + BlsScalar, Error as ExecErr, }; use rusk_abi::PiecrustError; @@ -47,10 +47,6 @@ pub enum Error { Vm(PiecrustError), /// IO Errors Io(io::Error), - /// Bad block height in coinbase (got, expected) - CoinbaseBlockHeight(u64, u64), - /// Bad dusk spent in coinbase (got, expected). - CoinbaseDuskSpent(Dusk, Dusk), /// Failed to produce proper state #[cfg(feature = "chain")] InconsistentState(Box), @@ -159,13 +155,6 @@ impl fmt::Display for Error { Error::Transaction(err) => write!(f, "Transaction Error: {err}"), Error::Phoenix(err) => write!(f, "Phoenix error: {err}"), Error::Other(err) => write!(f, "Other error: {err}"), - Error::CoinbaseBlockHeight(got, expected) => write!( - f, - "Coinbase has block height {got}, expected {expected}" - ), - Error::CoinbaseDuskSpent(got, expected) => { - write!(f, "Coinbase has dusk spent {got}, expected {expected}") - } Error::ProofVerification => write!(f, "Proof verification failure"), Error::OutOfGas => write!(f, "Out of gas"), Error::RepeatingNullifiers(n) => { From 466c5662e232e41b0d471509224188a41082c29f Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 1 Oct 2024 15:11:24 +0200 Subject: [PATCH 5/5] rusk: change error descriptions --- rusk/src/lib/error.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/rusk/src/lib/error.rs b/rusk/src/lib/error.rs index 65a85fc0ae..39ea449b83 100644 --- a/rusk/src/lib/error.rs +++ b/rusk/src/lib/error.rs @@ -158,7 +158,7 @@ impl fmt::Display for Error { Error::ProofVerification => write!(f, "Proof verification failure"), Error::OutOfGas => write!(f, "Out of gas"), Error::RepeatingNullifiers(n) => { - write!(f, "Nullifiers repeat: {n:?}") + write!(f, "Nullifiers already spent: {n:?}") } Error::DoubleNullifiers => write!(f, "Double nullifiers"), Error::RepeatingNonce(account, nonce) => { @@ -170,21 +170,14 @@ impl fmt::Display for Error { write!(f,"Expected: 0 < (inputs: {inputs_len}) < 5, 0 ≤ (outputs: {outputs_len}) < 3") } #[cfg(feature = "chain")] - Error::InconsistentState(verification_output) => { - write!( - f, - "Inconsistent state verification data {verification_output}", - ) + Error::InconsistentState(vo) => { + write!(f, "Inconsistent state verification data {vo}",) } Error::CommitNotFound(commit_id) => { write!(f, "Commit not found, id = {}", hex::encode(commit_id),) } Error::InvalidCreditsCount(height, credits) => { - write!( - f, - "Invalid credits count, height = {}, credits = {}", - height, credits - ) + write!(f, "Invalid credits: H= {height}, credits= {credits}",) } Error::MemoTooLarge(size) => { write!(f, "The memo size {size} is too large")