ethereum.forks.prague.requests

Requests were introduced in EIP-7685 as a general purpose framework for storing contract-triggered requests. It extends the execution header and body with a single field each to store the request information. This inherently exposes the requests to the consensus layer, which can then process each one.

DEPOSIT_CONTRACT_ADDRESS

25
DEPOSIT_CONTRACT_ADDRESS = hex_to_address(
26
    "0x00000000219ab540356cbb839cbe05303d7705fa"
27
)

DEPOSIT_EVENT_SIGNATURE_HASH

28
DEPOSIT_EVENT_SIGNATURE_HASH = hex_to_bytes32(
29
    "0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"
30
)

DEPOSIT_REQUEST_TYPE

31
DEPOSIT_REQUEST_TYPE = b"\x00"

WITHDRAWAL_REQUEST_TYPE

32
WITHDRAWAL_REQUEST_TYPE = b"\x01"

CONSOLIDATION_REQUEST_TYPE

33
CONSOLIDATION_REQUEST_TYPE = b"\x02"

DEPOSIT_EVENT_LENGTH

36
DEPOSIT_EVENT_LENGTH = Uint(576)

PUBKEY_OFFSET

38
PUBKEY_OFFSET = Uint(160)

WITHDRAWAL_CREDENTIALS_OFFSET

39
WITHDRAWAL_CREDENTIALS_OFFSET = Uint(256)

AMOUNT_OFFSET

40
AMOUNT_OFFSET = Uint(320)

SIGNATURE_OFFSET

41
SIGNATURE_OFFSET = Uint(384)

INDEX_OFFSET

42
INDEX_OFFSET = Uint(512)

PUBKEY_SIZE

44
PUBKEY_SIZE = Uint(48)

WITHDRAWAL_CREDENTIALS_SIZE

45
WITHDRAWAL_CREDENTIALS_SIZE = Uint(32)

AMOUNT_SIZE

46
AMOUNT_SIZE = Uint(8)

SIGNATURE_SIZE

47
SIGNATURE_SIZE = Uint(96)

INDEX_SIZE

48
INDEX_SIZE = Uint(8)

extract_deposit_data

Extracts Deposit Request from the DepositContract.DepositEvent data.

Raises

InvalidBlock : If the deposit contract did not produce a valid log.

def extract_deposit_data(data: Bytes) -> Bytes:
52
    """
53
    Extracts Deposit Request from the DepositContract.DepositEvent data.
54
55
    Raises
56
    ------
57
    InvalidBlock :
58
        If the deposit contract did not produce a valid log.
59
60
    """
61
    if ulen(data) != DEPOSIT_EVENT_LENGTH:
62
        raise InvalidBlock("Invalid deposit event data length")
63
64
    # Check that all the offsets are in order
65
    pubkey_offset = Uint.from_be_bytes(data[0:32])
66
    if pubkey_offset != PUBKEY_OFFSET:
67
        raise InvalidBlock("Invalid pubkey offset in deposit log")
68
69
    withdrawal_credentials_offset = Uint.from_be_bytes(data[32:64])
70
    if withdrawal_credentials_offset != WITHDRAWAL_CREDENTIALS_OFFSET:
71
        raise InvalidBlock(
72
            "Invalid withdrawal credentials offset in deposit log"
73
        )
74
75
    amount_offset = Uint.from_be_bytes(data[64:96])
76
    if amount_offset != AMOUNT_OFFSET:
77
        raise InvalidBlock("Invalid amount offset in deposit log")
78
79
    signature_offset = Uint.from_be_bytes(data[96:128])
80
    if signature_offset != SIGNATURE_OFFSET:
81
        raise InvalidBlock("Invalid signature offset in deposit log")
82
83
    index_offset = Uint.from_be_bytes(data[128:160])
84
    if index_offset != INDEX_OFFSET:
85
        raise InvalidBlock("Invalid index offset in deposit log")
86
87
    # Check that all the sizes are in order
