Skip to content

test_invalid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_invalid@21507778.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_invalid --fork Amsterdam

Negative tests for the BLS12_PAIRING precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
@pytest.mark.parametrize(
    "input_data",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("fail-pairing_check_bls.json")
    + [
        # Coordinate equal to p (modulus) in G1
        pytest.param(
            PointG1(Spec.P, 0) + Spec.INF_G2,
            id="g1_p_g2_inf_1",
        ),
        pytest.param(
            PointG1(0, Spec.P) + Spec.INF_G2,
            id="g1_p_g2_inf_2",
        ),
        # Coordinate equal to p (modulus) in G2
        pytest.param(
            Spec.INF_G1 + PointG2((Spec.P, 0), (0, 0)),
            id="g1_inf_g2_p_1",
        ),
        pytest.param(
            Spec.INF_G1 + PointG2((0, Spec.P), (0, 0)),
            id="g1_inf_g2_p_2",
        ),
        pytest.param(
            Spec.INF_G1 + PointG2((0, 0), (Spec.P, 0)),
            id="g1_inf_g2_p_3",
        ),
        pytest.param(
            Spec.INF_G1 + PointG2((0, 0), (0, Spec.P)),
            id="g1_inf_g2_p_4",
        ),
        pytest.param(
            b"\x80" + bytes(Spec.INF_G1)[1:] + Spec.INF_G2,
            id="invalid_encoding_g1",
        ),
        pytest.param(
            Spec.INF_G1 + b"\x80" + bytes(Spec.INF_G2)[1:],
            id="invalid_encoding_g2",
        ),
        pytest.param(
            Spec.P1_NOT_IN_SUBGROUP + Spec.INF_G2,
            id="p1_not_in_subgroup",
        ),
        pytest.param(
            Spec.INF_G1 + Spec.P2_NOT_IN_SUBGROUP,
            id="p2_not_in_subgroup",
        ),
        # Points not in the subgroup or not on the curve randomly generated.
        pytest.param(
            G1_POINTS_NOT_ON_CURVE[0] + Spec.INF_G2,
            id="rand_not_on_curve_g1_0_plus_inf",
        ),
        pytest.param(
            G1_POINTS_NOT_ON_CURVE[1] + Spec.G2,
            id="rand_not_on_curve_g1_1_plus_g2",
        ),
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[0] + Spec.G2,
            id="rand_not_in_subgroup_g1_0_plus_g2",
        ),
        pytest.param(
            G1_POINTS_NOT_IN_SUBGROUP[1] + Spec.INF_G2,
            id="rand_not_in_subgroup_g1_1_plus_inf",
        ),
        pytest.param(
            Spec.INF_G1 + G2_POINTS_NOT_ON_CURVE[0],
            id="inf_plus_rand_not_on_curve_g2_0",
        ),
        pytest.param(
            Spec.G1 + G2_POINTS_NOT_ON_CURVE[1],
            id="g1_plus_rand_not_on_curve_g2_1",
        ),
        pytest.param(
            Spec.INF_G1 + G2_POINTS_NOT_IN_SUBGROUP[0],
            id="inf_plus_rand_not_in_subgroup_g2_0",
        ),
        pytest.param(
            Spec.G1 + G2_POINTS_NOT_IN_SUBGROUP[1],
            id="g1_plus_rand_not_in_subgroup_g2_1",
        ),
        # Coordinates above modulus p cases.
        pytest.param(
            PointG1(Spec.P1.x + Spec.P, Spec.P1.y) + Spec.INF_G2,
            id="g1_x_above_p_with_inf_g2",
        ),
        pytest.param(
            PointG1(Spec.P1.x, Spec.P1.y + Spec.P) + Spec.INF_G2,
            id="g1_y_above_p_with_inf_g2",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y),
            id="inf_g1_with_g2_x_c0_above_p",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y),
            id="inf_g1_with_g2_x_c1_above_p",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1])),
            id="inf_g1_with_g2_y_c0_above_p",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P)),
            id="inf_g1_with_g2_y_c1_above_p",
        ),
        # BLS serialization flag byte in coordinate: values >= p whose first
        # coordinate byte has BLS flag bits set.
        # See: https://github.com/lambdaclass/ethrex/pull/6287
        pytest.param(
            PointG1(0x40 << (47 * 8), 0) + Spec.INF_G2,
            id="g1_x_bls_infinity_flag",
        ),
        # Non-zero byte 16 boundary violation test cases.
        pytest.param(
            PointG1(Spec.G1.x | Spec.MAX_FP_BIT_SET, Spec.G1.y) + Spec.INF_G2,
            id="non_zero_byte_16_boundary_violation_g1_x",
        ),
        pytest.param(
            PointG1(Spec.G1.x, Spec.G1.y | Spec.MAX_FP_BIT_SET) + Spec.INF_G2,
            id="non_zero_byte_16_boundary_violation_g1_y",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2(
                (Spec.G2.x[0] | Spec.MAX_FP_BIT_SET, Spec.G2.x[1]), Spec.G2.y
            ),
            id="non_zero_byte_16_boundary_violation_g1_x1",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2(
                (Spec.G2.x[0], Spec.G2.x[1] | Spec.MAX_FP_BIT_SET), Spec.G2.y
            ),
            id="non_zero_byte_16_boundary_violation_g1_x2",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2(
                Spec.G2.x, (Spec.G2.y[0] | Spec.MAX_FP_BIT_SET, Spec.G2.y[1])
            ),
            id="non_zero_byte_16_boundary_violation_g1_y1",
        ),
        pytest.param(
            Spec.INF_G1
            + PointG2(
                Spec.G2.x, (Spec.G2.y[0], Spec.G2.y[1] | Spec.MAX_FP_BIT_SET)
            ),
            id="non_zero_byte_16_boundary_violation_g1_y2",
        ),
    ],
)
@pytest.mark.parametrize("expected_output", [Spec.INVALID], ids=[""])
@pytest.mark.eels_base_coverage
def test_invalid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Negative tests for the BLS12_PAIRING precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 54 parametrized test cases across 3 forks.