Skip to content

Commit

Permalink
fix(types,tests): EIP-7685 fixes for devnet-5 (#990)
Browse files Browse the repository at this point in the history
* fix(forks): Update EIP-7002, EIP-7251 contracts

* fix(types): Remove empty requests from list

* fix(tests): Remove empty requests from lists in all tests

* chore: tox black fix.

---------

Co-authored-by: spencer-tb <[email protected]>
  • Loading branch information
marioevz and spencer-tb authored Dec 4, 2024
1 parent 88c1401 commit 5a40172
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 77 deletions.
6 changes: 0 additions & 6 deletions src/ethereum_test_fixtures/tests/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@
source_pubkey=BLSPublicKey(1),
target_pubkey=BLSPublicKey(2),
),
max_request_type=2,
).requests_list,
validation_error=[
BlockException.INCORRECT_BLOCK_FORMAT,
Expand Down Expand Up @@ -786,7 +785,6 @@
source_pubkey=BLSPublicKey(1),
target_pubkey=BLSPublicKey(2),
),
max_request_type=2,
).requests_list
],
],
Expand Down Expand Up @@ -861,7 +859,6 @@
source_pubkey=BLSPublicKey(1),
target_pubkey=BLSPublicKey(2),
),
max_request_type=2,
).requests_list,
validation_error=[
BlockException.INCORRECT_BLOCK_FORMAT,
Expand Down Expand Up @@ -942,7 +939,6 @@
source_pubkey=BLSPublicKey(1),
target_pubkey=BLSPublicKey(2),
),
max_request_type=2,
).requests_list
],
],
Expand Down Expand Up @@ -1230,7 +1226,6 @@ def test_json_deserialization(
source_pubkey=BLSPublicKey(1),
target_pubkey=BLSPublicKey(2),
),
max_request_type=2,
).requests_list,
),
[
Expand Down Expand Up @@ -1295,7 +1290,6 @@ def test_json_deserialization(
source_pubkey=BLSPublicKey(1),
target_pubkey=BLSPublicKey(2),
),
max_request_type=2,
).requests_list
],
],
Expand Down
Binary file not shown.
Binary file modified src/ethereum_test_forks/forks/contracts/withdrawal_request.bin
Binary file not shown.
4 changes: 1 addition & 3 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,7 @@ def make_genesis(
Withdrawal.list_root(env.withdrawals) if env.withdrawals is not None else None
),
parent_beacon_block_root=env.parent_beacon_block_root,
requests_hash=Requests(max_request_type=fork.max_request_type(0, 0))
if fork.header_requests_required(0, 0)
else None,
requests_hash=Requests() if fork.header_requests_required(0, 0) else None,
fork=fork,
)

