From dc505abe20d7b5270de8f901b21898631704118b Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 23 Nov 2023 11:14:46 +0200 Subject: [PATCH] Account for gas refund quotient --- core/state_transition.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 01fe81db47..71cc2b885b 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -420,12 +420,13 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { ret, st.gasRemaining, vmerr = st.evm.Call(sender, st.to(), msg.Data, st.gasRemaining, msg.Value) } + var gasRefund uint64 if !rules.IsLondon { // Before EIP-3529: refunds were capped to gasUsed / 2 - st.refundGas(params.RefundQuotient) + gasRefund = st.refundGas(params.RefundQuotient) } else { // After EIP-3529: refunds are capped to gasUsed / 5 - st.refundGas(params.RefundQuotientEIP3529) + gasRefund = st.refundGas(params.RefundQuotientEIP3529) } effectiveTip := msg.GasPrice if rules.IsLondon { @@ -446,11 +447,11 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { UsedGas: st.gasUsed(), Err: vmerr, ReturnData: ret, - GasRefund: st.state.GetRefund(), + GasRefund: gasRefund, }, nil } -func (st *StateTransition) refundGas(refundQuotient uint64) { +func (st *StateTransition) refundGas(refundQuotient uint64) uint64 { // Apply refund counter, capped to a refund quotient refund := st.gasUsed() / refundQuotient if refund > st.state.GetRefund() { @@ -465,6 +466,8 @@ func (st *StateTransition) refundGas(refundQuotient 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.