Skip to content

Commit

Permalink
post-review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gurukamath authored and SamWilsn committed Feb 15, 2024
1 parent a456b0d commit f35dd3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/ethereum/cancun/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class State:
Trie[Address, Optional[Account]], Dict[Address, Trie[Bytes, U256]]
]
] = field(default_factory=list)
_created_accounts: Set[Address] = field(default_factory=set)
created_accounts: Set[Address] = field(default_factory=set)


@dataclass
Expand All @@ -67,7 +67,7 @@ def close_state(state: State) -> None:
del state._main_trie
del state._storage_tries
del state._snapshots
del state._created_accounts
del state.created_accounts


def begin_transaction(
Expand Down Expand Up @@ -109,7 +109,7 @@ def commit_transaction(state: State) -> None:
"""
state._snapshots.pop()
if not state._snapshots:
state._created_accounts.clear()
state.created_accounts.clear()


def rollback_transaction(
Expand All @@ -128,7 +128,7 @@ def rollback_transaction(
"""
state._main_trie, state._storage_tries = state._snapshots.pop()
if not state._snapshots:
state._created_accounts.clear()
state.created_accounts.clear()

if transient_storage and transient_storage._snapshots:
transient_storage._tries = transient_storage._snapshots.pop()
Expand Down Expand Up @@ -252,7 +252,7 @@ def mark_account_created(state: State, address: Address) -> None:
address : `Address`
Address of the account that has been created.
"""
state._created_accounts.add(address)
state.created_accounts.add(address)


def get_storage(state: State, address: Address, key: Bytes) -> U256:
Expand Down Expand Up @@ -617,7 +617,7 @@ def get_storage_original(state: State, address: Address, key: Bytes) -> U256:
"""
# In the transaction where an account is created, its preexisting storage
# is ignored.
if address in state._created_accounts:
if address in state.created_accounts:
return U256(0)

_, original_trie = state._snapshots[0]
Expand Down
30 changes: 13 additions & 17 deletions src/ethereum/cancun/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
get_account,
increment_nonce,
is_account_alive,
move_ether,
set_account_balance,
)
from ...utils.address import (
Expand Down Expand Up @@ -512,26 +513,21 @@ def selfdestruct(evm: Evm) -> None:
ensure(not evm.message.is_static, WriteInStaticContext)

originator = evm.message.current_target
beneficiary_balance = get_account(evm.env.state, beneficiary).balance
originator_balance = get_account(evm.env.state, originator).balance

if (
originator in evm.env.state._created_accounts
or originator != beneficiary
):
# First Transfer to beneficiary
set_account_balance(
evm.env.state,
beneficiary,
beneficiary_balance + originator_balance,
)
# Next, Zero the balance of the address being deleted (must come after
# sending to beneficiary in case the contract named itself as the
# beneficiary).
set_account_balance(evm.env.state, originator, U256(0))
move_ether(
evm.env.state,
originator,
beneficiary,
originator_balance,
)

# register account for deletion
if originator in evm.env.state._created_accounts:
# register account for deletion only if it was created
# in the same transaction
if originator in evm.env.state.created_accounts:
# If beneficiary is the same as originator, then
# the ether is burnt.
set_account_balance(evm.env.state, originator, U256(0))
evm.accounts_to_delete.add(originator)

# mark beneficiary as touched
Expand Down

0 comments on commit f35dd3d

Please sign in to comment.