@@ -504,20 +504,24 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype
504504 } else {
505505 ret , st .gasRemaining , vmerr = st .evm .Call (sender , st .to (), st .data , st .gasRemaining , st .value , bailout )
506506 }
507- gasUsed := st .gasUsed ()
508- if gasUsed < floorGas7623 && rules .IsPrague {
509- gasUsed = floorGas7623
510- st .gasRemaining = st .initialGas - gasUsed
511- }
507+
512508 if refunds && ! gasBailout {
509+ refundQuotient := params .RefundQuotient
513510 if rules .IsLondon {
514- // After EIP-3529: refunds are capped to gasUsed / 5
515- st .refundGas (params .RefundQuotientEIP3529 )
516- } else {
517- // Before EIP-3529: refunds were capped to gasUsed / 2
518- st .refundGas (params .RefundQuotient )
511+ refundQuotient = params .RefundQuotientEIP3529
512+ }
513+ gasUsed := st .gasUsed ()
514+ refund := min (gasUsed / refundQuotient , st .state .GetRefund ())
515+ gasUsed = gasUsed - refund
516+ if rules .IsPrague {
517+ gasUsed = max (floorGas7623 , gasUsed )
519518 }
519+ st .gasRemaining = st .initialGas - gasUsed
520+ st .refundGas ()
521+ } else if rules .IsPrague {
522+ st .gasRemaining = st .initialGas - max (floorGas7623 , st .gasUsed ())
520523 }
524+
521525 effectiveTip := st .gasPrice
522526 if rules .IsLondon {
523527 if st .gasFeeCap .Gt (st .evm .Context .BaseFee ) {
@@ -560,14 +564,7 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*evmtype
560564 return result , nil
561565}
562566
563- func (st * StateTransition ) refundGas (refundQuotient uint64 ) {
564- // Apply refund counter, capped to half of the used gas.
565- refund := st .gasUsed () / refundQuotient
566- if refund > st .state .GetRefund () {
567- refund = st .state .GetRefund ()
568- }
569- st .gasRemaining += refund
570-
567+ func (st * StateTransition ) refundGas () {
571568 // Return ETH for remaining gas, exchanged at the original rate.
572569 remaining := new (uint256.Int ).Mul (new (uint256.Int ).SetUint64 (st .gasRemaining ), st .gasPrice )
573570 st .state .AddBalance (st .msg .From (), remaining , tracing .BalanceIncreaseGasReturn )
0 commit comments