From 5fa5ebdf5974b9276875f9b03e1eab619b4048df Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 1 May 2024 18:03:58 -0700 Subject: [PATCH 1/4] add: essential info to `TooManyBlobs` err enum --- crates/primitives/src/env.rs | 8 ++++++-- crates/primitives/src/result.rs | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 9d0bc100a1..4d6ed54305 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -172,8 +172,12 @@ impl Env { // ensure the total blob gas spent is at most equal to the limit // assert blob_gas_used <= MAX_BLOB_GAS_PER_BLOCK - if self.tx.blob_hashes.len() > MAX_BLOB_NUMBER_PER_BLOCK as usize { - return Err(InvalidTransaction::TooManyBlobs); + let num_blobs = self.tx.blob_hashes.len(); + if num_blobs > MAX_BLOB_NUMBER_PER_BLOCK as usize { + return Err(InvalidTransaction::TooManyBlobs( + num_blobs, + MAX_BLOB_NUMBER_PER_BLOCK as usize, + )); } } } else { diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 516ce25160..1a36f84c44 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -242,7 +242,7 @@ pub enum InvalidTransaction { /// `to` must be present BlobCreateTransaction, /// Transaction has more then [`crate::MAX_BLOB_NUMBER_PER_BLOCK`] blobs - TooManyBlobs, + TooManyBlobs(usize, usize), /// Blob transaction contains a versioned hash with an incorrect version BlobVersionNotSupported, /// EOF TxCreate transaction is not supported before Prague hardfork. @@ -339,7 +339,9 @@ impl fmt::Display for InvalidTransaction { } Self::EmptyBlobs => write!(f, "empty blobs"), Self::BlobCreateTransaction => write!(f, "blob create transaction"), - Self::TooManyBlobs => write!(f, "too many blobs"), + Self::TooManyBlobs(num_blobs, max) => { + write!(f, "too many blobs, have {num_blobs}, max {max}") + } Self::BlobVersionNotSupported => write!(f, "blob version not supported"), Self::EofInitcodesNotSupported => write!(f, "EOF initcodes not supported"), Self::EofCrateShouldHaveToAddress => write!(f, "EOF crate should have `to` address"), From b06fa86ee5519619ade87aa6c79bcd8e3e3a0f2a Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Thu, 2 May 2024 10:22:10 -0700 Subject: [PATCH 2/4] fix clippy --- bins/revme/src/cmd/statetest/runner.rs | 2 +- crates/revm/src/db/states/transition_account.rs | 2 +- crates/revm/src/inspector/eip3155.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bins/revme/src/cmd/statetest/runner.rs b/bins/revme/src/cmd/statetest/runner.rs index c9f8aede3a..dcf8fcc3a5 100644 --- a/bins/revme/src/cmd/statetest/runner.rs +++ b/bins/revme/src/cmd/statetest/runner.rs @@ -361,7 +361,7 @@ pub fn execute_test_suite( .build(); let mut evm = Evm::builder() .with_db(&mut state) - .modify_env(|e| *e = env.clone()) + .modify_env(|e| e.clone_from(&env)) .with_spec_id(spec_id) .build(); diff --git a/crates/revm/src/db/states/transition_account.rs b/crates/revm/src/db/states/transition_account.rs index 1dc6bc33dd..599bc290b0 100644 --- a/crates/revm/src/db/states/transition_account.rs +++ b/crates/revm/src/db/states/transition_account.rs @@ -85,7 +85,7 @@ impl TransitionAccount { /// Update new values of transition. Don't override old values. /// Both account info and old storages need to be left intact. pub fn update(&mut self, other: Self) { - self.info = other.info.clone(); + self.info.clone_from(&other.info); self.status = other.status; // if transition is from some to destroyed drop the storage. diff --git a/crates/revm/src/inspector/eip3155.rs b/crates/revm/src/inspector/eip3155.rs index b5331157dc..aec20ffd8f 100644 --- a/crates/revm/src/inspector/eip3155.rs +++ b/crates/revm/src/inspector/eip3155.rs @@ -191,7 +191,7 @@ impl Inspector for TracerEip3155 { fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { self.gas_inspector.step(interp, context); - self.stack = interp.stack.data().clone(); + self.stack.clone_from(interp.stack.data()); self.memory = if self.include_memory { Some(hex::encode_prefixed(interp.shared_memory.context_memory())) } else { From 55412584fb6a0a7edf7430bbf7bc8dae14287af4 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 3 May 2024 10:20:11 -0700 Subject: [PATCH 3/4] nit: with names Co-authored-by: rakita --- crates/primitives/src/result.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 1a36f84c44..a3199a6722 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -242,7 +242,10 @@ pub enum InvalidTransaction { /// `to` must be present BlobCreateTransaction, /// Transaction has more then [`crate::MAX_BLOB_NUMBER_PER_BLOCK`] blobs - TooManyBlobs(usize, usize), + TooManyBlobs { + max: usize, + have: usize, + }, /// Blob transaction contains a versioned hash with an incorrect version BlobVersionNotSupported, /// EOF TxCreate transaction is not supported before Prague hardfork. From c7c3c501e61c4a5fb051fe9b789c838f17799e87 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Fri, 3 May 2024 11:11:12 -0700 Subject: [PATCH 4/4] fix --- crates/primitives/src/env.rs | 8 ++++---- crates/primitives/src/result.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 4d6ed54305..99b5557149 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -174,10 +174,10 @@ impl Env { // assert blob_gas_used <= MAX_BLOB_GAS_PER_BLOCK let num_blobs = self.tx.blob_hashes.len(); if num_blobs > MAX_BLOB_NUMBER_PER_BLOCK as usize { - return Err(InvalidTransaction::TooManyBlobs( - num_blobs, - MAX_BLOB_NUMBER_PER_BLOCK as usize, - )); + return Err(InvalidTransaction::TooManyBlobs { + have: num_blobs, + max: MAX_BLOB_NUMBER_PER_BLOCK as usize, + }); } } } else { diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index a3199a6722..659c4fe357 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -243,9 +243,9 @@ pub enum InvalidTransaction { BlobCreateTransaction, /// Transaction has more then [`crate::MAX_BLOB_NUMBER_PER_BLOCK`] blobs TooManyBlobs { - max: usize, - have: usize, - }, + max: usize, + have: usize, + }, /// Blob transaction contains a versioned hash with an incorrect version BlobVersionNotSupported, /// EOF TxCreate transaction is not supported before Prague hardfork. @@ -342,8 +342,8 @@ impl fmt::Display for InvalidTransaction { } Self::EmptyBlobs => write!(f, "empty blobs"), Self::BlobCreateTransaction => write!(f, "blob create transaction"), - Self::TooManyBlobs(num_blobs, max) => { - write!(f, "too many blobs, have {num_blobs}, max {max}") + Self::TooManyBlobs { max, have } => { + write!(f, "too many blobs, have {have}, max {max}") } Self::BlobVersionNotSupported => write!(f, "blob version not supported"), Self::EofInitcodesNotSupported => write!(f, "EOF initcodes not supported"),