Skip to content

test_valid()

Documentation for tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py::test_valid@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py::test_valid --fork Bogota

Test valid calls to the BLS12_G1MSM precompile.

Source code in tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py
@pytest.mark.parametrize(
    "input_data,expected_output,vector_gas_value",
    # Test vectors from the reference spec (from the cryptography team)
    vectors_from_file("msm_G1_bls.json")
    + [
        # Multiple pair scalar multiplication cases.
        pytest.param(
            Spec.G1 + Scalar(1) + Spec.INF_G1 + Scalar(1),
            Spec.G1,
            None,
            id="g1_plus_inf",
        ),
        pytest.param(
            Spec.G1
            + Scalar(0)
            + Spec.P1
            + Scalar(0)
            + Spec.INF_G1
            + Scalar(0),
            Spec.INF_G1,
            None,
            id="all_zero_scalars",
        ),
        pytest.param(
            Spec.G1 + Scalar(1) + (-Spec.G1) + Scalar(1),
            Spec.INF_G1,
            None,
            id="sum_to_identity_opposite",
        ),
        pytest.param(
            Spec.G1 + Scalar(Spec.Q - 1) + Spec.G1 + Scalar(1),
            Spec.INF_G1,
            None,
            id="scalars_sum_to_q",
        ),
        pytest.param(
            Spec.G1
            + Scalar(1)
            + Spec.G1
            + Scalar(0)
            + Spec.INF_G1
            + Scalar(5),
            Spec.G1,
            None,
            id="combined_basic_cases",
        ),
        pytest.param(
            Spec.G1 + Scalar(1) + Spec.INF_G1 + Scalar(500),
            Spec.G1,
            None,
            id="identity_with_large_scalar",
        ),
        pytest.param(
            Spec.G1 + Scalar(0) + Spec.P1 + Scalar(0) + (-Spec.G1) + Scalar(0),
            Spec.INF_G1,
            None,
            id="multiple_points_zero_scalar",
        ),
        pytest.param(  # Scalar above Q with bit 255 set on the multi-pair path
            Spec.G1
            + Scalar(2**256 - 1)
            + Spec.G1
            + Scalar(Spec.Q - (2**256 - 1) % Spec.Q),
            Spec.INF_G1,
            None,
            id="max_scalar_sum_to_identity",
        ),
        # Cases with maximum discount table (test vector for gas cost
        # calculation)
        pytest.param(
            (Spec.P1 + Scalar(Spec.Q)) * (len(Spec.G1MSM_DISCOUNT_TABLE) - 1),
            Spec.INF_G1,
            None,
            id="max_discount",
        ),
        pytest.param(
            (Spec.P1 + Scalar(Spec.Q)) * len(Spec.G1MSM_DISCOUNT_TABLE),
            Spec.INF_G1,
            None,
            id="max_discount_plus_1",
        ),
    ],
)
@pytest.mark.slow()
def test_valid(
    state_test: StateTestFiller,
    pre: Alloc,
    post: dict,
    tx: Transaction,
) -> None:
    """Test valid calls to the BLS12_G1MSM precompile."""
    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post=post,
    )

Parametrized Test Cases

This test generates 173 parametrized test cases across 4 forks.