Skip to content

Commit f6497e4

Browse files
authored
core: Modify refund gas behaviour for floorgas and update EEST (#13522)
- Fix an issue where after the refund the gasUsed could go below floor gas - Update spec tests for devnet-5 to release 1.2.0 - Update spec test version in Hive-EEST
1 parent a2d9394 commit f6497e4

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

.github/workflows/test-hive-eest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
echo -e "\n\n============================================================"
4848
echo "Running test: ${1}"
4949
echo -e "\n"
50-
./hive --sim 'ethereum/eest/consume-engine' --client erigon --sim.buildarg fixtures=https://github.com/ethereum/execution-spec-tests/releases/download/pectra-devnet-5%40v1.1.0/fixtures_pectra-devnet-5.tar.gz --sim.buildarg branch=pectra-devnet-5 2>&1 | tee output.log || {
50+
./hive --sim 'ethereum/eest/consume-engine' --client erigon --sim.buildarg fixtures=https://github.com/ethereum/execution-spec-tests/releases/download/pectra-devnet-5%40v1.2.0/fixtures_pectra-devnet-5.tar.gz --sim.buildarg branch=pectra-devnet-5 2>&1 | tee output.log || {
5151
if [ $? -gt 0 ]; then
5252
echo "Exitcode gt 0"
5353
fi

core/state_transition.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

params/protocol_params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ const (
166166
Bls12381MapFp2ToG2Gas uint64 = 23800 // Gas price for BLS12-381 mapping field element to G2 operation
167167

168168
// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
169-
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529
169+
// up to half the consumed gas could be refunded.
170170
RefundQuotient uint64 = 2
171-
RefundQuotientEIP3529 uint64 = 5
171+
RefundQuotientEIP3529 uint64 = 5 // After EIP-3529: refunds are capped to gasUsed / 5
172172

173173
// EIP-4844: Shard Blob Transactions
174174
PointEvaluationGas uint64 = 50000

tests/execution-spec-tests

0 commit comments

Comments
 (0)