Skip to content

test_invalid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_map_fp_to_g1.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_fp_to_g1.py::test_invalid --fork Amsterdam

Negative tests for the BLS12_MAP_FP_TO_G1 precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_map_fp_to_g1.py
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
147
148
149
150
151
152
153
154
155
@pytest.mark.parametrize(
    "input_data",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("fail-map_fp_to_G1_bls.json")
    + [
        pytest.param(b"\x80" + bytes(FP(0))[1:], id="invalid_encoding"),
        pytest.param(bytes(FP(0))[1:], id="input_too_short"),
        pytest.param(b"\x00" + FP(0), id="input_too_long"),
        pytest.param(b"", id="zero_length_input"),
        pytest.param(FP(Spec.P), id="fq_eq_q"),
        pytest.param(FP(2**512 - 1), id="fq_eq_2_512_minus_1"),
        pytest.param(Spec.G1, id="g1_input"),
        pytest.param(FP(Spec.P + 1), id="fp_above_modulus"),
        pytest.param(FP(2**384), id="fp_large_power_of_2"),
        pytest.param(bytes(FP(0)) + bytes([0x00]), id="fp_with_extra_byte"),
        pytest.param(bytes(FP(0))[:47], id="fp_one_byte_short"),
        pytest.param(
            bytes([0xFF]) + bytes(FP(0))[1:], id="fp_invalid_first_byte"
        ),
        pytest.param(Spec.INF_G1, id="g1_inf_input"),
        pytest.param(
            FP((Spec.P - 1) | Spec.MAX_FP_BIT_SET),
            id="non_zero_byte_16_boundary_violation",
        ),
    ],
)
@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_MAP_FP_TO_G1 precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 17 parametrized test cases across 3 forks.