Skip to content

test_worst_clz_same_input()

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

Generate fixtures for these test cases for Osaka with:

fill -v tests/benchmark/test_worst_compute.py::test_worst_clz_same_input -m benchmark

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

Source code in tests/benchmark/test_worst_compute.py
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
@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