From 070c3ee238c2df09b0875dc3e97f02cf671d4977 Mon Sep 17 00:00:00 2001 From: lightclient Date: Fri, 16 Jan 2026 13:15:33 -0700 Subject: [PATCH] core: remove SelfDestruct6780 method --- core/state/statedb.go | 10 ---------- core/state/statedb_hooked.go | 4 ---- core/state/statedb_hooked_test.go | 2 +- core/vm/instructions.go | 24 +++++++++++------------- core/vm/interface.go | 5 ----- 5 files changed, 12 insertions(+), 33 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index de5c875c7e..39160aa1c7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -525,16 +525,6 @@ func (s *StateDB) SelfDestruct(addr common.Address) { } } -func (s *StateDB) SelfDestruct6780(addr common.Address) { - stateObject := s.getStateObject(addr) - if stateObject == nil { - return - } - if stateObject.newContract { - s.SelfDestruct(addr) - } -} - // SetTransientState sets transient storage for a given account. It // adds the change to the journal so that it can be rolled back // to its previous value if there is a revert. diff --git a/core/state/statedb_hooked.go b/core/state/statedb_hooked.go index e88b21b224..4ffa69b419 100644 --- a/core/state/statedb_hooked.go +++ b/core/state/statedb_hooked.go @@ -219,10 +219,6 @@ func (s *hookedStateDB) SelfDestruct(address common.Address) { s.inner.SelfDestruct(address) } -func (s *hookedStateDB) SelfDestruct6780(address common.Address) { - s.inner.SelfDestruct6780(address) -} - func (s *hookedStateDB) AddLog(log *types.Log) { // The inner will modify the log (add fields), so invoke that first s.inner.AddLog(log) diff --git a/core/state/statedb_hooked_test.go b/core/state/statedb_hooked_test.go index db3832b7d7..6fe17ec1b4 100644 --- a/core/state/statedb_hooked_test.go +++ b/core/state/statedb_hooked_test.go @@ -159,7 +159,7 @@ func TestHooks_OnCodeChangeV2(t *testing.T) { sdb.SetCode(common.Address{0xbb}, []byte{0x13, 38}, tracing.CodeChangeContractCreation) sdb.CreateContract(common.Address{0xbb}) - sdb.SelfDestruct6780(common.Address{0xbb}) + sdb.SelfDestruct(common.Address{0xbb}) sdb.Finalise(true) if len(result) != len(wants) { diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 09e1ba35fa..958cf9dedc 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -885,7 +885,7 @@ func opSelfdestruct(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) { // The funds are burned immediately if the beneficiary is the caller itself, // in this case, the beneficiary's balance is not increased. - if beneficiary != this { + if this != beneficiary { evm.StateDB.AddBalance(beneficiary, balance, tracing.BalanceIncreaseSelfdestruct) } // Clear any leftover funds for the account being destructed. @@ -909,26 +909,24 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro balance = evm.StateDB.GetBalance(this) top = scope.Stack.pop() beneficiary = common.Address(top.Bytes20()) + + newContract = evm.StateDB.IsNewContract(this) ) - if evm.StateDB.IsNewContract(this) { - // Contract is newly created in this transaction, so it will be actually - // deleted from the state. - if this == beneficiary { - // Since the contract will be deleted from state, it isn't necessary to - // also subtract the balance beforehand as it will affect the tracing. - } else { - // Otherwise, we can proceed with transfer. + // Contract is new and will actually be deleted. + if newContract { + if this != beneficiary { // Skip no-op transfer when self-destructing to self. evm.StateDB.AddBalance(beneficiary, balance, tracing.BalanceIncreaseSelfdestruct) } evm.StateDB.SubBalance(this, balance, tracing.BalanceDecreaseSelfdestruct) - } else { - // Contract already exists in the state, therefore it will send it's full - // balance and remain in the state. + evm.StateDB.SelfDestruct(this) + } + + // Contract already exists, only do transfer if beneficiary is not self. + if !newContract && this != beneficiary { evm.StateDB.SubBalance(this, balance, tracing.BalanceDecreaseSelfdestruct) evm.StateDB.AddBalance(beneficiary, balance, tracing.BalanceIncreaseSelfdestruct) } - evm.StateDB.SelfDestruct6780(this) if tracer := evm.Config.Tracer; tracer != nil { if tracer.OnEnter != nil { diff --git a/core/vm/interface.go b/core/vm/interface.go index fbc6529d18..e285b18b0f 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -60,11 +60,6 @@ type StateDB interface { SelfDestruct(common.Address) HasSelfDestructed(common.Address) bool - // SelfDestruct6780 is post-EIP6780 selfdestruct, which means that it's a - // send-all-to-beneficiary, unless the contract was created in this same - // transaction, in which case it will be destructed. - SelfDestruct6780(common.Address) - // Exist reports whether the given account exists in state. // Notably this also returns true for self-destructed accounts within the current transaction. Exist(common.Address) bool