Skip to content

Commit

Permalink
Merge branch 'eip-7251' into devnet-1
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jun 27, 2024
2 parents 789bd39 + cf2ba90 commit 48a9fcd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 51 deletions.
4 changes: 1 addition & 3 deletions src/ethereum_test_tools/common/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def to_fixed_size_bytes(input: FixedSizeBytesConvertible, size: int) -> bytes:
Converts multiple types into fixed-size bytes.
"""
if isinstance(input, int):
if input < 0:
return int.to_bytes(input, length=size, byteorder="big", signed=True)
return int.to_bytes(input, length=size, byteorder="big")
return int.to_bytes(input, length=size, byteorder="big", signed=input < 0)
input = to_bytes(input)
if len(input) > size:
raise Exception(f"input is too large for fixed size bytes: {len(input)} > {size}")
Expand Down
22 changes: 18 additions & 4 deletions tests/prague/eip7002_el_triggerable_withdrawals/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Fixtures for the EIP-7002 deposit tests.
"""
from itertools import zip_longest
from typing import List

import pytest
Expand Down Expand Up @@ -57,6 +58,13 @@ def included_requests(
excess_withdrawal_requests,
len(current_block_requests),
)
while carry_over_requests:
# Keep adding blocks until all withdrawal requests are included
per_block_included_requests.append(
carry_over_requests[: Spec.MAX_WITHDRAWAL_REQUESTS_PER_BLOCK]
)
carry_over_requests = carry_over_requests[Spec.MAX_WITHDRAWAL_REQUESTS_PER_BLOCK :]

return per_block_included_requests


Expand All @@ -69,10 +77,16 @@ def blocks(
"""
Return the list of blocks that should be included in the test.
"""
return [
return [ # type: ignore
Block(
txs=sum((r.transactions() for r in block_requests), []),
header_verify=Header(requests_root=included_requests[i]),
header_verify=Header(requests_root=block_included_requests),
)
for block_requests, block_included_requests in zip_longest(
blocks_withdrawal_requests,
included_requests,
fillvalue=[],
)
for i, block_requests in enumerate(blocks_withdrawal_requests)
]
] + [
Block(header_verify=Header(requests_root=[]))
] # 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 @@ -64,6 +64,7 @@
validator_pubkey=0x01,
amount=0,
fee=0,
valid=False,
)
],
),
Expand Down Expand Up @@ -262,7 +263,6 @@
),
pytest.param(
[
# Block 1
[
WithdrawalRequestTransaction(
requests=[
Expand All @@ -275,10 +275,6 @@
]
)
],
# Block 2, no new withdrawal requests, but queued requests from previous block
[],
# Block 3, no new nor queued withdrawal requests
[],
],
id="multiple_block_above_max_withdrawal_requests_from_eoa",
),
Expand Down
23 changes: 19 additions & 4 deletions tests/prague/eip7251_consolidations/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Fixtures for the EIP-7251 consolidations tests.
"""
from itertools import zip_longest
from typing import List

import pytest
Expand Down Expand Up @@ -57,6 +58,14 @@ def included_requests(
excess_consolidation_requests,
len(current_block_requests),
)

while carry_over_requests:
# Keep adding blocks until all consolidation requests are included
per_block_included_requests.append(
carry_over_requests[: Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK]
)
carry_over_requests = carry_over_requests[Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK :]

return per_block_included_requests


Expand All @@ -69,10 +78,16 @@ def blocks(
"""
Return the list of blocks that should be included in the test.
"""
return [
return [ # type: ignore
Block(
txs=sum((r.transactions() for r in block_requests), []),
header_verify=Header(requests_root=included_requests[i]),
header_verify=Header(requests_root=block_included_requests),
)
for block_requests, block_included_requests in zip_longest(
blocks_consolidation_requests,
included_requests,
fillvalue=[],
)
for i, block_requests in enumerate(blocks_consolidation_requests)
]
] + [
Block(header_verify=Header(requests_root=[]))
] # Add an empty block at the end to verify that no more consolidation requests are included
2 changes: 1 addition & 1 deletion tests/prague/eip7251_consolidations/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ConsolidationRequestInteractionBase:
"""
requests: List[ConsolidationRequest]
"""
Withdrawal request to be included in the block.
Consolidation requests to be included in the block.
"""

