From 857c3fa4d733535f32e9f17250d5790dd7ab5a76 Mon Sep 17 00:00:00 2001 From: Peter Miller Date: Mon, 2 Dec 2024 12:38:49 +0000 Subject: [PATCH] Make EXTCODE* operations not follow delegations --- src/ethereum/prague/vm/eoa_delegation.py | 27 +++++++++++++++++++ .../prague/vm/instructions/environment.py | 11 +++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/ethereum/prague/vm/eoa_delegation.py b/src/ethereum/prague/vm/eoa_delegation.py index ce13b891ab..d7aaac8da4 100644 --- a/src/ethereum/prague/vm/eoa_delegation.py +++ b/src/ethereum/prague/vm/eoa_delegation.py @@ -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 @@ -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. diff --git a/src/ethereum/prague/vm/instructions/environment.py b/src/ethereum/prague/vm/instructions/environment.py index 17c21d509f..489ae82924 100644 --- a/src/ethereum/prague/vm/instructions/environment.py +++ b/src/ethereum/prague/vm/instructions/environment.py @@ -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 @@ -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 @@ -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) @@ -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)