Skip to content

Commit

Permalink
feat(core): refactor gas refund logic in state transition (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
johntaiko authored Dec 18, 2023
1 parent 3eb0b0f commit 566c8c3
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
st.state.SetNonce(msg.From, st.state.GetNonce(sender.Address())+1)
ret, st.gasRemaining, vmerr = st.evm.Call(sender, st.to(), msg.Data, st.gasRemaining, msg.Value)
}
if !st.msg.IsAnchor {
if !rules.IsLondon {
// Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient)
} else {
// After EIP-3529: refunds are capped to gasUsed / 5
st.refundGas(params.RefundQuotientEIP3529)
}
if !rules.IsLondon {
// Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient)
} else {
// After EIP-3529: refunds are capped to gasUsed / 5
st.refundGas(params.RefundQuotientEIP3529)
}
effectiveTip := msg.GasPrice
if rules.IsLondon {
Expand Down Expand Up @@ -469,11 +467,12 @@ func (st *StateTransition) refundGas(refundQuotient uint64) {
refund = st.state.GetRefund()
}
st.gasRemaining += refund

// Return ETH for remaining gas, exchanged at the original rate.
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gasRemaining), st.msg.GasPrice)
st.state.AddBalance(st.msg.From, remaining)

// Do not change the balance in anchor transactions.
if !st.msg.IsAnchor {
// Return ETH for remaining gas, exchanged at the original rate.
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gasRemaining), st.msg.GasPrice)
st.state.AddBalance(st.msg.From, remaining)
}
// Also return remaining gas to the block gas counter so it is
// available for the next transaction.
st.gp.AddGas(st.gasRemaining)
Expand Down

0 comments on commit 566c8c3

Please sign in to comment.