Skip to content

test_worst_clz_same_input()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_clz_same_input@v5.0.0.

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_clz_same_input --fork Osaka

Test running a block with as many CLZ with same input as possible.

Source code in tests/benchmark/test_worst_compute.py
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
@pytest.mark.valid_from("Osaka")
def test_worst_clz_same_input(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_benchmark_value: int,
    env: Environment,
):
    """Test running a block with as many CLZ with same input as possible."""
    tx_gas_limit = fork.transaction_gas_limit_cap() or env.gas_limit

    magic_value = 248  # CLZ(248) = 248

    calldata = Op.PUSH1(magic_value)
    attack_block = Op.CLZ
    code = code_loop_precompile_call(calldata, attack_block, fork)
    assert len(code) <= fork.max_code_size()

    code_address = pre.deploy_contract(code=code)

    sender = pre.fund_eoa()
    tx_count = gas_benchmark_value // tx_gas_limit
    remainder_gas = gas_benchmark_value % tx_gas_limit

    txs = [
        Transaction(
            to=code_address,
            gas_limit=tx_gas_limit if i < tx_count else remainder_gas,
            nonce=i,
            sender=sender,
        )
        for i in range(tx_count + 1)
    ]

    blockchain_test(
        genesis_environment=env,
        pre=pre,
        post={},
        blocks=[Block(txs=txs)],
    )

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated)
...fork_Osaka-blockchain_test