diff --git a/core/state_transition.go b/core/state_transition.go index 934ff4fbf1..f08f36ff02 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -527,6 +527,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { peakGasUsed := st.gasUsed() // Compute refund counter, capped to a refund quotient. + gasBeforeRefunds := peakGasUsed st.gasRemaining += st.calcRefund() if rules.IsPrague { // After EIP-7623: Data-heavy transactions pay the floor gas. @@ -541,7 +542,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { peakGasUsed = floorDataGas } } - st.returnGas() + st.returnGas(rules, gasBeforeRefunds) effectiveTip := msg.GasPrice if rules.IsLondon { @@ -661,7 +662,7 @@ func (st *stateTransition) calcRefund() uint64 { // returnGas returns ETH for remaining gas, // exchanged at the original rate. -func (st *stateTransition) returnGas() { +func (st *stateTransition) returnGas(rules params.Rules, gasBeforeRefunds uint64) { remaining := uint256.NewInt(st.gasRemaining) remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice)) st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn) @@ -670,9 +671,14 @@ func (st *stateTransition) returnGas() { st.evm.Config.Tracer.OnGasChange(st.gasRemaining, 0, tracing.GasChangeTxLeftOverReturned) } - // Also return remaining gas to the block gas counter so it is - // available for the next transaction. - st.gp.AddGas(st.gasRemaining) + if !rules.IsAmsterdam { + // Pre-Amsterdam return remaining gas to the block gas counter so it is + // available for the next transaction. + st.gp.AddGas(st.gasRemaining) + } else { + // Post-Amsterdam only return the remaining gas minus the refunds. + st.gp.AddGas(gasBeforeRefunds) + } } // gasUsed returns the amount of gas used up by the state transition. diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 75a277be40..b38cd4d4d0 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -397,13 +397,10 @@ const ( // execution (e.g. storage slot being cleared). this generates an increase in // gas. There is at most one of such gas change per transaction. GasChangeTxRefunds GasChangeReason = 3 - - // GasChangeTxLeftOverReturned is the amount of gas left over at the end of - // transaction's execution that will be returned to the chain. This change - // will always be a negative change as we "drain" left over gas towards 0. - // If there was no gas left at the end of execution, no such even will be - // emitted. The returned gas's value in Wei is returned to caller. There is - // at most one of such gas change per transaction. + // GasChangeTxLeftOverReturned is the amount of gas left over at the end of transaction's execution that will be returned + // to the account. This change will always be a negative change as we "drain" left over gas towards 0. If there was no gas + // left at the end of execution, no such even will be emitted. The returned gas's value in Wei is returned to caller. + // There is at most one of such gas change per transaction. GasChangeTxLeftOverReturned GasChangeReason = 4 // GasChangeCallInitialBalance is the initial balance for the call which