diff --git a/fvm/evm/emulator/emulator.go b/fvm/evm/emulator/emulator.go index 53b247a1fa4..447d66b2384 100644 --- a/fvm/evm/emulator/emulator.go +++ b/fvm/evm/emulator/emulator.go @@ -290,26 +290,6 @@ func (bl *BlockView) DryRunTransaction( // return without committing the state txResult, err = proc.run(msg, tx.Hash(), 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 = AddOne64th(txResult.GasConsumed) - - // 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 - } // call tracer on tx end if proc.evm.Config.Tracer != nil && @@ -707,11 +687,6 @@ func (proc *procedure) run( return &res, nil } -func AddOne64th(n uint64) uint64 { - // NOTE: Go's integer division floors, but that is desirable here - return n + (n / 64) -} - func convertAndCheckValue(input *big.Int) (isValid bool, converted *uint256.Int) { // check for negative input if input.Sign() < 0 { diff --git a/fvm/evm/evm_test.go b/fvm/evm/evm_test.go index 70357202f74..0967c6ed58e 100644 --- a/fvm/evm/evm_test.go +++ b/fvm/evm/evm_test.go @@ -23,7 +23,6 @@ import ( "github.com/onflow/flow-go/fvm/environment" envMock "github.com/onflow/flow-go/fvm/environment/mock" "github.com/onflow/flow-go/fvm/evm" - "github.com/onflow/flow-go/fvm/evm/emulator" "github.com/onflow/flow-go/fvm/evm/events" "github.com/onflow/flow-go/fvm/evm/impl" "github.com/onflow/flow-go/fvm/evm/stdlib" @@ -1513,11 +1512,13 @@ func TestDryRun(t *testing.T) { evmAddress, )) + // Use the gas estimation from Evm.dryRun with some buffer + gasLimit := dryRunResult.GasConsumed + gethParams.SstoreSentryGasEIP2200 innerTxBytes := testAccount.PrepareSignAndEncodeTx(t, testContract.DeployedAt.ToCommon(), data, big.NewInt(0), - dryRunResult.GasConsumed, // use the gas estimation from Evm.dryRun + gasLimit, big.NewInt(0), ) @@ -1545,15 +1546,7 @@ func TestDryRun(t *testing.T) { require.NoError(t, err) require.Equal(t, types.StatusSuccessful, res.Status) require.Equal(t, types.ErrCodeNoError, res.ErrorCode) - // Make sure that gas consumed from `EVM.dryRun` is bigger - // than the actual gas consumption of the equivalent - // `EVM.run`. - totalGas := emulator.AddOne64th(res.GasConsumed) + gethParams.SstoreSentryGasEIP2200 - require.Equal( - t, - totalGas, - dryRunResult.GasConsumed, - ) + require.Equal(t, res.GasConsumed, dryRunResult.GasConsumed) }) }) @@ -1679,15 +1672,7 @@ func TestDryRun(t *testing.T) { require.NoError(t, err) require.Equal(t, types.StatusSuccessful, res.Status) require.Equal(t, types.ErrCodeNoError, res.ErrorCode) - // Make sure that gas consumed from `EVM.dryRun` is bigger - // than the actual gas consumption of the equivalent - // `EVM.run`. - totalGas := emulator.AddOne64th(res.GasConsumed) + gethParams.SstoreSentryGasEIP2200 - require.Equal( - t, - totalGas, - dryRunResult.GasConsumed, - ) + require.Equal(t, res.GasConsumed, dryRunResult.GasConsumed) }) }) @@ -1779,11 +1764,13 @@ func TestDryRun(t *testing.T) { evmAddress, )) + // use the gas estimation from Evm.dryRun with the necessary buffer gas + gasLimit := dryRunResult.GasConsumed + gethParams.SstoreSentryGasEIP2200 + gethParams.SstoreClearsScheduleRefundEIP3529 innerTxBytes = testAccount.PrepareSignAndEncodeTx(t, testContract.DeployedAt.ToCommon(), data, big.NewInt(0), - dryRunResult.GasConsumed, // use the gas estimation from Evm.dryRun + gasLimit, big.NewInt(0), ) @@ -1809,17 +1796,9 @@ func TestDryRun(t *testing.T) { res, err := impl.ResultSummaryFromEVMResultValue(output.Value) require.NoError(t, err) - //require.Equal(t, types.StatusSuccessful, res.Status) + require.Equal(t, types.StatusSuccessful, res.Status) require.Equal(t, types.ErrCodeNoError, res.ErrorCode) - // Make sure that gas consumed from `EVM.dryRun` is bigger - // than the actual gas consumption of the equivalent - // `EVM.run`. - totalGas := emulator.AddOne64th(res.GasConsumed) + gethParams.SstoreSentryGasEIP2200 + gethParams.SstoreClearsScheduleRefundEIP3529 - require.Equal( - t, - totalGas, - dryRunResult.GasConsumed, - ) + require.Equal(t, res.GasConsumed, dryRunResult.GasConsumed) }) })