Skip to content

Commit 843f4e8

Browse files
authored
fix(tests): modexp - cover more widths and parities of moduli (#1729)
1 parent ddf5842 commit 843f4e8

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

tests/byzantium/eip198_modexp_precompile/test_modexp.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
Transaction,
1717
compute_create_address,
1818
)
19+
from execution_testing.base_types.base_types import (
20+
FixedSizeBytes,
21+
)
1922

2023
from .helpers import ModExpInput, ModExpOutput
2124

@@ -146,35 +149,32 @@
146149
id="EIP-198-case5-raw-input",
147150
),
148151
# different declared moduli lengths and parities
149-
pytest.param(
150-
ModExpInput(
151-
base="1234",
152-
exponent="234",
153-
modulus="1000",
154-
declared_modulus_length=256,
155-
),
156-
ModExpOutput(
157-
returned_data=Bytes(
158-
"07be9ec040921bf6ffa9faad54b5e88c503ea4511cc15505e36fc9569cf20698"
159-
"933819b8c4b15e52a51f64261954708f55432c5a7011dc7d1787c64a8ece6f20"
160-
"65772d1dbc3ea9e96e3f55eeec7477bc92cb587ae416c8316fb3fa825ee25410"
161-
"811fad4f98ade2eaa665b48e930247bb30b25100000000000000000000000000"
162-
+ (256 - 4 * 32)
163-
* "00"
164-
)
165-
),
166-
id="EIP-198-case1-mod-power2-declared-length-256-bytes",
167-
),
168-
pytest.param(
169-
ModExpInput(
170-
base="1234",
171-
exponent="234",
172-
modulus="1010",
173-
declared_modulus_length=128,
174-
),
175-
ModExpOutput(returned_data=Bytes("00") + Bytes(hex(2**1014))),
176-
id="EIP-198-case1-mod-even-declared-length-128-bytes",
177-
),
152+
*[
153+
pytest.param(
154+
ModExpInput(
155+
base="1234",
156+
exponent="234",
157+
modulus="1000" if parity == "power2" else "1010",
158+
declared_modulus_length=width,
159+
),
160+
ModExpOutput(
161+
returned_data=FixedSizeBytes[width]( # type: ignore
162+
(
163+
(0x1234**0x234)
164+
% (
165+
(0x1000 if parity == "power2" else 0x1010)
166+
# declared `width` bitshifts modulus left.
167+
<< ((width - 2) * 8)
168+
)
169+
),
170+
left_padding=True,
171+
)
172+
),
173+
id=f"EIP-198-case1-mod-{parity}-declared-length-{width}-bytes",
174+
)
175+
for width in [64, 128, 256, 512]
176+
for parity in ["power2", "even"]
177+
],
178178
# out of gas cases
179179
pytest.param(
180180
Bytes(

0 commit comments

Comments
 (0)