Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 5 additions & 12 deletions src/ethereum/cancun/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from .state import (
State,
TransientStorage,
account_exists_and_is_empty,
destroy_account,
get_account,
increment_nonce,
Expand Down Expand Up @@ -784,14 +783,11 @@ def process_transaction(
coinbase_balance_after_mining_fee = get_account(
block_env.state, block_env.coinbase
).balance + U256(transaction_fee)
if coinbase_balance_after_mining_fee != 0:
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)
elif account_exists_and_is_empty(block_env.state, block_env.coinbase):
destroy_account(block_env.state, block_env.coinbase)
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)

for address in tx_output.accounts_to_delete:
destroy_account(block_env.state, address)
Expand Down Expand Up @@ -836,9 +832,6 @@ def increase_recipient_balance(recipient: Account) -> None:

modify_state(block_env.state, wd.address, increase_recipient_balance)

if account_exists_and_is_empty(block_env.state, wd.address):
destroy_account(block_env.state, wd.address)


def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool:
"""
Expand Down
41 changes: 12 additions & 29 deletions src/ethereum/cancun/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,33 +425,6 @@ def account_has_storage(state: State, address: Address) -> bool:
return address in state._storage_tries


def account_exists_and_is_empty(state: State, address: Address) -> bool:
"""
Checks if an account exists and has zero nonce, empty code and zero
balance.

Parameters
----------
state:
The state
address:
Address of the account that needs to be checked.

Returns
-------
exists_and_is_empty : `bool`
True if an account exists and has zero nonce, empty code and zero
balance, False otherwise.
"""
account = get_account_optional(state, address)
return (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)


def is_account_alive(state: State, address: Address) -> bool:
"""
Check whether is an account is both in the state and non empty.
Expand All @@ -476,10 +449,20 @@ def modify_state(
state: State, address: Address, f: Callable[[Account], None]
) -> None:
"""
Modify an `Account` in the `State`.
Modify an `Account` in the `State`. If, after modification, the account
exists and has zero nonce, empty code, and zero balance, it is destroyed.
"""
set_account(state, address, modify(get_account(state, address), f))
if account_exists_and_is_empty(state, address):

account = get_account_optional(state, address)
account_exists_and_is_empty = (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)

if account_exists_and_is_empty:
destroy_account(state, address)


Expand Down
17 changes: 5 additions & 12 deletions src/ethereum/osaka/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from .state import (
State,
TransientStorage,
account_exists_and_is_empty,
destroy_account,
get_account,
increment_nonce,
Expand Down Expand Up @@ -960,14 +959,11 @@ def process_transaction(
coinbase_balance_after_mining_fee = get_account(
block_env.state, block_env.coinbase
).balance + U256(transaction_fee)
if coinbase_balance_after_mining_fee != 0:
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)
elif account_exists_and_is_empty(block_env.state, block_env.coinbase):
destroy_account(block_env.state, block_env.coinbase)
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)

for address in tx_output.accounts_to_delete:
destroy_account(block_env.state, address)
Expand Down Expand Up @@ -1012,9 +1008,6 @@ def increase_recipient_balance(recipient: Account) -> None:

modify_state(block_env.state, wd.address, increase_recipient_balance)

if account_exists_and_is_empty(block_env.state, wd.address):
destroy_account(block_env.state, wd.address)


def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool:
"""
Expand Down
41 changes: 12 additions & 29 deletions src/ethereum/osaka/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,33 +425,6 @@ def account_has_storage(state: State, address: Address) -> bool:
return address in state._storage_tries


def account_exists_and_is_empty(state: State, address: Address) -> bool:
"""
Checks if an account exists and has zero nonce, empty code and zero
balance.

Parameters
----------
state:
The state
address:
Address of the account that needs to be checked.

Returns
-------
exists_and_is_empty : `bool`
True if an account exists and has zero nonce, empty code and zero
balance, False otherwise.
"""
account = get_account_optional(state, address)
return (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)


def is_account_alive(state: State, address: Address) -> bool:
"""
Check whether is an account is both in the state and non empty.
Expand All @@ -476,10 +449,20 @@ def modify_state(
state: State, address: Address, f: Callable[[Account], None]
) -> None:
"""
Modify an `Account` in the `State`.
Modify an `Account` in the `State`. If, after modification, the account
exists and has zero nonce, empty code, and zero balance, it is destroyed.
"""
set_account(state, address, modify(get_account(state, address), f))
if account_exists_and_is_empty(state, address):

account = get_account_optional(state, address)
account_exists_and_is_empty = (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)