88
    pubkey_size = Uint.from_be_bytes(
89
        data[pubkey_offset : pubkey_offset + Uint(32)]
90
    )
91
    if pubkey_size != PUBKEY_SIZE:
92
        raise InvalidBlock("Invalid pubkey size in deposit log")
93
94
    pubkey = data[
95
        pubkey_offset + Uint(32) : pubkey_offset + Uint(32) + PUBKEY_SIZE
96
    ]
97
98
    withdrawal_credentials_size = Uint.from_be_bytes(
99
        data[
100
            withdrawal_credentials_offset : withdrawal_credentials_offset
101
            + Uint(32)
102
        ],
103
    )
104
    if withdrawal_credentials_size != WITHDRAWAL_CREDENTIALS_SIZE:
105
        raise InvalidBlock(
106
            "Invalid withdrawal credentials size in deposit log"
107
        )
108
109
    withdrawal_credentials = data[
110
        withdrawal_credentials_offset
111
        + Uint(32) : withdrawal_credentials_offset
112
        + Uint(32)
113
        + WITHDRAWAL_CREDENTIALS_SIZE
114
    ]
115
116
    amount_size = Uint.from_be_bytes(
117
        data[amount_offset : amount_offset + Uint(32)]
118
    )
119
    if amount_size != AMOUNT_SIZE:
120
        raise InvalidBlock("Invalid amount size in deposit log")
121
122
    amount = data[
123
        amount_offset + Uint(32) : amount_offset + Uint(32) + AMOUNT_SIZE
124
    ]
125
126
    signature_size = Uint.from_be_bytes(
127
        data[signature_offset : signature_offset + Uint(32)]
128
    )
129
    if signature_size != SIGNATURE_SIZE:
130
        raise InvalidBlock("Invalid signature size in deposit log")
131
132
    signature = data[
133
        signature_offset + Uint(32) : signature_offset
134
        + Uint(32)
135
        + SIGNATURE_SIZE
136
    ]
137
138
    index_size = Uint.from_be_bytes(
139
        data[index_offset : index_offset + Uint(32)]
140
    )
141
    if index_size != INDEX_SIZE:
142
        raise InvalidBlock("Invalid index size in deposit log")
143
144
    index = data[
145
        index_offset + Uint(32) : index_offset + Uint(32) + INDEX_SIZE
146
    ]
147
148
    return pubkey + withdrawal_credentials + amount + signature + index

parse_deposit_requests

Parse deposit requests from the block output.

def parse_deposit_requests(block_output: BlockOutput) -> Bytes:
152
    """
153
    Parse deposit requests from the block output.
154
    """
155
    deposit_requests: Bytes = b""
156
    for key in block_output.receipt_keys:
157
        receipt = trie_get(block_output.receipts_trie, key)
158
        assert receipt is not None
159
        decoded_receipt = decode_receipt(receipt)
160
        for log in decoded_receipt.logs:
161
            if log.address == DEPOSIT_CONTRACT_ADDRESS:
162
                if (
163
                    len(log.topics) > 0
164
                    and log.topics[0] == DEPOSIT_EVENT_SIGNATURE_HASH
165
                ):
166
                    request = extract_deposit_data(log.data)
167
                    deposit_requests += request
168
169
    return deposit_requests

compute_requests_hash

Get the hash of the requests using the SHA2-256 algorithm.

Parameters

requests : Bytes The requests to hash.

Returns

requests_hash : Bytes The hash of the requests.

def compute_requests_hash(requests: List[Bytes]) -> Bytes:
173
    """
174
    Get the hash of the requests using the SHA2-256 algorithm.
175
176
    Parameters
177
    ----------
178
    requests : Bytes
179
        The requests to hash.
180
181
    Returns
182
    -------
183
    requests_hash : Bytes
184
        The hash of the requests.
185
186
    """
187
    m = sha256()
188
    for request in requests:
189
        m.update(sha256(request).digest())
190
191
    return m.digest()