Skip to content

Commit

Permalink
fix: Use saturating_add instead of checked_add in finalize (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Aug 22, 2022
1 parent 1069e3f commit 97b1631
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,10 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,

let gas_refunded = min(gas.refunded(), gas.spend() / max_refund_quotient);
let acc_caller = self.data.journaled_state.state().get_mut(&caller).unwrap();
if let Some(balance) = acc_caller
acc_caller.info.balance = acc_caller
.info
.balance
.checked_add(effective_gas_price * (gas.remaining() + gas_refunded))
{
acc_caller.info.balance = balance
}
.saturating_add(effective_gas_price * (gas.remaining() + gas_refunded));

// EIP-1559
let coinbase_gas_price = if SPEC::enabled(LONDON) {
Expand All @@ -249,13 +246,10 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
.state()
.get_mut(&coinbase)
.unwrap();
if let Some(balance) = acc_coinbase
acc_coinbase.info.balance = acc_coinbase
.info
.balance
.checked_add(coinbase_gas_price * (gas.spend() - gas_refunded))
{
acc_coinbase.info.balance = balance;
}
.saturating_add(coinbase_gas_price * (gas.spend() - gas_refunded));
(gas.spend() - gas_refunded, gas_refunded)
} else {
// touch coinbase
Expand Down

0 comments on commit 97b1631

Please sign in to comment.