Skip to content

Commit

Permalink
EIP-6780 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gurukamath committed Jan 27, 2024
1 parent bba5f8c commit d84a075
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/ethereum/cancun/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ def apply_body(
prev_randao=prev_randao,
state=state,
chain_id=chain_id,
created_contracts=set(),
traces=[],
)

Expand Down
1 change: 0 additions & 1 deletion src/ethereum/cancun/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Environment:
prev_randao: Bytes32
state: State
chain_id: U64
created_contracts: Set[Address]
traces: List[dict]


Expand Down
39 changes: 21 additions & 18 deletions src/ethereum/cancun/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def generic_create(
)

evm.accessed_addresses.add(contract_address)
evm.env.created_contracts.add(contract_address)

create_message_gas = max_message_call_gas(Uint(evm.gas_left))
evm.gas_left -= create_message_gas
Expand Down Expand Up @@ -514,27 +513,31 @@ def selfdestruct(evm: Evm) -> None:
beneficiary_balance = get_account(evm.env.state, beneficiary).balance
originator_balance = get_account(evm.env.state, originator).balance

# 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))

# Only continue if the contract has been created in the same tx
if originator in evm.env.created_contracts:
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))

# register account for deletion
# register account for deletion
if originator in evm.env.state._created_accounts:
evm.accounts_to_delete.add(originator)

# mark beneficiary as touched
if account_exists_and_is_empty(evm.env.state, beneficiary):
evm.touched_accounts.add(beneficiary)
# mark beneficiary as touched
if account_exists_and_is_empty(evm.env.state, beneficiary):
evm.touched_accounts.add(beneficiary)

# HALT the execution
evm.running = False
# HALT the execution
evm.running = False

# PROGRAM COUNTER
pass
Expand Down

0 comments on commit d84a075

Please sign in to comment.