Skip to content

Commit

Permalink
fix(levm): fix gas refunds (#1410)
Browse files Browse the repository at this point in the history
**Motivation**

The gas refunds had a bug in the sstore calculation. Fixes all the tests
from `stShift` folder.

**Description**

Also, this PR sums the refunds to the sender's balance.
  • Loading branch information
maximopalopoli authored Dec 5, 2024
1 parent b33c626 commit 378fa53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl VM {
let mut gas_refunds = U256::zero();
if new_storage_slot_value != storage_slot.current_value {
if storage_slot.current_value == storage_slot.original_value {
if storage_slot.original_value.is_zero() && new_storage_slot_value.is_zero() {
if !storage_slot.original_value.is_zero() && new_storage_slot_value.is_zero() {
gas_refunds = gas_refunds
.checked_add(U256::from(4800))
.ok_or(VMError::GasRefundsOverflow)?;
Expand Down
6 changes: 6 additions & 0 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,12 @@ impl VM {
.checked_mul(self.env.gas_price)
.ok_or(VMError::GasLimitPriceProductOverflow)?,
)?;
self.increase_account_balance(
sender,
U256::from(report.gas_refunded)
.checked_mul(self.env.gas_price)
.ok_or(VMError::GasLimitPriceProductOverflow)?,
)?;

// Send coinbase fee
let priority_fee_per_gas = self
Expand Down

0 comments on commit 378fa53

Please sign in to comment.