ethereum.arrow_glacier.utils.message
Hardfork Utility Functions For The Message Data-structure ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Message specific functions used in this arrow_glacier version of specification.
1""" 2Hardfork Utility Functions For The Message Data-structure 3^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 5.. contents:: Table of Contents 6 :backlinks: none 7 :local: 8 9Introduction 10------------ 11 12Message specific functions used in this arrow_glacier version of 13specification. 14""" 15from typing import FrozenSet, Optional, Tuple, Union 16 17from ethereum.base_types import U256, Bytes, Bytes0, Bytes32, Uint 18 19from ..fork_types import Address 20from ..state import get_account 21from ..vm import Environment, Message 22from ..vm.precompiled_contracts.mapping import PRE_COMPILED_CONTRACTS 23from .address import compute_contract_address 24 25 26def prepare_message( 27 caller: Address, 28 target: Union[Bytes0, Address], 29 value: U256, 30 data: Bytes, 31 gas: Uint, 32 env: Environment, 33 code_address: Optional[Address] = None, 34 should_transfer_value: bool = True, 35 is_static: bool = False, 36 preaccessed_addresses: FrozenSet[Address] = frozenset(), 37 preaccessed_storage_keys: FrozenSet[ 38 Tuple[(Address, Bytes32)] 39 ] = frozenset(), 40) -> Message: 41 """ 42 Execute a transaction against the provided environment. 43 44 Parameters 45 ---------- 46 caller : 47 Address which initiated the transaction 48 target : 49 Address whose code will be executed 50 value : 51 Value to be transferred. 52 data : 53 Array of bytes provided to the code in `target`. 54 gas : 55 Gas provided for the code in `target`. 56 env : 57 Environment for the Ethereum Virtual Machine. 58 code_address : 59 This is usually same as the `target` address except when an alternative 60 accounts code needs to be executed. 61 eg. `CALLCODE` calling a precompile. 62 should_transfer_value : 63 if True ETH should be transferred while executing a message call. 64 is_static: 65 if True then it prevents all state-changing operations from being 66 executed. 67 preaccessed_addresses: 68 Addresses that should be marked as accessed prior to the message call 69 preaccessed_storage_keys: 70 Storage keys that should be marked as accessed prior to the message 71 call 72 73 Returns 74 ------- 75 message: `ethereum.arrow_glacier.vm.Message` 76 Items containing contract creation or message call specific data. 77 """ 78 if isinstance(target, Bytes0): 79 current_target = compute_contract_address( 80 caller, 81 get_account(env.state, caller).nonce - U256(1), 82 ) 83 msg_data = Bytes(b"") 84 code = data 85 elif isinstance(target, Address): 86 current_target = target 87 msg_data = data 88 code = get_account(env.state, target).code 89 if code_address is None: 90 code_address = target 91 else: 92 raise AssertionError("Target must be address or empty bytes") 93 94 accessed_addresses = set() 95 accessed_addresses.add(current_target) 96 accessed_addresses.add(caller) 97 accessed_addresses.update(PRE_COMPILED_CONTRACTS.keys()) 98 accessed_addresses.update(preaccessed_addresses) 99 100 return Message( 101 caller=caller, 102 target=target, 103 gas=gas, 104 value=value, 105 data=msg_data, 106 code=code, 107 depth=Uint(0), 108 current_target=current_target, 109 code_address=code_address, 110 should_transfer_value=should_transfer_value, 111 is_static=is_static, 112 accessed_addresses=accessed_addresses, 113 accessed_storage_keys=set(preaccessed_storage_keys), 114 parent_evm=None, 115 )
27def prepare_message( 28 caller: Address, 29 target: Union[Bytes0, Address], 30 value: U256, 31 data: Bytes, 32 gas: Uint, 33 env: Environment, 34 code_address: Optional[Address] = None, 35 should_transfer_value: bool = True, 36 is_static: bool = False, 37 preaccessed_addresses: FrozenSet[Address] = frozenset(), 38 preaccessed_storage_keys: FrozenSet[ 39 Tuple[(Address, Bytes32)] 40 ] = frozenset(), 41) -> Message: 42 """ 43 Execute a transaction against the provided environment. 44 45 Parameters 46 ---------- 47 caller : 48 Address which initiated the transaction 49 target : 50 Address whose code will be executed 51 value : 52 Value to be transferred. 53 data : 54 Array of bytes provided to the code in `target`. 55 gas : 56 Gas provided for the code in `target`. 57 env : 58 Environment for the Ethereum Virtual Machine. 59 code_address : 60 This is usually same as the `target` address except when an alternative 61 accounts code needs to be executed. 62 eg. `CALLCODE` calling a precompile. 63 should_transfer_value : 64 if True ETH should be transferred while executing a message call. 65 is_static: 66 if True then it prevents all state-changing operations from being 67 executed. 68 preaccessed_addresses: 69 Addresses that should be marked as accessed prior to the message call 70 preaccessed_storage_keys: 71 Storage keys that should be marked as accessed prior to the message 72 call 73 74 Returns 75 ------- 76 message: `ethereum.arrow_glacier.vm.Message` 77 Items containing contract creation or message call specific data. 78 """ 79 if isinstance(target, Bytes0): 80 current_target = compute_contract_address( 81 caller, 82 get_account(env.state, caller).nonce - U256(1), 83 ) 84 msg_data = Bytes(b"") 85 code = data 86 elif isinstance(target, Address): 87 current_target = target 88 msg_data = data 89 code = get_account(env.state, target).code 90 if code_address is None: 91 code_address = target 92 else: 93 raise AssertionError("Target must be address or empty bytes") 94 95 accessed_addresses = set() 96 accessed_addresses.add(current_target) 97 accessed_addresses.add(caller) 98 accessed_addresses.update(PRE_COMPILED_CONTRACTS.keys()) 99 accessed_addresses.update(preaccessed_addresses) 100 101 return Message( 102 caller=caller, 103 target=target, 104 gas=gas, 105 value=value, 106 data=msg_data, 107 code=code, 108 depth=Uint(0), 109 current_target=current_target, 110 code_address=code_address, 111 should_transfer_value=should_transfer_value, 112 is_static=is_static, 113 accessed_addresses=accessed_addresses, 114 accessed_storage_keys=set(preaccessed_storage_keys), 115 parent_evm=None, 116 )
Execute a transaction against the provided environment.
Parameters
caller :
Address which initiated the transaction
target :
Address whose code will be executed
value :
Value to be transferred.
data :
Array of bytes provided to the code in target
.
gas :
Gas provided for the code in target
.
env :
Environment for the Ethereum Virtual Machine.
code_address :
This is usually same as the target
address except when an alternative
accounts code needs to be executed.
eg. CALLCODE
calling a precompile.
should_transfer_value :
if True ETH should be transferred while executing a message call.
is_static:
if True then it prevents all state-changing operations from being
executed.
preaccessed_addresses:
Addresses that should be marked as accessed prior to the message call
preaccessed_storage_keys:
Storage keys that should be marked as accessed prior to the message
call
Returns
message: ethereum.arrow_glacier.vm.Message
Items containing contract creation or message call specific data.