Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error message for LackOfFundForMaxFee #858

Merged
merged 6 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -227,8 +228,8 @@ impl Env {
account.info.balance = balance_check;
} else {
return Err(InvalidTransaction::LackOfFundForMaxFee {
fee: self.tx.gas_limit,
balance: account.info.balance,
fee: Box::new(balance_check),
balance: Box::new(account.info.balance),
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<DBError> {
/// Transaction validation error.
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<DBError> From<InvalidTransaction> for EVMError<DBError> {
}

/// 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:
Expand All @@ -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: u64,
balance: U256,
fee: Box<U256>,
balance: Box<U256>,
},
/// Overflow payment in transaction.
OverflowPaymentInTransaction,
Expand Down
13 changes: 4 additions & 9 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: u64_cost,
balance: acc.info.balance,
fee: Box::new(l1_cost),
balance: Box::new(acc.info.balance),
},
));
}
Expand Down Expand Up @@ -827,8 +822,8 @@ mod tests {
),
Err(EVMError::Transaction(
InvalidTransaction::LackOfFundForMaxFee {
fee: 101u64,
balance: U256::from(100),
fee: Box::new(U256::from(101)),
balance: Box::new(U256::from(100)),
},
))
);
Expand Down