From d55c8f41d748583ecd353b14f4b0c16716f2c94c Mon Sep 17 00:00:00 2001 From: MariusVanDerWijden Date: Thu, 30 Apr 2026 13:16:17 +0200 Subject: [PATCH] core: fix selfdestructs --- build/checksums.txt | 6 +++--- core/state_transition.go | 25 ++++--------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/build/checksums.txt b/build/checksums.txt index 79af0758bf..b153b6c108 100644 --- a/build/checksums.txt +++ b/build/checksums.txt @@ -5,10 +5,10 @@ # https://github.com/ethereum/execution-spec-tests/releases/download/v5.1.0 a3192784375acec7eaec492799d5c5d0c47a2909a3cc40178898e4ecd20cc416 fixtures_develop.tar.gz -# version:spec-tests-bal v5.7.0 +# version:spec-tests-bal v6.0.0 # https://github.com/ethereum/execution-spec-tests/releases -# https://github.com/ethereum/execution-spec-tests/releases/download/bal%40v5.7.0 -1b458d1d932e6b5ff4e2ac43882b48a145de5f13d2fb34833162a75e5690d2b5 fixtures_bal.tar.gz +# https://github.com/ethereum/execution-spec-tests/releases/download/bal%40v6.0.0 +683fe9a741480ca3a3b1eb98b6caaa72d461dede490358688f7194686edc2196 fixtures_bal.tar.gz # version:golang 1.25.9 # https://go.dev/dl/ diff --git a/core/state_transition.go b/core/state_transition.go index 0f22a48a2c..a2ec740e9c 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -634,10 +634,8 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { execGasUsed.StateGas = 0 } - // Refund costs for selfdestructed accounts and slots. if rules.IsAmsterdam && vmerr == nil { cpsb := st.evm.Context.CostPerGasByte - stateGasUsed := int64(cost.StateGas) + execGasUsed.StateGas var sdRefund uint64 for _, addr := range st.state.SameTxSelfDestructs() { r := params.AccountCreationSize * cpsb @@ -645,29 +643,14 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { r += uint64(st.state.GetCodeSize(addr)) * cpsb sdRefund += r } - if stateGasUsed < 0 { + if execGasUsed.StateGas <= 0 { sdRefund = 0 - } else if sdRefund > uint64(stateGasUsed) { - sdRefund = uint64(stateGasUsed) + } else if sdRefund > uint64(execGasUsed.StateGas) { + sdRefund = uint64(execGasUsed.StateGas) } if sdRefund > 0 { st.gasRemaining.StateGas += sdRefund - if execGasUsed.StateGas >= int64(sdRefund) { - execGasUsed.StateGas -= int64(sdRefund) - } else { - var extra uint64 - if execGasUsed.StateGas > 0 { - extra = sdRefund - uint64(execGasUsed.StateGas) - } else { - extra = sdRefund - } - execGasUsed.StateGas = 0 - if cost.StateGas >= extra { - cost.StateGas -= extra - } else { - cost.StateGas = 0 - } - } + execGasUsed.StateGas -= int64(sdRefund) } }