Skip to content

test_modexp_length_above_upper_bound()

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

Generate fixtures for these test cases for Amsterdam with:

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

Benchmark MODEXP rejecting a length above its EIP-7823 upper bound.

Source code in tests/benchmark/compute/precompile/test_modexp.py
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
@pytest.mark.valid_from("Osaka")
@pytest.mark.parametrize(
    "base_length,exponent_length,modulus_length",
    [
        pytest.param(Spec.MAX_LENGTH_BYTES + 1, 1, 1, id="oversized base"),
        pytest.param(1, Spec.MAX_LENGTH_BYTES + 1, 1, id="oversized exponent"),
        pytest.param(1, 1, Spec.MAX_LENGTH_BYTES + 1, id="oversized modulus"),
    ],
)
def test_modexp_length_above_upper_bound(
    benchmark_test: BenchmarkTestFiller,
    base_length: int,
    exponent_length: int,
    modulus_length: int,
) -> None:
    """
    Benchmark MODEXP rejecting a length above its EIP-7823 upper bound.
    """
    mod_exp_input = ModExpInput(
        base=b"\x01",
        exponent=b"\x01",
        modulus=b"\x01",
        declared_base_length=base_length,
        declared_exponent_length=exponent_length,
        declared_modulus_length=modulus_length,
    )

    attack_block = Op.POP(
        Op.STATICCALL(
            gas=Spec7883.calculate_gas_cost(mod_exp_input),
            address=Spec.MODEXP_ADDRESS,
            args_size=Op.CALLDATASIZE,
        ),
    )

    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)},
        ),
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 2 forks.