Skip to content

Commit 880f8d8

Browse files
authored
feat(tests): extra BLS tests with invalid point coords (#2004)
* feat(tests): extra BLS tests with invalid point coords. * chore(tests): remove redundancies.
1 parent 846d5cc commit 880f8d8

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ethereum_test_tools import Opcodes as Op
1010

1111
from .conftest import G1_POINTS_NOT_IN_SUBGROUP, G1_POINTS_NOT_ON_CURVE
12-
from .helpers import vectors_from_file
12+
from .helpers import PointG1, vectors_from_file
1313
from .spec import Scalar, Spec, ref_spec_2537
1414

1515
REFERENCE_SPEC_GIT_PATH = ref_spec_2537.git_path
@@ -180,6 +180,23 @@ def test_valid(
180180
bytes([0]) * 159, # Just under minimum valid length
181181
id="input_too_short_by_1",
182182
),
183+
# Coordinates above modulus p cases.
184+
pytest.param(
185+
PointG1(Spec.P1.x + Spec.P, Spec.P1.y) + Scalar(1),
186+
id="x_above_p_pos_0",
187+
),
188+
pytest.param(
189+
PointG1(Spec.P1.x, Spec.P1.y + Spec.P) + Scalar(1),
190+
id="y_above_p_pos_0",
191+
),
192+
pytest.param(
193+
Spec.G1 + Scalar(1) + PointG1(Spec.P1.x + Spec.P, Spec.P1.y) + Scalar(0),
194+
id="x_above_p_pos_1",
195+
),
196+
pytest.param(
197+
Spec.G1 + Scalar(1) + PointG1(Spec.P1.x, Spec.P1.y + Spec.P) + Scalar(0),
198+
id="y_above_p_pos_1",
199+
),
183200
],
184201
# Input length tests can be found in ./test_bls12_variable_length_input_contracts.py
185202
)

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ethereum_test_tools import Opcodes as Op
1010

1111
from .conftest import G2_POINTS_NOT_IN_SUBGROUP, G2_POINTS_NOT_ON_CURVE
12-
from .helpers import vectors_from_file
12+
from .helpers import PointG2, vectors_from_file
1313
from .spec import Scalar, Spec, ref_spec_2537
1414

1515
REFERENCE_SPEC_GIT_PATH = ref_spec_2537.git_path
@@ -178,6 +178,51 @@ def test_valid(
178178
bytes([0]) * 287, # Just under minimum valid length
179179
id="input_too_short_by_1",
180180
),
181+
# Coordinates above modulus p cases.
182+
pytest.param(
183+
PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y) + Scalar(1),
184+
id="x_c0_above_p_pos_0",
185+
),
186+
pytest.param(
187+
PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y) + Scalar(1),
188+
id="x_c1_above_p_pos_0",
189+
),
190+
pytest.param(
191+
PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1])) + Scalar(1),
192+
id="y_c0_above_p_pos_0",
193+
),
194+
pytest.param(
195+
PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P)) + Scalar(1),
196+
id="y_c1_above_p_pos_0",
197+
),
198+
pytest.param(
199+
Spec.G2
200+
+ Scalar(1)
201+
+ PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y)
202+
+ Scalar(0),
203+
id="x_c0_above_p_pos_1",
204+
),
205+
pytest.param(
206+
Spec.G2
207+
+ Scalar(1)
208+
+ PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y)
209+
+ Scalar(0),
210+
id="x_c1_above_p_pos_1",
211+
),
212+
pytest.param(
213+
Spec.G2
214+
+ Scalar(1)
215+
+ PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1]))
216+
+ Scalar(0),
217+
id="y_c0_above_p_pos_1",
218+
),
219+
pytest.param(
220+
Spec.G2
221+
+ Scalar(1)
222+
+ PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P))
223+
+ Scalar(0),
224+
id="y_c1_above_p_pos_1",
225+
),
181226
],
182227
# Input length tests can be found in ./test_bls12_variable_length_input_contracts.py
183228
)

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,31 @@ def test_valid_multi_inf(
267267
Spec.G1 + G2_POINTS_NOT_IN_SUBGROUP[1],
268268
id="g1_plus_rand_not_in_subgroup_g2_1",
269269
),
270+
# Coordinates above modulus p cases.
271+
pytest.param(
272+
PointG1(Spec.P1.x + Spec.P, Spec.P1.y) + Spec.INF_G2,
273+
id="g1_x_above_p_with_inf_g2",
274+
),
275+
pytest.param(
276+
PointG1(Spec.P1.x, Spec.P1.y + Spec.P) + Spec.INF_G2,
277+
id="g1_y_above_p_with_inf_g2",
278+
),
279+
pytest.param(
280+
Spec.INF_G1 + PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y),
281+
id="inf_g1_with_g2_x_c0_above_p",
282+
),
283+
pytest.param(
284+
Spec.INF_G1 + PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y),
285+
id="inf_g1_with_g2_x_c1_above_p",
286+
),
287+
pytest.param(
288+
Spec.INF_G1 + PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1])),
289+
id="inf_g1_with_g2_y_c0_above_p",
290+
),
291+
pytest.param(
292+
Spec.INF_G1 + PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P)),
293+
id="inf_g1_with_g2_y_c1_above_p",
294+
),
270295
],
271296
)
272297
@pytest.mark.parametrize("expected_output", [Spec.INVALID], ids=[""])

0 commit comments

Comments
 (0)