Skip to content

test_valid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py::test_valid@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

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

Test valid calls to the BLS12_G2MSM precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 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
@pytest.mark.parametrize(
    "input_data,expected_output,vector_gas_value",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("msm_G2_bls.json")
    + [
        # Multiple pair scalar multiplication cases.
        pytest.param(
            Spec.G2 + Scalar(1) + Spec.INF_G2 + Scalar(1),
            Spec.G2,
            None,
            id="g2_plus_inf",
        ),
        pytest.param(
            Spec.G2
            + Scalar(0)
            + Spec.P2
            + Scalar(0)
            + Spec.INF_G2
            + Scalar(0),
            Spec.INF_G2,
            None,
            id="all_zero_scalars",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + (-Spec.G2) + Scalar(1),
            Spec.INF_G2,
            None,
            id="sum_to_identity_opposite",
        ),
        pytest.param(
            Spec.G2 + Scalar(Spec.Q - 1) + Spec.G2 + Scalar(1),
            Spec.INF_G2,
            None,
            id="scalars_sum_to_q",
        ),
        pytest.param(
            Spec.G2
            + Scalar(1)
            + Spec.G2
            + Scalar(0)
            + Spec.INF_G2
            + Scalar(5),
            Spec.G2,
            None,
            id="combined_basic_cases",
        ),
        pytest.param(
            Spec.G2 + Scalar(1) + Spec.INF_G2 + Scalar(500),
            Spec.G2,
            None,
            id="identity_with_large_scalar",
        ),
        pytest.param(
            Spec.G2 + Scalar(0) + Spec.P2 + Scalar(0) + (-Spec.G2) + Scalar(0),
            Spec.INF_G2,
            None,
            id="multiple_points_zero_scalar",
        ),
        # Cases with maximum discount table (test vector for gas cost
        # calculation)
        pytest.param(
            (Spec.P2 + Scalar(Spec.Q)) * (len(Spec.G2MSM_DISCOUNT_TABLE) - 1),
            Spec.INF_G2,
            None,
            id="max_discount",
            marks=pytest.mark.slow,
        ),
        pytest.param(
            (Spec.P2 + Scalar(Spec.Q)) * len(Spec.G2MSM_DISCOUNT_TABLE),
            Spec.INF_G2,
            None,
            id="max_discount_plus_1",
            marks=pytest.mark.slow,
        ),
    ],
)
@pytest.mark.slow()
def test_valid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Test valid calls to the BLS12_G2MSM precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 173 parametrized test cases across 3 forks.