Expand Down
16 changes: 8 additions & 8 deletions src/ethereum_test_types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from abc import abstractmethod
from collections import defaultdict
from dataclasses import dataclass
from functools import cached_property
from typing import Any, ClassVar, Dict, Generic, List, Literal, Sequence, SupportsBytes, Tuple
Expand Down Expand Up @@ -1204,7 +1205,6 @@ class Requests:
def __init__(
self,
*requests: RequestBase,
max_request_type: int | None = None,
requests_lists: List[List[RequestBase] | Bytes] | None = None,
):
"""
Expand All @@ -1217,21 +1217,21 @@ def __init__(
self.requests_list.append(requests_list_to_bytes(requests_list))
return
else:

assert max_request_type is not None, "max_request_type must be provided"

lists: List[List[RequestBase]] = [[] for _ in range(max_request_type + 1)]
lists: Dict[int, List[RequestBase]] = defaultdict(list)
for r in requests:
lists[r.type].append(r)

self.requests_list = [requests_list_to_bytes(requests_list) for requests_list in lists]
self.requests_list = [
Bytes(bytes([request_type]) + requests_list_to_bytes(lists[request_type]))
for request_type in sorted(lists.keys())
]

def __bytes__(self) -> bytes:
"""
Returns the requests hash.
"""
s: bytes = b""
for i, r in enumerate(self.requests_list):
for r in self.requests_list:
# Append the index of the request type to the request data before hashing
s = s + Bytes(bytes([i]) + r).sha256()
s = s + r.sha256()
return Bytes(s).sha256()
7 changes: 1 addition & 6 deletions src/pytest_plugins/execute/rpc/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,7 @@ def base_pre_genesis(
if env.withdrawals is not None
else None,
parent_beacon_block_root=env.parent_beacon_block_root,
requests_hash=Requests(
max_request_type=base_fork.max_request_type(
block_number=block_number,
timestamp=timestamp,
),
)
requests_hash=Requests()
if base_fork.header_requests_required(block_number=block_number, timestamp=timestamp)
else None,
)
Expand Down
2 changes: 0 additions & 2 deletions tests/prague/eip6110_deposits/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ def blocks(
header_verify=Header(
requests_hash=Requests(
*included_requests,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
),
),
requests=Requests(
*block_body_override_requests,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
).requests_list
if block_body_override_requests is not None
else None,
Expand Down
17 changes: 4 additions & 13 deletions tests/prague/eip7002_el_triggerable_withdrawals/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ def blocks(
included_requests,
fillvalue=[],
):
max_request_type = fork.max_request_type(
header_verify: Header | None = None
if fork.header_requests_required(
block_number=len(blocks) + 1,
timestamp=timestamp,
)
header_verify: Header | None = None
if max_request_type > -1:
):
header_verify = Header(
requests_hash=Requests(
*block_included_requests,
max_request_type=max_request_type,
)
)
else:
Expand All @@ -120,14 +118,7 @@ def blocks(

return blocks + [
Block(
header_verify=Header(
requests_hash=Requests(
max_request_type=fork.max_request_type(
block_number=len(blocks) + 1,
timestamp=timestamp,
)
)
),
header_verify=Header(requests_hash=Requests()),
timestamp=timestamp,
)
] # Add an empty block at the end to verify that no more withdrawal requests are included
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,11 @@ def test_withdrawal_requests_negative(
header_verify=Header(
requests_hash=Requests(
*included_requests,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
),
),
requests=(
Requests(
*block_body_override_requests,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
).requests_list
if block_body_override_requests is not None
else None
Expand Down
23 changes: 5 additions & 18 deletions tests/prague/eip7251_consolidations/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,12 @@ def blocks(
included_requests,
fillvalue=[],
):
max_request_type = fork.max_request_type(
header_verify: Header | None = None
if fork.header_requests_required(
block_number=len(blocks) + 1,
timestamp=timestamp,
)
header_verify: Header | None = None
if max_request_type > -1:
header_verify = Header(
requests_hash=Requests(
*block_included_requests,
max_request_type=max_request_type,
)
)
):
header_verify = Header(requests_hash=Requests(*block_included_requests))
else:
assert not block_included_requests
blocks.append(
Expand All @@ -121,14 +115,7 @@ def blocks(

return blocks + [
Block(
header_verify=Header(
requests_hash=Requests(
max_request_type=fork.max_request_type(
block_number=len(blocks) + 1,
timestamp=timestamp,
)
)
),
header_verify=Header(requests_hash=Requests()),
timestamp=timestamp,
)
] # Add an empty block at the end to verify that no more consolidation requests are included
10 changes: 2 additions & 8 deletions tests/prague/eip7251_consolidations/test_consolidations.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,10 @@ def test_consolidation_requests_negative(
Block(
txs=sum((r.transactions() for r in requests), []),
header_verify=Header(
requests_hash=Requests(
*included_requests,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
),
requests_hash=Requests(*included_requests),
),
requests=(
Requests(
*block_body_override_requests,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
).requests_list
Requests(*block_body_override_requests).requests_list
if block_body_override_requests is not None
else None
),
Expand Down
9 changes: 2 additions & 7 deletions tests/prague/eip7685_general_purpose_el_requests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def blocks(
elif isinstance(r, ConsolidationRequestInteractionBase):
valid_requests_list += r.valid_requests(consolidation_request_fee)

valid_requests = Requests(
*valid_requests_list,
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
)
valid_requests = Requests(*valid_requests_list)

if block_body_override_requests is None and block_body_extra_requests is not None:
block_body_override_requests = valid_requests.requests_list + block_body_extra_requests
Expand All @@ -96,9 +93,7 @@ def blocks(
return [
Block(
txs=sum((r.transactions() for r in requests), []),
header_verify=Header(
requests_hash=valid_requests,
),
header_verify=Header(requests_hash=valid_requests),
requests=block_body_override_requests,
exception=exception,
rlp_modifier=rlp_modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ def test_valid_deposit_withdrawal_consolidation_request_from_same_tx(
request.with_source_address(contract_address)
for request in sorted(requests, key=lambda r: r.type)
],
max_request_type=fork.max_request_type(block_number=1, timestamp=1),
)
),
)
Expand Down
4 changes: 1 addition & 3 deletions tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2884,9 +2884,7 @@ def test_set_code_to_system_contract(
blocks=[
Block(
txs=txs,
requests_hash=Requests(
max_request_type=fork.max_request_type(block_number=1)
), # Verify nothing slipped into the requests trie
requests_hash=Requests(), # Verify nothing slipped into the requests trie
)
],
post={
Expand Down

0 comments on commit 5a40172

Please sign in to comment.