Skip to content

Commit bf117bf

Browse files
authored
feat(tests): Add more cases for EIP-7951 (#2023)
* feat(tests): Add additional invalid inputs * feat(tests): Add tests for zero gas, 3450 gas * feat(tests): Test precompiles in traditional range, and one outside range * feat(tests): Check return status * feat(tests): Test wrong endianness * fix(tests): Remove brittle storage check
1 parent d0ee738 commit bf117bf

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

tests/berlin/eip2929_gas_cost_increases/test_precompile_warming.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,27 @@ def precompile_addresses_in_predecessor_successor(
4040
boolean indicating whether the address has existed in the predecessor.
4141
4242
"""
43+
precompile_range = range(0x01, 0x100)
4344
predecessor_precompiles = set(get_transition_fork_predecessor(fork).precompiles())
4445
successor_precompiles = set(get_transition_fork_successor(fork).precompiles())
4546
all_precompiles = successor_precompiles | predecessor_precompiles
46-
highest_precompile = int.from_bytes(max(all_precompiles), byteorder="big")
47+
48+
precompiles_in_range = {
49+
addr
50+
for addr in all_precompiles
51+
if int.from_bytes(addr, byteorder="big") in precompile_range
52+
}
53+
54+
highest_in_range = max(int.from_bytes(addr, byteorder="big") for addr in precompiles_in_range)
55+
highest_overall = max(int.from_bytes(addr, byteorder="big") for addr in all_precompiles)
4756
extra_range = 32
4857
extra_precompiles = {
49-
Address(i) for i in range(highest_precompile + 1, highest_precompile + extra_range)
58+
Address(i) for i in range(highest_in_range + 1, highest_in_range + extra_range)
5059
}
51-
all_precompiles = all_precompiles | extra_precompiles
60+
extra_precompiles_outside_range = {Address(highest_overall + 1)}
61+
62+
all_precompiles = all_precompiles | extra_precompiles | extra_precompiles_outside_range
63+
5264
for address in sorted(all_precompiles):
5365
yield address, address in successor_precompiles, address in predecessor_precompiles
5466

tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,34 @@ def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transact
9090
Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Y(Spec.Y0.value + 1),
9191
id="point_not_on_curve_y",
9292
),
93+
pytest.param(
94+
Spec.H0 + Spec.R0 + Spec.S0 + Spec.Y0 + Spec.X0,
95+
id="x_and_y_reversed",
96+
),
97+
pytest.param(
98+
Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Y(Spec.P + 1),
99+
id="y_greater_than_p",
100+
),
101+
pytest.param(
102+
Spec.H0 + Spec.R0 + Spec.S0 + X(Spec.P + 1) + Spec.Y0,
103+
id="x_greater_than_p",
104+
),
105+
pytest.param(
106+
Spec.H0
107+
+ R(0x813EF79CCEFA9A56F7BA805F0E478584FE5F0DD5F567BC09B5123CCBC9832365)
108+
+ S(0x900E75AD233FCC908509DBFF5922647DB37C21F4AFD3203AE8DC4AE7794B0F87)
109+
+ X(0xB838FF44E5BC177BF21189D0766082FC9D843226887FC9760371100B7EE20A6F)
110+
+ Y(0xF0C9D75BFBA7B31A6BCA1974496EEB56DE357071955D83C4B1BADAA0B21832E9),
111+
id="valid_secp256k1_inputs",
112+
),
113+
pytest.param(
114+
H(0x235060CAFE19A407880C272BC3E73600E3A12294F56143ED61929C2FF4525ABB)
115+
+ R(0x182E5CBDF96ACCB859E8EEA1850DE5FF6E430A19D1D9A680ECD5946BBEA8A32B)
116+
+ S(0x76DDFAE6797FA6777CAAB9FA10E75F52E70A4E6CEB117B3C5B2F445D850BD64C)
117+
+ X(0x3828736CDFC4C8696008F71999260329AD8B12287846FEDCEDE3BA1205B12729)
118+
+ Y(0x3E5141734E971A8D55015068D9B3666760F4608A49B11F92E500ACEA647978C7),
119+
id="wrong_endianness",
120+
),
93121
],
94122
)
95123
@pytest.mark.parametrize("expected_output", [Spec.INVALID_RETURN_VALUE], ids=[""])
@@ -98,6 +126,7 @@ def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transact
98126
@pytest.mark.eip_checklist("precompile/test/inputs/invalid")
99127
@pytest.mark.eip_checklist("precompile/test/inputs/invalid/crypto")
100128
@pytest.mark.eip_checklist("precompile/test/inputs/invalid/corrupted")
129+
@pytest.mark.eip_checklist("precompile/test/input_lengths/zero")
101130
@pytest.mark.eip_checklist("precompile/test/input_lengths/static/correct")
102131
@pytest.mark.eip_checklist("precompile/test/input_lengths/static/too_short")
103132
@pytest.mark.eip_checklist("precompile/test/input_lengths/static/too_long")
@@ -123,6 +152,20 @@ def test_invalid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transa
123152
False,
124153
id="insufficient_gas",
125154
),
155+
pytest.param(
156+
Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Spec.Y0,
157+
Spec.INVALID_RETURN_VALUE,
158+
-6900,
159+
False,
160+
id="zero_gas",
161+
),
162+
pytest.param(
163+
Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Spec.Y0,
164+
Spec.INVALID_RETURN_VALUE,
165+
-3450,
166+
False,
167+
id="3450_gas",
168+
),
126169
],
127170
)
128171
@pytest.mark.parametrize("precompile_address", [Spec.P256VERIFY], ids=[""])

0 commit comments

Comments
 (0)