ethereum.gray_glacier.utils.addressethereum.paris.utils.address

Hardfork Utility Functions For Addresses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Introduction

Address specific functions used in this gray_glacier version ofAddress specific functions used in this paris version of specification.

to_address

Convert a Uint or U256 value to a valid address (20 bytes).

Parameters

data : The string to be converted to bytes.

Returns

address : Address The obtained address.

def to_address(data: Union[Uint, U256]) -> Address:
28
    """
29
    Convert a Uint or U256 value to a valid address (20 bytes).
30
31
    Parameters
32
    ----------
33
    data :
34
        The string to be converted to bytes.
35
36
    Returns
37
    -------
38
    address : `Address`
39
        The obtained address.
40
    """
41
    return Address(data.to_be_bytes32()[-20:])

compute_contract_address

Computes address of the new account that needs to be created.

Parameters

address : The address of the account that wants to create the new account. nonce : The transaction count of the account that wants to create the new account.

Returns

address: Address The computed address of the new account.

def compute_contract_address(address: Address, ​​nonce: Uint) -> Address:
45
    """
46
    Computes address of the new account that needs to be created.
47
48
    Parameters
49
    ----------
50
    address :
51
        The address of the account that wants to create the new account.
52
    nonce :
53
        The transaction count of the account that wants to create the new
54
        account.
55
56
    Returns
57
    -------
58
    address: `Address`
59
        The computed address of the new account.
60
    """
61
    computed_address = keccak256(rlp.encode([address, nonce]))
62
    canonical_address = computed_address[-20:]
63
    padded_address = left_pad_zero_bytes(canonical_address, 20)
64
    return Address(padded_address)

compute_create2_contract_address

Computes address of the new account that needs to be created, which is based on the sender address, salt and the call data as well.

Parameters

address : The address of the account that wants to create the new account. salt : Address generation salt. call_data : The code of the new account which is to be created.

Returns

address: ethereum.gray_glacier.fork_types.Addressethereum.paris.fork_types.Address The computed address of the new account.

def compute_create2_contract_address(address: Address, ​​salt: Bytes32, ​​call_data: bytearray) -> Address:
70
    """
71
    Computes address of the new account that needs to be created, which is
72
    based on the sender address, salt and the call data as well.
73
74
    Parameters
75
    ----------
76
    address :
77
        The address of the account that wants to create the new account.
78
    salt :
79
        Address generation salt.
80
    call_data :
81
        The code of the new account which is to be created.
82
83
    Returns
84
    -------
85
    address: `ethereum.gray_glacier.fork_types.Address`
85
    address: `ethereum.paris.fork_types.Address`
86
        The computed address of the new account.
87
    """
88
    preimage = b"\xff" + address + salt + keccak256(call_data)
89
    computed_address = keccak256(preimage)
90
    canonical_address = computed_address[-20:]
91
    padded_address = left_pad_zero_bytes(canonical_address, 20)
92
93
    return Address(padded_address)