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

Use gas price in place of effective gas price for initial balance check #359

Merged
merged 4 commits into from
Feb 9, 2023
Merged
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
9 changes: 5 additions & 4 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,23 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
.info
.balance;

let payment_value = U256::from(gas_limit)
.checked_mul(effective_gas_price)
let balance_check = U256::from(gas_limit)
.checked_mul(self.data.env.tx.gas_price)
.and_then(|gas_cost| gas_cost.checked_add(value))
.ok_or(EVMError::Transaction(
InvalidTransaction::OverflowPaymentInTransaction,
))?;

// 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 {
if balance_check > *caller_balance && !disable_balance_check {
return Err(InvalidTransaction::LackOfFundForGasLimit.into());
}

// Reduce gas_limit*gas_price amount of caller account.
// unwrap_or can only occur if disable_balance_check is enabled
*caller_balance = caller_balance
.checked_sub(payment_value)
.checked_sub(U256::from(gas_limit) * effective_gas_price)
rakita marked this conversation as resolved.
Show resolved Hide resolved
.unwrap_or(U256::ZERO);

let mut gas = Gas::new(gas_limit);
Expand Down