ethereum.shanghai.utils.messageethereum.cancun.utils.message

Hardfork Utility Functions For The Message Data-structure ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Message specific functions used in this shanghai version ofMessage specific functions used in this cancun version of specification.

prepare_message

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.shanghai.vm.Messageethereum.cancun.vm.Message Items containing contract creation or message call specific data.

def prepare_message(caller: Address, ​​target: Union[Bytes0, Address], ​​value: U256, ​​data: Bytes, ​​gas: Uint, ​​env: Environment, ​​code_address: Optional[Address], ​​should_transfer_value: bool, ​​is_static: bool, ​​preaccessed_addresses: FrozenSet[Address], ​​preaccessed_storage_keys: FrozenSet[Tuple[(Address, Bytes32)]]) -> 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.shanghai.vm.Message`
76
    message: `ethereum.cancun.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 - Uint(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
    )