From e9afb2f4ad347816b1e22520780a05d0768edbd0 Mon Sep 17 00:00:00 2001 From: Robert Miller Date: Fri, 10 Nov 2023 16:50:09 -0500 Subject: [PATCH 1/6] Fix error handling for LackOfFundForMaxFee --- crates/primitives/src/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index a6b3917d95..1acade5334 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -227,7 +227,7 @@ impl Env { account.info.balance = balance_check; } else { return Err(InvalidTransaction::LackOfFundForMaxFee { - fee: self.tx.gas_limit, + fee: balance_check, balance: account.info.balance, }); } From f3329662a1aeec2eadbcda60020977e7a5d5cfeb Mon Sep 17 00:00:00 2001 From: Robert Miller Date: Fri, 10 Nov 2023 17:04:55 -0500 Subject: [PATCH 2/6] fix types in LackOfFundForMaxFee --- crates/primitives/src/result.rs | 2 +- crates/revm/src/evm_impl.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 6688269277..189414c944 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -180,7 +180,7 @@ pub enum InvalidTransaction { RejectCallerWithCode, /// Transaction account does not have enough amount of ether to cover transferred value and gas_limit*gas_price. LackOfFundForMaxFee { - fee: u64, + fee: U256, balance: U256, }, /// Overflow payment in transaction. diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 6990f1b437..8593ee0d21 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -73,7 +73,7 @@ impl<'a, SPEC: Spec, DB: Database> EVMImpl<'a, SPEC, DB> { }; return Err(EVMError::Transaction( InvalidTransaction::LackOfFundForMaxFee { - fee: u64_cost, + fee: U256::from(u64_cost), balance: acc.info.balance, }, )); @@ -827,7 +827,7 @@ mod tests { ), Err(EVMError::Transaction( InvalidTransaction::LackOfFundForMaxFee { - fee: 101u64, + fee: U256::from(101), balance: U256::from(100), }, )) From 2ce7373665d17cd0520f2378932c242b1be2823d Mon Sep 17 00:00:00 2001 From: rakita Date: Sun, 12 Nov 2023 07:53:12 +0100 Subject: [PATCH 3/6] chore: Box U256 in Error --- crates/primitives/src/env.rs | 4 ++-- crates/primitives/src/result.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 1acade5334..9e5a4c92d0 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -227,8 +227,8 @@ impl Env { account.info.balance = balance_check; } else { return Err(InvalidTransaction::LackOfFundForMaxFee { - fee: balance_check, - balance: account.info.balance, + fee: Box::new(balance_check), + balance: Box::new(account.info.balance), }); } } diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 189414c944..d69de8b820 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -126,7 +126,7 @@ impl Output { } /// Main EVM error. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum EVMError { /// Transaction validation error. @@ -157,7 +157,7 @@ impl From for EVMError { } /// Transaction validation error. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum InvalidTransaction { /// When using the EIP-1559 fee model introduced in the London upgrade, transactions specify two primary fee fields: @@ -180,8 +180,8 @@ pub enum InvalidTransaction { RejectCallerWithCode, /// Transaction account does not have enough amount of ether to cover transferred value and gas_limit*gas_price. LackOfFundForMaxFee { - fee: U256, - balance: U256, + fee: Box, + balance: Box, }, /// Overflow payment in transaction. OverflowPaymentInTransaction, From 3871324f7c249f4e6f67f085df549ce014d458dd Mon Sep 17 00:00:00 2001 From: rakita Date: Sun, 12 Nov 2023 08:03:14 +0100 Subject: [PATCH 4/6] set proper fee for optimism case --- crates/revm/src/evm_impl.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 8593ee0d21..3d1caa4cc5 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -66,15 +66,10 @@ impl<'a, SPEC: Spec, DB: Database> EVMImpl<'a, SPEC, DB> { .map_err(EVMError::Database)? .0; if l1_cost.gt(&acc.info.balance) { - let u64_cost = if U256::from(u64::MAX).lt(&l1_cost) { - u64::MAX - } else { - l1_cost.as_limbs()[0] - }; return Err(EVMError::Transaction( InvalidTransaction::LackOfFundForMaxFee { - fee: U256::from(u64_cost), - balance: acc.info.balance, + fee: Box::new(l1_cost), + balance: Box::new(acc.info.balance), }, )); } From 58821673c83e6f18362a821ab995ac70ac5d2f1e Mon Sep 17 00:00:00 2001 From: rakita Date: Sun, 12 Nov 2023 08:11:55 +0100 Subject: [PATCH 5/6] tests --- crates/revm/src/evm_impl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 3d1caa4cc5..99e509e32d 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -822,8 +822,8 @@ mod tests { ), Err(EVMError::Transaction( InvalidTransaction::LackOfFundForMaxFee { - fee: U256::from(101), - balance: U256::from(100), + fee: Box::new(U256::from(101)), + balance: Box::new(U256::from(100)), }, )) ); From 07a6cd95ff422dd760104ed47d7531be1d7dbb34 Mon Sep 17 00:00:00 2001 From: rakita Date: Sun, 12 Nov 2023 08:35:19 +0100 Subject: [PATCH 6/6] use alloc box --- crates/primitives/src/env.rs | 1 + crates/primitives/src/result.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 9e5a4c92d0..e6c91ceb07 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -3,6 +3,7 @@ use crate::{ InvalidTransaction, Spec, SpecId, B256, GAS_PER_BLOB, KECCAK_EMPTY, MAX_BLOB_NUMBER_PER_BLOCK, MAX_INITCODE_SIZE, U256, VERSIONED_HASH_VERSION_KZG, }; +use alloc::boxed::Box; use core::cmp::{min, Ordering}; /// EVM environment configuration. diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index d69de8b820..9b1583b227 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -1,5 +1,5 @@ use crate::{Address, Bytes, Log, State, U256}; -use alloc::vec::Vec; +use alloc::{boxed::Box, vec::Vec}; use core::fmt; /// Result of EVM execution.