Skip to content

Commit

Permalink
Make EXTCODE* operations not follow delegations
Browse files Browse the repository at this point in the history
  • Loading branch information
petertdavies authored and spencer-tb committed Dec 4, 2024
1 parent 05f7390 commit 857c3fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
27 changes: 27 additions & 0 deletions src/ethereum/prague/vm/eoa_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ethereum.crypto.hash import keccak256
from ethereum.exceptions import InvalidBlock

from ...utils.hexadecimal import hex_to_bytes
from ..fork_types import Address, Authorization
from ..state import account_exists, get_account, increment_nonce, set_code
from ..utils.hexadecimal import hex_to_address
Expand Down Expand Up @@ -144,6 +145,32 @@ def access_delegation(
return True, address, code, access_gas_cost


def access_delegation_read(
evm: Evm,
address: Address,
) -> Bytes:
"""
Get the code from an address, as read by the EXTCODE* opcodes
Parameters
----------
evm : `Evm`
The execution frame.
address : `Address`
The address to get the delegation from.
Returns
-------
code : Bytes
"""
code = get_account(evm.env.state, address).code

if is_valid_delegation(code):
return hex_to_bytes("0xef01")
else:
return code


def set_delegation(message: Message, env: Environment) -> U256:
"""
Set the delegation code for the authorities in the message.
Expand Down
11 changes: 4 additions & 7 deletions src/ethereum/prague/vm/instructions/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ...fork_types import EMPTY_ACCOUNT
from ...state import get_account
from ...utils.address import to_address
from ...vm.eoa_delegation import access_delegation
from ...vm.eoa_delegation import access_delegation_read
from ...vm.memory import buffer_read, memory_write
from .. import Evm
from ..exceptions import OutOfBoundsRead
Expand Down Expand Up @@ -347,8 +347,7 @@ def extcodesize(evm: Evm) -> None:
evm.accessed_addresses.add(address)
access_gas_cost = GAS_COLD_ACCOUNT_ACCESS

_, address, code, designation_access_cost = access_delegation(evm, address)
access_gas_cost += designation_access_cost
code = access_delegation_read(evm, address)
charge_gas(evm, access_gas_cost)

# OPERATION
Expand Down Expand Up @@ -388,8 +387,7 @@ def extcodecopy(evm: Evm) -> None:
evm.accessed_addresses.add(address)
access_gas_cost = GAS_COLD_ACCOUNT_ACCESS

_, address, code, designation_access_cost = access_delegation(evm, address)
access_gas_cost += designation_access_cost
code = access_delegation_read(evm, address)

charge_gas(evm, access_gas_cost + copy_gas_cost + extend_memory.cost)

Expand Down Expand Up @@ -476,8 +474,7 @@ def extcodehash(evm: Evm) -> None:
evm.accessed_addresses.add(address)
access_gas_cost = GAS_COLD_ACCOUNT_ACCESS

_, address, code, designation_access_cost = access_delegation(evm, address)
access_gas_cost += designation_access_cost
code = access_delegation_read(evm, address)

charge_gas(evm, access_gas_cost)

Expand Down

0 comments on commit 857c3fa

Please sign in to comment.