Skip to content

test_invalid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_map_fp2_to_g2.py::test_invalid@636b5f17.

Generate fixtures for these test cases for Bogota with:

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

Negative tests for the BLS12_MAP_FP_TO_G2 precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_map_fp2_to_g2.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@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,
    )

Parametrized Test Cases

This test generates 22 parametrized test cases across 4 forks.