Skip to content

test_invalid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_map_fp2_to_g2.py::test_invalid@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
@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 3 forks.