Skip to content

test_modexp()

Documentation for tests/benchmark/compute/precompile/test_modexp.py::test_modexp@tests-bal@v5.7.0.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/precompile/test_modexp.py::test_modexp --gas-benchmark-values 1

Test running a block with as many calls to the MODEXP (5) precompile as possible. All the calls have the same parametrized input.

Source code in tests/benchmark/compute/precompile/test_modexp.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
@pytest.mark.parametrize(
    ["mod_exp_input"],
    create_modexp_test_cases(),
)
def test_modexp(
    benchmark_test: BenchmarkTestFiller,
    mod_exp_input: ModExpInput,
) -> None:
    """
    Test running a block with as many calls to the MODEXP (5) precompile as
    possible. All the calls have the same parametrized input.
    """
    attack_block = Op.POP(
        Op.STATICCALL(
            Op.GAS, 0x5, Op.PUSH0, Op.CALLDATASIZE, Op.PUSH0, Op.PUSH0
        )
    )
    benchmark_test(
        target_opcode=Precompile.MODEXP,
        code_generator=JumpLoopGenerator(
            setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE),
            attack_block=attack_block,
            tx_kwargs={"data": bytes(mod_exp_input).rstrip(b"\x00")},
        ),
    )

Parametrized Test Cases

This test generates 85 parametrized test cases across 3 forks.