Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: replace instances of 'suicide' with 'selfdestruct' to improve code consistency. #27716

Merged
merged 7 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion accounts/abi/bind/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
var (
// ErrNoCode is returned by call and transact operations for which the requested
// recipient contract to operate on does not exist in the state db or does not
// have any code associated with it (i.e. suicided).
// have any code associated with it (i.e. self-destructed).
ErrNoCode = errors.New("no contract code at given address")

// ErrNoPendingState is raised when attempting to perform a pending state action
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
if miningReward >= 0 {
// Add mining reward. The mining reward may be `0`, which only makes a difference in the cases
// where
// - the coinbase suicided, or
// - the coinbase selfdestructed, or
jwasinger marked this conversation as resolved.
Show resolved Hide resolved
// - there are only 'bad' transactions, which aren't executed. In those cases,
// the coinbase gets no txfee, so isn't created, and thus needs to be touched
var (
Expand Down
10 changes: 5 additions & 5 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ type (
prevAccountOrigin []byte
prevStorageOrigin map[common.Hash][]byte
}
suicideChange struct {
selfDestructChange struct {
account *common.Address
prev bool // whether account had already suicided
prev bool // whether account had already self-destructed
prevbalance *big.Int
}

Expand Down Expand Up @@ -184,15 +184,15 @@ func (ch resetObjectChange) dirtied() *common.Address {
return ch.account
}

func (ch suicideChange) revert(s *StateDB) {
func (ch selfDestructChange) revert(s *StateDB) {
obj := s.getStateObject(*ch.account)
if obj != nil {
obj.suicided = ch.prev
obj.selfDestructed = ch.prev
obj.setBalance(ch.prevbalance)
}
}

func (ch suicideChange) dirtied() *common.Address {
func (ch selfDestructChange) dirtied() *common.Address {
return ch.account
}

Expand Down
14 changes: 7 additions & 7 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ type stateObject struct {
// Cache flags.
dirtyCode bool // true if the code was updated

// Flag whether the account was marked as suicided. The suicided account
// Flag whether the account was marked as self-destructed. The self-destructed account
// is still accessible in the scope of same transaction.
suicided bool
selfDestructed bool

// Flag whether the account was marked as deleted. The suicided account
// or the account is considered as empty will be marked as deleted at
// Flag whether the account was marked as deleted. A self-destructed account
// or an account that is considered as empty will be marked as deleted at
// the end of transaction and no longer accessible anymore.
deleted bool
}
Expand Down Expand Up @@ -116,8 +116,8 @@ func (s *stateObject) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &s.data)
}

func (s *stateObject) markSuicided() {
s.suicided = true
func (s *stateObject) markSelfdestructed() {
s.selfDestructed = true
}

func (s *stateObject) touch() {
Expand Down Expand Up @@ -446,7 +446,7 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject {
obj.dirtyStorage = s.dirtyStorage.Copy()
obj.originStorage = s.originStorage.Copy()
obj.pendingStorage = s.pendingStorage.Copy()
obj.suicided = s.suicided
obj.selfDestructed = s.selfDestructed
obj.dirtyCode = s.dirtyCode
obj.deleted = s.deleted
return obj
Expand Down
4 changes: 2 additions & 2 deletions core/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestSnapshot2(t *testing.T) {
so0.SetBalance(big.NewInt(42))
so0.SetNonce(43)
so0.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e'}), []byte{'c', 'a', 'f', 'e'})
so0.suicided = false
so0.selfDestructed = false
so0.deleted = false
state.setStateObject(so0)

Expand All @@ -220,7 +220,7 @@ func TestSnapshot2(t *testing.T) {
so1.SetBalance(big.NewInt(52))
so1.SetNonce(53)
so1.SetCode(crypto.Keccak256Hash([]byte{'c', 'a', 'f', 'e', '2'}), []byte{'c', 'a', 'f', 'e', '2'})
so1.suicided = true
so1.selfDestructed = true
so1.deleted = true
state.setStateObject(so1)

Expand Down
23 changes: 11 additions & 12 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (s *StateDB) SubRefund(gas uint64) {
}

// Exist reports whether the given account address exists in the state.
// Notably this also returns true for suicided accounts.
// Notably this also returns true for self-destructed accounts.
func (s *StateDB) Exist(addr common.Address) bool {
return s.getStateObject(addr) != nil
}
Expand Down Expand Up @@ -397,10 +397,10 @@ func (s *StateDB) StorageTrie(addr common.Address) (Trie, error) {
return cpy.getTrie(s.db)
}

func (s *StateDB) HasSuicided(addr common.Address) bool {
func (s *StateDB) HasSelfDestructed(addr common.Address) bool {
stateObject := s.getStateObject(addr)
if stateObject != nil {
return stateObject.suicided
return stateObject.selfDestructed
}
return false
}
Expand Down Expand Up @@ -474,24 +474,23 @@ func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common
}
}

// Suicide marks the given account as suicided.
// SelfDestruct marks the given account as selfdestructed.
// This clears the account balance.
//
// The account's state object is still available until the state is committed,
// getStateObject will return a non-nil account after Suicide.
func (s *StateDB) Suicide(addr common.Address) bool {
// getStateObject will return a non-nil account after SelfDestruct.
func (s *StateDB) SelfDestruct(addr common.Address) {
stateObject := s.getStateObject(addr)
if stateObject == nil {
return false
return
}
s.journal.append(suicideChange{
s.journal.append(selfDestructChange{
jwasinger marked this conversation as resolved.
Show resolved Hide resolved
account: &addr,
prev: stateObject.suicided,
prev: stateObject.selfDestructed,
prevbalance: new(big.Int).Set(stateObject.Balance()),
})
stateObject.markSuicided()
stateObject.markSelfdestructed()
stateObject.data.Balance = new(big.Int)
return true
}

// SetTransientState sets transient storage for a given account. It
Expand Down Expand Up @@ -892,7 +891,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
// Thus, we can safely ignore it here
continue
}
if obj.suicided || (deleteEmptyObjects && obj.empty()) {
if obj.selfDestructed || (deleteEmptyObjects && obj.empty()) {
obj.deleted = true

// We need to maintain account deletions explicitly (will remain
Expand Down
4 changes: 2 additions & 2 deletions core/state/statedb_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func newStateTestAction(addr common.Address, r *rand.Rand, index int) testAction
},
},
{
name: "Suicide",
name: "Selfdestruct",
fn: func(a testAction, s *StateDB) {
s.Suicide(addr)
s.SelfDestruct(addr)
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
},
},
{
name: "Suicide",
name: "SelfDestruct",
fn: func(a testAction, s *StateDB) {
s.Suicide(addr)
s.SelfDestruct(addr)
},
},
{
Expand Down Expand Up @@ -453,7 +453,7 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
}
// Check basic accessor methods.
checkeq("Exist", state.Exist(addr), checkstate.Exist(addr))
checkeq("HasSuicided", state.HasSuicided(addr), checkstate.HasSuicided(addr))
checkeq("HasSelfdestructed", state.HasSelfDestructed(addr), checkstate.HasSelfDestructed(addr))
checkeq("GetBalance", state.GetBalance(addr), checkstate.GetBalance(addr))
checkeq("GetNonce", state.GetNonce(addr), checkstate.GetNonce(addr))
checkeq("GetCode", state.GetCode(addr), checkstate.GetCode(addr))
Expand Down Expand Up @@ -727,7 +727,7 @@ func TestDeleteCreateRevert(t *testing.T) {
state, _ = New(root, state.db, state.snaps)

// Simulate self-destructing in one transaction, then create-reverting in another
state.Suicide(addr)
state.SelfDestruct(addr)
state.Finalise(true)

id := state.Snapshot()
Expand Down
2 changes: 1 addition & 1 deletion core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func gasSelfdestruct(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
}
}

if !evm.StateDB.HasSuicided(contract.Address()) {
if !evm.StateDB.HasSelfDestructed(contract.Address()) {
evm.StateDB.AddRefund(params.SelfdestructRefundGas)
}
return gas, nil
Expand Down
4 changes: 2 additions & 2 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
// emptyCodeHash. If the precompile account is not transferred any amount on a private or
// customized chain, the return value will be zero.
//
// 5. Caller tries to get the code hash for an account which is marked as suicided
// 5. Caller tries to get the code hash for an account which is marked as self-destructed
// in the current transaction, the code hash of this account should be returned.
//
// 6. Caller tries to get the code hash for an account which is marked as deleted, this
Expand Down Expand Up @@ -821,7 +821,7 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
beneficiary := scope.Stack.pop()
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
interpreter.evm.StateDB.Suicide(scope.Contract.Address())
interpreter.evm.StateDB.SelfDestruct(scope.Contract.Address())
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
tracer.CaptureExit([]byte{}, 0, nil)
Expand Down
6 changes: 3 additions & 3 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ type StateDB interface {
GetTransientState(addr common.Address, key common.Hash) common.Hash
SetTransientState(addr common.Address, key, value common.Hash)

Suicide(common.Address) bool
lightclient marked this conversation as resolved.
Show resolved Hide resolved
HasSuicided(common.Address) bool
SelfDestruct(common.Address)
HasSelfDestructed(common.Address) bool

// Exist reports whether the given account exists in state.
// Notably this should also return true for suicided accounts.
// Notably this should also return true for self-destructed accounts.
Exist(common.Address) bool
// Empty returns whether the given account is empty. Empty
// is defined according to EIP161 (balance = nonce = code = 0).
Expand Down
2 changes: 1 addition & 1 deletion core/vm/operations_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc {
if evm.StateDB.Empty(address) && evm.StateDB.GetBalance(contract.Address()).Sign() != 0 {
gas += params.CreateBySelfdestructGas
}
if refundsEnabled && !evm.StateDB.HasSuicided(contract.Address()) {
if refundsEnabled && !evm.StateDB.HasSelfDestructed(contract.Address()) {
evm.StateDB.AddRefund(params.SelfdestructRefundGas)
}
return gas, nil
Expand Down
6 changes: 3 additions & 3 deletions eth/tracers/native/call_flat.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func flatFromNested(input *callFrame, traceAddress []int, convertErrs bool, ctx
case vm.CREATE, vm.CREATE2:
frame = newFlatCreate(input)
case vm.SELFDESTRUCT:
frame = newFlatSuicide(input)
frame = newFlatSelfdestruct(input)
case vm.CALL, vm.STATICCALL, vm.CALLCODE, vm.DELEGATECALL:
frame = newFlatCall(input)
default:
Expand Down Expand Up @@ -330,9 +330,9 @@ func newFlatCall(input *callFrame) *flatCallFrame {
}
}

func newFlatSuicide(input *callFrame) *flatCallFrame {
func newFlatSelfdestruct(input *callFrame) *flatCallFrame {
return &flatCallFrame{
Type: "suicide",
jwasinger marked this conversation as resolved.
Show resolved Hide resolved
Type: "selfdestruct",
Action: flatCallAction{
SelfDestructed: &input.From,
Balance: input.Value,
Expand Down
4 changes: 2 additions & 2 deletions tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bo
}
post := t.json.Post[subtest.Fork][subtest.Index]
// N.B: We need to do this in a two-step process, because the first Commit takes care
// of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
// of self-destructs, and we need to touch the coinbase _after_ it has potentially self-destructed.
if root != common.Hash(post.Root) {
return snaps, statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
}
// Add 0-value mining reward. This only makes a difference in the cases
// where
// - the coinbase suicided, or
// - the coinbase self-destructed, or
// - there are only 'bad' transactions, which aren't executed. In those cases,
// the coinbase gets no txfee, so isn't created, and thus needs to be touched
statedb.AddBalance(block.Coinbase(), new(big.Int))
Expand Down