From 93ffca2571e3ecfbd3fb01680cf08665f63b0a9c Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 10 Mar 2026 17:24:50 +0100 Subject: [PATCH] core/vm: fix readonly in selfdestruct --- core/vm/gas_table.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index a04efc6923..570c957fbd 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -649,6 +649,9 @@ func gasCall8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory } func gasSelfdestruct8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (GasCosts, error) { + if evm.readOnly { + return GasCosts{}, ErrWriteProtection + } var ( gas GasCosts address = common.Address(stack.peek().Bytes20()) @@ -658,6 +661,10 @@ func gasSelfdestruct8037(evm *EVM, contract *Contract, stack *Stack, mem *Memory evm.StateDB.AddAddressToAccessList(address) gas.RegularGas = params.ColdAccountAccessCostEIP2929 } + // Check we have enough regular gas before we add the address to the BAL + if contract.Gas.RegularGas < gas.RegularGas { + return gas, nil + } // if empty and transfers value if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 { gas.StateGas += params.AccountCreationSize * evm.Context.CostPerGasByte