if account_exists_and_is_empty:
destroy_account(state, address)


Expand Down
14 changes: 5 additions & 9 deletions src/ethereum/paris/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from .fork_types import Address
from .state import (
State,
account_exists_and_is_empty,
destroy_account,
get_account,
increment_nonce,
Expand Down Expand Up @@ -578,14 +577,11 @@ def process_transaction(
coinbase_balance_after_mining_fee = get_account(
block_env.state, block_env.coinbase
).balance + U256(transaction_fee)
if coinbase_balance_after_mining_fee != 0:
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)
elif account_exists_and_is_empty(block_env.state, block_env.coinbase):
destroy_account(block_env.state, block_env.coinbase)
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)

for address in tx_output.accounts_to_delete:
destroy_account(block_env.state, address)
Expand Down
41 changes: 12 additions & 29 deletions src/ethereum/paris/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,33 +391,6 @@ def account_has_storage(state: State, address: Address) -> bool:
return address in state._storage_tries


def account_exists_and_is_empty(state: State, address: Address) -> bool:
"""
Checks if an account exists and has zero nonce, empty code and zero
balance.

Parameters
----------
state:
The state
address:
Address of the account that needs to be checked.

Returns
-------
exists_and_is_empty : `bool`
True if an account exists and has zero nonce, empty code and zero
balance, False otherwise.
"""
account = get_account_optional(state, address)
return (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)


def is_account_alive(state: State, address: Address) -> bool:
"""
Check whether is an account is both in the state and non empty.
Expand All @@ -442,10 +415,20 @@ def modify_state(
state: State, address: Address, f: Callable[[Account], None]
) -> None:
"""
Modify an `Account` in the `State`.
Modify an `Account` in the `State`. If, after modification, the account
exists and has zero nonce, empty code, and zero balance, it is destroyed.
"""
set_account(state, address, modify(get_account(state, address), f))
if account_exists_and_is_empty(state, address):

account = get_account_optional(state, address)
account_exists_and_is_empty = (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)

if account_exists_and_is_empty:
destroy_account(state, address)


Expand Down
17 changes: 5 additions & 12 deletions src/ethereum/prague/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from .state import (
State,
TransientStorage,
account_exists_and_is_empty,
destroy_account,
get_account,
increment_nonce,
Expand Down Expand Up @@ -945,14 +944,11 @@ def process_transaction(
coinbase_balance_after_mining_fee = get_account(
block_env.state, block_env.coinbase
).balance + U256(transaction_fee)
if coinbase_balance_after_mining_fee != 0:
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)
elif account_exists_and_is_empty(block_env.state, block_env.coinbase):
destroy_account(block_env.state, block_env.coinbase)
set_account_balance(
block_env.state,
block_env.coinbase,
coinbase_balance_after_mining_fee,
)

for address in tx_output.accounts_to_delete:
destroy_account(block_env.state, address)
Expand Down Expand Up @@ -997,9 +993,6 @@ def increase_recipient_balance(recipient: Account) -> None:

modify_state(block_env.state, wd.address, increase_recipient_balance)

if account_exists_and_is_empty(block_env.state, wd.address):
destroy_account(block_env.state, wd.address)


def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool:
"""
Expand Down
41 changes: 12 additions & 29 deletions src/ethereum/prague/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,33 +425,6 @@ def account_has_storage(state: State, address: Address) -> bool:
return address in state._storage_tries


def account_exists_and_is_empty(state: State, address: Address) -> bool:
"""
Checks if an account exists and has zero nonce, empty code and zero
balance.

Parameters
----------
state:
The state
address:
Address of the account that needs to be checked.

Returns
-------
exists_and_is_empty : `bool`
True if an account exists and has zero nonce, empty code and zero
balance, False otherwise.
"""
account = get_account_optional(state, address)
return (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)


def is_account_alive(state: State, address: Address) -> bool:
"""
Check whether is an account is both in the state and non empty.
Expand All @@ -476,10 +449,20 @@ def modify_state(
state: State, address: Address, f: Callable[[Account], None]
) -> None:
"""
Modify an `Account` in the `State`.
Modify an `Account` in the `State`. If, after modification, the account
exists and has zero nonce, empty code, and zero balance, it is destroyed.
"""
set_account(state, address, modify(get_account(state, address), f))
if account_exists_and_is_empty(state, address):

account = get_account_optional(state, address)
account_exists_and_is_empty = (
account is not None
and account.nonce == Uint(0)
and account.code == b""
and account.balance == 0
)

if account_exists_and_is_empty:
destroy_account(state, address)


Expand Down
Loading
Loading