Skip to content

Commit

Permalink
Add a buffer gas of all but one 64th for gas used on EVM.dryRun
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Jun 20, 2024
1 parent 0c0c0d2 commit 724d538
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions fvm/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,21 @@ func (bl *BlockView) DryRunTransaction(
// return without commiting the state
txResult, err := proc.run(msg, tx.Hash(), 0, tx.Type())
if txResult.Successful() {
// As mentioned in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-150.md#specification
// Define "all but one 64th" of N as N - floor(N / 64).
// If a call asks for more gas than the maximum allowed amount
// (i.e. the total amount of gas remaining in the parent after subtracting
// the gas cost of the call and memory expansion), do not return an OOG error;
// instead, if a call asks for more gas than all but one 64th of the maximum
// allowed amount, call with all but one 64th of the maximum allowed amount of
// gas (this is equivalent to a version of EIP-901 plus EIP-1142).
// CREATE only provides all but one 64th of the parent gas to the child call.
txResult.GasConsumed = txResult.GasConsumed + (txResult.GasConsumed / 64)

// Adding `gethParams.SstoreSentryGasEIP2200` is needed for this condition:
// https://github.com/onflow/go-ethereum/blob/master/core/vm/operations_acl.go#L29-L32
txResult.GasConsumed += gethParams.SstoreSentryGasEIP2200

// Take into account any gas refunds, which are calculated only after
// transaction execution.
txResult.GasConsumed += txResult.GasRefund
Expand Down

0 comments on commit 724d538

Please sign in to comment.