def transactions(self) -> List[Transaction]:
Expand Down
7 changes: 2 additions & 5 deletions tests/prague/eip7251_consolidations/spec.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Common procedures to test
[EIP-7251: Increase the MAX_EFFECTIVE_BALANCE](https://eips.ethereum.org/EIPS/eip-7251)
""" # noqa: E501
Defines EIP-7251 specification constants and functions.
"""

from dataclasses import dataclass

Expand Down Expand Up @@ -49,8 +48,6 @@ class Spec:
CONSOLIDATION_REQUEST_FEE_UPDATE_FRACTION = 17
EXCESS_INHIBITOR = 1181

MAX_AMOUNT = 2**64 - 1

@staticmethod
def fake_exponential(factor: int, numerator: int, denominator: int) -> int:
"""
Expand Down
71 changes: 49 additions & 22 deletions tests/prague/eip7251_consolidations/test_consolidations.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@
],
id="single_block_single_consolidation_request_from_eoa",
),
pytest.param(
[
[
ConsolidationRequestTransaction(
requests=[
ConsolidationRequest(
source_pubkey=0x01,
target_pubkey=0x01,
fee=Spec.get_fee(0),
)
],
),
],
],
id="single_block_single_consolidation_request_from_eoa_equal_pubkeys",
),
pytest.param(
[
[
ConsolidationRequestTransaction(
requests=[
ConsolidationRequest(
source_pubkey=-1,
target_pubkey=-2,
fee=Spec.get_fee(0),
)
],
),
],
],
id="single_block_single_consolidation_request_from_eoa_max_pubkeys",
),
pytest.param(
[
[
Expand All @@ -64,6 +96,7 @@
source_pubkey=0x01,
target_pubkey=0x02,
fee=0,
valid=False,
)
],
),
Expand Down Expand Up @@ -168,6 +201,9 @@
)
],
],
marks=pytest.mark.skip(
reason="duplicate test due to MAX_CONSOLIDATION_REQUESTS_PER_BLOCK==1"
),
id="single_block_max_consolidation_requests_from_eoa",
),
pytest.param(
Expand Down Expand Up @@ -262,7 +298,6 @@
),
pytest.param(
[
# Block 1
[
ConsolidationRequestTransaction(
requests=[
Expand All @@ -271,14 +306,10 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 2)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
]
)
],
# Block 2, no new consolidation requests, but queued requests from previous block
[],
# Block 3, no new nor queued consolidation requests
[],
],
id="multiple_block_above_max_consolidation_requests_from_eoa",
),
Expand Down Expand Up @@ -308,9 +339,7 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(
Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK
) # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
),
],
Expand All @@ -334,9 +363,7 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(
1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK
) # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
for i in range(1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
),
],
Expand All @@ -353,15 +380,15 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK - 1)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
]
+ [
ConsolidationRequest(
source_pubkey=-1,
target_pubkey=-2,
fee=0,
)
], # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
],
),
],
],
Expand All @@ -388,9 +415,9 @@
fee=Spec.get_fee(0),
valid=True,
)
for i in range(1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
), # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
),
],
],
id="single_block_multiple_consolidation_requests_from_contract_first_oog",
Expand All @@ -407,7 +434,7 @@
gas_limit=1_000_000,
valid=True,
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
]
+ [
ConsolidationRequest(
Expand All @@ -418,7 +445,7 @@
valid=False,
)
],
), # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
),
],
],
id="single_block_multiple_consolidation_requests_from_contract_last_oog",
Expand All @@ -434,11 +461,11 @@
fee=Spec.get_fee(0),
valid=False,
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
extra_code=Op.REVERT(0, 0),
),
], # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
],
],
id="single_block_multiple_consolidation_requests_from_contract_caller_reverts",
),
Expand All @@ -453,10 +480,10 @@
fee=Spec.get_fee(0),
valid=False,
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
extra_code=Macros.OOG(),
), # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
),
],
],
id="single_block_multiple_consolidation_requests_from_contract_caller_oog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,10 @@ def test_valid_deposit_withdrawal_consolidation_request_from_same_tx(
contract_code += Op.SSTORE(
storage.store_next(1),
Op.CALL(
Op.GAS,
call_contract_address,
value,
0,
len(current_calldata),
0,
0,
address=call_contract_address,
value=value,
args_offset=0,
args_size=len(current_calldata),
),
)

Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extcodehash
extcodesize
F00
filesystem
fillvalue
firstlineno
fn
fname
Expand Down

0 comments on commit 48a9fcd

Please # to comment.