ethereum.forks.gray_glacier.utils.addressethereum.forks.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_masked

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

Parameters

data : The numeric value to be converted to address.

Returns

address : Address The obtained address.

def to_address_masked(data: Uint | U256) -> Address:
25
    <snip>
39
    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:
43
    <snip>
60
    computed_address = keccak256(rlp.encode([address, nonce]))
61
    canonical_address = computed_address[-20:]
62
    padded_address = left_pad_zero_bytes(canonical_address, 20)
63
    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.forks.gray_glacier.fork_types.Addressethereum.forks.paris.fork_types.Address The computed address of the new account.

def compute_create2_contract_address(address: Address, ​​salt: Bytes32, ​​call_data: Bytes) -> Address:
69
    <snip>
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)