Skip to content

test_invalid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py::test_invalid@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py::test_invalid --fork Bogota

Negative tests for the BLS12_G2ADD precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py
@pytest.mark.parametrize(
    "input_data",
    vectors_from_file("fail-add_G2_bls.json")
    + [
        pytest.param(
            PointG2((1, 0), (0, 0)) + Spec.INF_G2,
            id="invalid_point_a_1",
        ),
        pytest.param(
            PointG2((0, 0), (1, 0)) + Spec.INF_G2,
            id="invalid_point_a_2",
        ),
        pytest.param(
            PointG2((0, 1), (0, 0)) + Spec.INF_G2,
            id="invalid_point_a_3",
        ),
        pytest.param(
            PointG2((0, 0), (0, 1)) + Spec.INF_G2,
            id="invalid_point_a_4",
        ),
        pytest.param(
            PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] - 1)) + Spec.P2,
            id="invalid_point_a_5",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((1, 0), (0, 0)),
            id="invalid_point_b_1",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((0, 0), (1, 0)),
            id="invalid_point_b_2",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((0, 1), (0, 0)),
            id="invalid_point_b_3",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((0, 0), (0, 1)),
            id="invalid_point_b_4",
        ),
        pytest.param(
            Spec.P2 + PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] - 1)),
            id="invalid_point_b_5",
        ),
        pytest.param(
            PointG2((Spec.P, 0), (0, 0)) + Spec.INF_G2,
            id="a_x_1_equal_to_p",
        ),
        pytest.param(
            PointG2((0, Spec.P), (0, 0)) + Spec.INF_G2,
            id="a_x_2_equal_to_p",
        ),
        pytest.param(
            PointG2((0, 0), (Spec.P, 0)) + Spec.INF_G2,
            id="a_y_1_equal_to_p",
        ),
        pytest.param(
            PointG2((0, 0), (0, Spec.P)) + Spec.INF_G2,
            id="a_y_2_equal_to_p",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((Spec.P, 0), (0, 0)),
            id="b_x_1_equal_to_p",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((0, Spec.P), (0, 0)),
            id="b_x_2_equal_to_p",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((0, 0), (Spec.P, 0)),
            id="b_y_1_equal_to_p",
        ),
        pytest.param(
            Spec.INF_G2 + PointG2((0, 0), (0, Spec.P)),
            id="b_y_2_equal_to_p",
        ),
        pytest.param(
            PointG2((Spec.P2.x[0] + Spec.P, Spec.P2.x[1]), Spec.P2.y)
            + Spec.G2,
            id="a_x_1_above_p",
        ),
        pytest.param(
            PointG2((Spec.P2.x[0], Spec.P2.x[1] + Spec.P), Spec.P2.y)
            + Spec.G2,
            id="a_x_2_above_p",
        ),
        pytest.param(
            PointG2(Spec.P2.x, (Spec.P2.y[0] + Spec.P, Spec.P2.y[1]))
            + Spec.G2,
            id="a_y_1_above_p",
        ),
        pytest.param(
            PointG2(Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] + Spec.P))
            + Spec.G2,
            id="a_y_2_above_p",
        ),
        pytest.param(
            Spec.P2
            + PointG2((Spec.G2.x[0] + Spec.P, Spec.G2.x[1]), Spec.G2.y),
            id="b_x_1_above_p",
        ),
        pytest.param(
            Spec.P2
            + PointG2((Spec.G2.x[0], Spec.G2.x[1] + Spec.P), Spec.G2.y),
            id="b_x_2_above_p",
        ),
        pytest.param(
            Spec.P2
            + PointG2(Spec.G2.x, (Spec.G2.y[0] + Spec.P, Spec.G2.y[1])),
            id="b_y_1_above_p",
        ),
        pytest.param(
            Spec.P2
            + PointG2(Spec.G2.x, (Spec.G2.y[0], Spec.G2.y[1] + Spec.P)),
            id="b_y_2_above_p",
        ),
        pytest.param(
            b"\x80" + bytes(Spec.INF_G2)[1:] + Spec.INF_G2,
            id="invalid_encoding_a",
        ),
        pytest.param(
            Spec.INF_G2 + b"\x80" + bytes(Spec.INF_G2)[1:],
            id="invalid_encoding_b",
        ),
        pytest.param(
            (Spec.INF_G2 + Spec.INF_G2)[:-1],
            id="input_too_short",
        ),
        pytest.param(
            b"\x00" + (Spec.INF_G2 + Spec.INF_G2),
            id="input_too_long",
        ),
        pytest.param(
            b"",
            id="zero_length_input",
        ),
        pytest.param(
            Spec.G2,
            id="only_one_point",
        ),
        pytest.param(
            Spec.G1 + Spec.G1,
            id="g1_points",
        ),
        pytest.param(
            PointG2((Spec.P + 1, 0), (0, 0)) + Spec.INF_G2,
            id="x1_above_modulus",
        ),
        pytest.param(
            PointG2(
                (0x01, 0),  # x coordinate in Fp2 (1 + 0i)
                (0x07, 0),  # y coordinate satisfying y^2 = x^3 + 5 in Fp2
            )
            + Spec.INF_G2,
            id="point_on_wrong_curve_b=5",
        ),
        pytest.param(
            bytes(Spec.G2) + bytes(Spec.G2)[128:],
            id="mixed_g1_g2_points",
        ),
        pytest.param(
            PointG2(
                (Spec.P2.x[0] | Spec.MAX_FP_BIT_SET, Spec.P2.x[1]), Spec.P2.y
            )
            + Spec.P2,
            id="non_zero_byte_16_boundary_violation_x1",
        ),
        pytest.param(
            PointG2(
                (Spec.P2.x[0], Spec.P2.x[1] | Spec.MAX_FP_BIT_SET), Spec.P2.y
            )
            + Spec.P2,
            id="non_zero_byte_16_boundary_violation_x2",
        ),
        pytest.param(
            PointG2(
                Spec.P2.x, (Spec.P2.y[0] | Spec.MAX_FP_BIT_SET, Spec.P2.y[1])
            )
            + Spec.P2,
            id="non_zero_byte_16_boundary_violation_y1",
        ),
        pytest.param(
            PointG2(
                Spec.P2.x, (Spec.P2.y[0], Spec.P2.y[1] | Spec.MAX_FP_BIT_SET)
            )
            + Spec.P2,
            id="non_zero_byte_16_boundary_violation_y2",
        ),
        # Not on the curve cases using random generated points.
        pytest.param(
            G2_POINTS_NOT_ON_CURVE[0] + Spec.INF_G2,
            id="rand_not_on_curve_0_plus_inf",
        ),
        pytest.param(
            G2_POINTS_NOT_ON_CURVE[1] + Spec.P2,
            id="rand_not_on_curve_1_plus_point",
        ),
        pytest.param(
            G2_POINTS_NOT_ON_CURVE[2] + G2_POINTS_NOT_IN_SUBGROUP[0],
            id="rand_not_on_curve_2_plus_not_in_subgroup_0",
        ),
        pytest.param(
            G2_POINTS_NOT_ON_CURVE[3] + G2_POINTS_NOT_ON_CURVE[4],
            id="rand_not_on_curve_3_plus_4",
        ),
        pytest.param(
            Spec.INF_G2 + G2_POINTS_NOT_ON_CURVE[0],
            id="inf_plus_rand_not_on_curve_0",
        ),
        pytest.param(
            Spec.P2 + G2_POINTS_NOT_ON_CURVE[1],
            id="point_plus_rand_not_on_curve_1",
        ),
        pytest.param(
            G2_POINTS_NOT_IN_SUBGROUP[2] + G2_POINTS_NOT_ON_CURVE[2],
            id="rand_not_in_subgroup_2_plus_rand_not_on_curve_2",
        ),
    ],
)
@pytest.mark.parametrize("expected_output", [Spec.INVALID], ids=[""])
def test_invalid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Negative tests for the BLS12_G2ADD precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 52 parametrized test cases across 4 forks.