Skip to content

Commit df69127

Browse files
authored
tests(eip7823): Add implementation coverage tests for ModExp bounds (#2117)
Add 5 targeted test cases to improve EIP-7823 implementation coverage: - all_exceed_check_ordering: Tests check ordering when all bounds exceed - exp_mod_exceed_base_ok: Tests partial bound violations - bitwise_pattern_base_exceed: Tests Nethermind bitwise optimization - near_uint64_max_base: Tests revm integer conversion edge case - zero_exp_mod_exceed: Tests zero exponent with modulus exceeding
1 parent b1441c9 commit df69127

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/osaka/eip7823_modexp_upper_bounds/test_modexp_upper_bounds.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,53 @@ def precompile_gas(fork: Fork, mod_exp_input: ModExpInput) -> int:
129129
),
130130
id="exp_2_pow_64_base_0_mod_0",
131131
),
132+
# Implementation coverage tests
133+
pytest.param(
134+
ModExpInput(
135+
base=b"\xff" * (MAX_LENGTH_BYTES + 1),
136+
exponent=b"\xff" * (MAX_LENGTH_BYTES + 1),
137+
modulus=b"\xff" * (MAX_LENGTH_BYTES + 1),
138+
),
139+
id="all_exceed_check_ordering",
140+
),
141+
pytest.param(
142+
ModExpInput(
143+
base=b"\x00" * MAX_LENGTH_BYTES,
144+
exponent=b"\xff" * (MAX_LENGTH_BYTES + 1),
145+
modulus=b"\xff" * (MAX_LENGTH_BYTES + 1),
146+
),
147+
id="exp_mod_exceed_base_ok",
148+
),
149+
pytest.param(
150+
ModExpInput(
151+
# Bitwise pattern for Nethermind optimization
152+
base=b"\xaa" * (MAX_LENGTH_BYTES + 1),
153+
exponent=b"\x55" * MAX_LENGTH_BYTES,
154+
modulus=b"\xff" * MAX_LENGTH_BYTES,
155+
),
156+
id="bitwise_pattern_base_exceed",
157+
),
158+
pytest.param(
159+
ModExpInput(
160+
base=b"",
161+
exponent=b"",
162+
modulus=b"",
163+
# Near max uint64 for revm conversion test
164+
declared_base_length=2**63 - 1,
165+
declared_exponent_length=1,
166+
declared_modulus_length=1,
167+
),
168+
id="near_uint64_max_base",
169+
),
170+
pytest.param(
171+
ModExpInput(
172+
base=b"\x01" * MAX_LENGTH_BYTES,
173+
exponent=b"",
174+
modulus=b"\x02" * (MAX_LENGTH_BYTES + 1),
175+
declared_exponent_length=0,
176+
),
177+
id="zero_exp_mod_exceed",
178+
),
132179
],
133180
)
134181
def test_modexp_upper_bounds(

0 commit comments

Comments
 (0)