Skip to content

Commit 93984e2

Browse files
authored
feat(tests): port stPreCompiledContracts/modexp 128-byte carry cases (#2753)
Add two MODEXP parametrizations with 128-byte (1024-bit) operands to test_modexp. Both use modulus 2**1024 - 0x69 and reduce to 9^exp mod m (in the first case, base = m + 9). The modulus size forces the implementation through the multi-word Montgomery/Barrett reduction path rather than any 256-bit specialization. Also bump the test's gas_limit from 500k to 2M so the Byzantium pre-EIP-2565 cost (~682k for a 128-byte modulus) fits. The bump is a no-op for every existing case: the "out-of-gas" params OOG on modexp's own gas formula (huge declared exp/mod lengths), not on the tx cap, so they stay OOG at 2M. Ported from two legacy fillers that the bulk static-filler import in #1442 did not pull in: - src/LegacyTests/Constantinople/GeneralStateTestsFiller/ stPreCompiledContracts/modexp_37120_37111_37111_1000000Filler.json - src/LegacyTests/Constantinople/GeneralStateTestsFiller/ stPreCompiledContracts/modexp_9_37111_37111_1000000Filler.json Those fillers live in the ethereum/tests LegacyTests submodule (ethereum/legacytests), which the original port did not descend into.
1 parent e7043cc commit 93984e2

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

tests/byzantium/eip198_modexp_precompile/test_modexp.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,40 @@
449449
),
450450
id="truncated_input_4",
451451
),
452+
# 128-byte (1024-bit) operands exercising the multi-word
453+
# Montgomery/Barrett reduction carry path. Modulus is
454+
# 2**1024 - 0x69, so neither operand hits any 256-bit
455+
# specialization. Both cases reduce to 9^exp mod m (base=m+9 in
456+
# the first case), and with this exp, 9^exp ≡ 9 mod m.
457+
pytest.param(
458+
ModExpInput(
459+
base="ff" * 127 + "a0",
460+
exponent="ff" * 127 + "97",
461+
modulus="ff" * 127 + "97",
462+
),
463+
ModExpOutput(returned_data="0x" + "00" * 127 + "09"),
464+
id="modexp_37120_37111_37111_1000000",
465+
),
466+
pytest.param(
467+
ModExpInput(
468+
base="09",
469+
exponent="ff" * 127 + "97",
470+
modulus="ff" * 127 + "97",
471+
),
472+
ModExpOutput(returned_data="0x" + "00" * 127 + "09"),
473+
id="modexp_9_37111_37111_1000000",
474+
),
452475
],
453476
ids=lambda param: param.__repr__(), # only required to remove parameter
454477
# names (input/output)
455478
)
456479
@pytest.mark.eels_base_coverage
480+
@pytest.mark.ported_from(
481+
[
482+
"https://github.com/ethereum/legacytests/blob/master/src/LegacyTests/Constantinople/GeneralStateTestsFiller/stPreCompiledContracts/modexp_37120_37111_37111_1000000Filler.json",
483+
"https://github.com/ethereum/legacytests/blob/master/src/LegacyTests/Constantinople/GeneralStateTestsFiller/stPreCompiledContracts/modexp_9_37111_37111_1000000Filler.json",
484+
],
485+
)
457486
def test_modexp(
458487
state_test: StateTestFiller,
459488
mod_exp_input: ModExpInput | Bytes,
@@ -504,7 +533,7 @@ def test_modexp(
504533
ty=0x0,
505534
to=account,
506535
data=mod_exp_input,
507-
gas_limit=500_000,
536+
gas_limit=2_000_000,
508537
protected=True,
509538
sender=sender,
510539
)

0 commit comments

Comments
 (0)