Skip to content

Commit 846d5cc

Browse files
authored
feat(tests): add critical BLS tests with invalid point coordinates (#2000)
This adds test cases for BLS precompiles where one of the point (G1/G2) coordinates is "slightly" above the value of the field prime P. The "slightly above" means that a valid point is modified by adding P to one of its field elements. Such test case has a chance of detecting an invalid implementation where the field element is loaded as 384-bit integer and converted to the Montgomery form. The Montgomery form round-trip has the effect of computing a value mod P, i.e. `(x + P) % P` gives `x` and the invalid point becomes valid. In the similar way test cases may be extended to other BLS precompiles. However, I assume BLS precompiles implementations share the input validation code.
1 parent 666cd64 commit 846d5cc

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ def test_valid(
273273
Spec.INF_G1 + PointG1(0, Spec.P),
274274
id="b_y_equal_to_p",
275275
),
276+
pytest.param(
277+
PointG1(Spec.P1.x + Spec.P, Spec.P1.y) + Spec.G1,
278+
id="a_x_above_p",
279+
),
280+
pytest.param(
281+
PointG1(Spec.P1.x, Spec.P1.y + Spec.P) + Spec.G1,
282+
id="a_y_above_p",
283+
),
284+
pytest.param(
285+
Spec.P1 + PointG1(Spec.G1.x + Spec.P, Spec.G1.y),
286+
id="b_x_above_p",
287+
),
288+
pytest.param(
289+
Spec.P1 + PointG1(Spec.G1.x, Spec.G1.y + Spec.P),
290+
id="b_y_above_p",
291+
),
276292
pytest.param(
277293
b"\x80" + bytes(Spec.INF_G1)[1:] + Spec.INF_G1,
278294
id="invalid_encoding_a",

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,38 @@ def test_valid(
289289
Spec.INF_G2 + PointG2((0, 0), (0, Spec.P)),
290290
id="b_y_2_equal_to_p",
291291
),
292+
pytest.param(
293+
PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y) + Spec.G2,
294+
id="a_x_1_above_p",
295+
),
296+
pytest.param(
297+
PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y) + Spec.G2,
298+
id="a_x_2_above_p",
299+
),
300+
pytest.param(
301+
PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1])) + Spec.G2,
302+
id="a_y_1_above_p",
303+
),
304+
pytest.param(
305+
PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P)) + Spec.G2,
306+
id="a_y_2_above_p",
307+
),
308+
pytest.param(
309+
Spec.P2 + PointG2((Spec.G2.x[0] + Spec.P, Spec.G2.x[1]), Spec.G2.y),
310+
id="b_x_1_above_p",
311+
),
312+
pytest.param(
313+
Spec.P2 + PointG2((Spec.G2.x[0], Spec.G2.x[1] + Spec.P), Spec.G2.y),
314+
id="b_x_2_above_p",
315+
),
316+
pytest.param(
317+
Spec.P2 + PointG2(Spec.G2.x, (Spec.G2.y[0] + Spec.P, Spec.G2.y[1])),
318+
id="b_y_1_above_p",
319+
),
320+
pytest.param(
321+
Spec.P2 + PointG2(Spec.G2.x, (Spec.G2.y[0], Spec.G2.y[1] + Spec.P)),
322+
id="b_y_2_above_p",
323+
),
292324
pytest.param(
293325
b"\x80" + bytes(Spec.INF_G2)[1:] + Spec.INF_G2,
294326
id="invalid_encoding_a",

0 commit comments

Comments
 (0)