diff --git a/core/state_transition.go b/core/state_transition.go index c40c66396fdf..c5651f63c7b5 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -510,11 +510,16 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { var gasRefund uint64 if !rules.IsLondon { // Before EIP-3529: refunds were capped to gasUsed / 2 - gasRefund = st.refundGas(params.RefundQuotient) + gasRefund = st.refundAmount(params.RefundQuotient) } else { // After EIP-3529: refunds are capped to gasUsed / 5 - gasRefund = st.refundGas(params.RefundQuotientEIP3529) + gasRefund = st.refundAmount(params.RefundQuotientEIP3529) } + + if st.evm.Config.Tracer != nil && st.evm.Config.Tracer.OnGasChange != nil && gasRefund > 0 { + st.evm.Config.Tracer.OnGasChange(st.gasRemaining, st.gasRemaining+gasRefund, tracing.GasChangeTxRefunds) + } + st.gasRemaining += gasRefund if rules.IsPrague { // After EIP-7623: Data-heavy transactions pay the floor gas. if st.gasUsed() < floorDataGas { @@ -525,6 +530,8 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { } } } + st.returnGas() + effectiveTip := msg.GasPrice if rules.IsLondon { effectiveTip = new(big.Int).Sub(msg.GasFeeCap, st.evm.Context.BaseFee) @@ -615,19 +622,16 @@ func (st *stateTransition) applyAuthorization(msg *Message, auth *types.SetCodeA return nil } -func (st *stateTransition) refundGas(refundQuotient uint64) uint64 { +func (st *stateTransition) refundAmount(refundQuotient uint64) uint64 { // Apply refund counter, capped to a refund quotient refund := st.gasUsed() / refundQuotient if refund > st.state.GetRefund() { refund = st.state.GetRefund() } + return refund +} - if st.evm.Config.Tracer != nil && st.evm.Config.Tracer.OnGasChange != nil && refund > 0 { - st.evm.Config.Tracer.OnGasChange(st.gasRemaining, st.gasRemaining+refund, tracing.GasChangeTxRefunds) - } - - st.gasRemaining += refund - +func (st *stateTransition) returnGas() { // Return ETH for remaining gas, exchanged at the original rate. remaining := uint256.NewInt(st.gasRemaining) remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice)) @@ -640,8 +644,6 @@ func (st *stateTransition) refundGas(refundQuotient uint64) uint64 { // Also return remaining gas to the block gas counter so it is // available for the next transaction. st.gp.AddGas(st.gasRemaining) - - return refund } // gasUsed returns the amount of gas used up by the state transition.