@pytest.mark.parametrize(
"input_data",
# Test vectors from the reference spec (from the cryptography team)
vectors_from_file("fail-map_fp2_to_G2_bls.json")
+ [
pytest.param(b"\x80" + bytes(FP2((0, 0)))[1:], id="invalid_encoding"),
pytest.param(bytes(FP2((0, 0)))[1:], id="input_too_short"),
pytest.param(b"\x00" + FP2((0, 0)), id="input_too_long"),
pytest.param(b"", id="zero_length_input"),
pytest.param(FP2((Spec.P, 0)), id="fq_eq_q"),
pytest.param(FP2((0, Spec.P)), id="fq_eq_q_2"),
pytest.param(FP2((2**512 - 1, 0)), id="fq_eq_2_512_minus_1"),
pytest.param(FP2((0, 2**512 - 1)), id="fq_eq_2_512_minus_1_2"),
pytest.param(Spec.G2, id="g2_input"),
pytest.param(FP2((Spec.P + 1, 0)), id="fp2_above_modulus_c0"),
pytest.param(FP2((0, Spec.P + 1)), id="fp2_above_modulus_c1"),
pytest.param(FP2((2**384, 0)), id="fp2_large_power_of_2_c0"),
pytest.param(FP2((0, 2**384)), id="fp2_large_power_of_2_c1"),
pytest.param(
bytes(FP2((0, 0))) + bytes([0x00]), id="fp2_with_extra_byte"
),
pytest.param(bytes(FP2((0, 0)))[:95], id="fp2_one_byte_short"),
pytest.param(
bytes([0xFF]) + bytes(FP2((0, 0)))[1:], id="fp2_invalid_first_byte"
),
pytest.param(Spec.INF_G2, id="g2_inf_input"),
pytest.param(
FP2(((Spec.P - 1) | Spec.MAX_FP_BIT_SET, Spec.P - 1)),
id="non_zero_byte_16_boundary_violation_c0",
),
pytest.param(
FP2((Spec.P - 1, (Spec.P - 1) | Spec.MAX_FP_BIT_SET)),
id="non_zero_byte_16_boundary_violation_c1",
),
],
)
@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_MAP_FP_TO_G2 precompile."""
state_test(
env=Environment(),
pre=pre,
tx=tx,
post=post,
)