Skip to content

test_modexp()

Documentation for tests/benchmark/compute/precompile/test_modexp.py::test_modexp@c74f1a67.

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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
@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 112 parametrized test cases across 3 forks.