Skip to content

Commit

Permalink
improvement: add error details to InvalidTransaction::LackOfFundForGa…
Browse files Browse the repository at this point in the history
…sLimit
  • Loading branch information
Wodann committed Feb 8, 2023
1 parent 8c22748 commit 235ebda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{Log, State, B160};
use bytes::Bytes;
use ruint::aliases::U256;

pub type EVMResult<DB> = core::result::Result<ResultAndState, EVMError<DB>>;

Expand Down Expand Up @@ -94,7 +95,10 @@ pub enum InvalidTransaction {
/// EIP-3607 Reject transactions from senders with deployed code
RejectCallerWithCode,
/// Transaction account does not have enough amount of ether to cover transferred value and gas_limit*gas_price.
LackOfFundForGasLimit,
LackOfFundForGasLimit {
gas_limit: U256,
balance: U256,
},
/// Overflow payment in transaction.
OverflowPaymentInTransaction,
/// Nonce overflows in transaction,
Expand Down
6 changes: 5 additions & 1 deletion crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
// Check if account has enough balance for gas_limit*gas_price and value transfer.
// Transfer will be done inside `*_inner` functions.
if payment_value + value > *caller_balance && !disable_balance_check {
return Err(InvalidTransaction::LackOfFundForGasLimit.into());
return Err(InvalidTransaction::LackOfFundForGasLimit {
gas_limit: payment_value + value,
balance: *caller_balance,
}
.into());
}

// Reduce gas_limit*gas_price amount of caller account.
Expand Down

0 comments on commit 235ebda

Please sign in to comment.