Skip to content

test_valid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid@20373115.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py::test_valid --fork Amsterdam

Test the BLS12_PAIRING precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 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
@pytest.mark.parametrize(
    "input_data,expected_output,vector_gas_value",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("pairing_check_bls.json")
    + [
        pytest.param(
            Spec.G1 + Spec.INF_G2,
            Spec.PAIRING_TRUE,
            None,
            id="generator_with_inf_g2",
        ),
        pytest.param(
            Spec.INF_G1 + Spec.G2,
            Spec.PAIRING_TRUE,
            None,
            id="inf_g1_with_generator",
        ),
        pytest.param(  # e(inf, inf) == 1
            Spec.INF_G1 + Spec.INF_G2,
            Spec.PAIRING_TRUE,
            None,
            id="inf_pair",
        ),
        pytest.param(  # e(P, Q) . e(P, −Q) == 1 (inverse pair, factors cancel)
            Spec.G1 + Spec.G2 + Spec.G1 + (-Spec.G2),
            Spec.PAIRING_TRUE,
            None,
            id="g1_g2_and_inverse",
        ),
        pytest.param(  # e(P,Q) · e(P,−Q) · e(−P,Q) · e(−P,−Q) == 1
            Spec.G1
            + Spec.G2
            + Spec.G1
            + (-Spec.G2)
            + (-Spec.G1)
            + Spec.G2
            + (-Spec.G1)
            + (-Spec.G2),
            Spec.PAIRING_TRUE,
            None,
            id="full_sign_cancellation",
        ),
        pytest.param(  # 127 × e(inf, inf) . e(P, Q) + e(P, −Q) == 1
            (Spec.INF_G1 + Spec.INF_G2) * 127
            + Spec.G1
            + Spec.G2
            + Spec.G1
            + (-Spec.G2),
            Spec.PAIRING_TRUE,
            None,
            id="large_input_with_cancellation",
        ),
        pytest.param(  # e(P, Q) . e(−P, −Q) =  e(P, Q)^2
            Spec.G1 + Spec.G2 + (-Spec.G1) + (-Spec.G2),
            Spec.PAIRING_FALSE,
            None,
            id="negated_both_pairs",
        ),
        pytest.param(  # e(inf, inf) . e(P, −Q)
            (Spec.INF_G1 + Spec.INF_G2) + (Spec.G1 + (-Spec.G2)),
            Spec.PAIRING_FALSE,
            None,
            id="multi_inf_g1_neg_g2",
        ),
        pytest.param(
            (Spec.G1 + (-Spec.G2)) + (Spec.INF_G1 + Spec.INF_G2),
            Spec.PAIRING_FALSE,
            None,
            id="g1_neg_g2_multi_inf",
        ),
        pytest.param(
            Spec.G1 + Spec.G2,
            Spec.PAIRING_FALSE,
            None,
            id="single_generator_pair",
        ),
        pytest.param(
            (Spec.INF_G1 + Spec.INF_G2) + (Spec.G1 + Spec.G2),
            Spec.PAIRING_FALSE,
            None,
            id="inf_plus_generator_pair",
        ),
        pytest.param(  # e(P, Q) . e(P, −Q) . e(−P, Q)
            Spec.G1 + Spec.G2 + Spec.G1 + (-Spec.G2) + (-Spec.G1) + Spec.G2,
            Spec.PAIRING_FALSE,
            None,
            id="partial_sign_cancellation",
        ),
    ],
)
@pytest.mark.eels_base_coverage
def test_valid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Test the BLS12_PAIRING precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 26 parametrized test cases across 3 forks.