15
15
)
16
16
from ethereum_test_tools .vm .opcode import Opcodes as Op
17
17
18
+ from ...byzantium .eip198_modexp_precompile .helpers import ModExpInput
18
19
from .helpers import vectors_from_file
19
20
from .spec import Spec , ref_spec_7883
20
21
@@ -75,9 +76,9 @@ def create_modexp_input(
75
76
return bytes .fromhex (input_hex )
76
77
77
78
78
- def generate_invalid_inputs_cases ():
79
- """Generate test cases for invalid ModExp inputs."""
80
- return [
79
+ @ pytest . mark . parametrize (
80
+ "modexp_input,modexp_expected,call_succeeds" ,
81
+ [
81
82
pytest .param (bytes (), bytes (), False , id = "zero-length-calldata" ),
82
83
pytest .param (
83
84
create_modexp_input (10 , 11 , 12 , b_data = "FF" * 9 ),
@@ -103,21 +104,92 @@ def generate_invalid_inputs_cases():
103
104
False ,
104
105
id = "all-zeros" ,
105
106
),
106
- ]
107
+ ],
108
+ )
109
+ @EIPChecklist .Precompile .Test .Inputs .AllZeros
110
+ def test_modexp_invalid_inputs (
111
+ state_test : StateTestFiller ,
112
+ pre : Alloc ,
113
+ tx : Transaction ,
114
+ post : Dict ,
115
+ ):
116
+ """Test ModExp gas cost with invalid inputs."""
117
+ state_test (
118
+ pre = pre ,
119
+ tx = tx ,
120
+ post = post ,
121
+ )
122
+
123
+
124
+ def create_boundary_modexp_case (
125
+ base : str = "FF" , exponent : str = "FF" , modulus : str = "FF" , case_id : str = ""
126
+ ):
127
+ """
128
+ Create a single boundary ModExp test case.
129
+
130
+ Args:
131
+ base: Base data (hex string)
132
+ exponent: Exponent data (hex string)
133
+ modulus: Modulus data (hex string)
134
+ case_id: Test case identifier
135
+
136
+ Returns:
137
+ pytest.param for the test case
138
+
139
+ """
140
+ modexp_input = ModExpInput (
141
+ base = base ,
142
+ exponent = exponent ,
143
+ modulus = modulus ,
144
+ )
145
+ return pytest .param (modexp_input , Spec .modexp_error , False , id = case_id )
107
146
108
147
109
148
@pytest .mark .parametrize (
110
149
"modexp_input,modexp_expected,call_succeeds" ,
111
- generate_invalid_inputs_cases (),
150
+ [
151
+ create_boundary_modexp_case (
152
+ base = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ), case_id = "base-too-long"
153
+ ),
154
+ create_boundary_modexp_case (
155
+ exponent = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ), case_id = "exponent-too-long"
156
+ ),
157
+ create_boundary_modexp_case (
158
+ modulus = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ), case_id = "modulus-too-long"
159
+ ),
160
+ create_boundary_modexp_case (
161
+ base = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
162
+ exponent = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
163
+ modulus = "FF" ,
164
+ case_id = "base-exponent-too-long" ,
165
+ ),
166
+ create_boundary_modexp_case (
167
+ base = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
168
+ exponent = "FF" ,
169
+ modulus = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
170
+ case_id = "base-modulus-too-long" ,
171
+ ),
172
+ create_boundary_modexp_case (
173
+ base = "FF" ,
174
+ exponent = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
175
+ modulus = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
176
+ case_id = "exponent-modulus-too-long" ,
177
+ ),
178
+ create_boundary_modexp_case (
179
+ base = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
180
+ exponent = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
181
+ modulus = "FF" * (Spec .MAX_LENGTH_BYTES + 1 ),
182
+ case_id = "all-too-long" ,
183
+ ),
184
+ ],
112
185
)
113
- @EIPChecklist .Precompile .Test .Inputs .AllZeros
114
- def test_modexp_invalid_inputs (
186
+ def test_modexp_boundary_inputs (
115
187
state_test : StateTestFiller ,
116
188
pre : Alloc ,
117
189
tx : Transaction ,
118
190
post : Dict ,
119
191
):
120
- """Test ModExp gas cost with invalid inputs."""
192
+ """Test ModExp boundary inputs."""
121
193
state_test (
122
194
pre = pre ,
123
195
tx = tx ,
0 commit comments