@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",
),
pytest.param(
Spec.G1 + Spec.G2 + Spec.P1_NOT_IN_SUBGROUP + Spec.G2,
id="p1_not_in_subgroup_pos_1",
),
pytest.param(
Spec.G1 + Spec.G2 + Spec.G1 + Spec.P2_NOT_IN_SUBGROUP,
id="p2_not_in_subgroup_pos_1",
),
# 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,
)