Skip to content

test_worst_clz_diff_input()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_clz_diff_input@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

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

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

Source code in tests/benchmark/test_worst_compute.py
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
@pytest.mark.valid_from("Osaka")
def test_worst_clz_diff_input(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test running a block with as many CLZ with different input as
    possible.
    """
    max_code_size = fork.max_code_size()

    code_prefix = Op.JUMPDEST
    code_suffix = Op.PUSH0 + Op.JUMP

    available_code_size = max_code_size - len(code_prefix) - len(code_suffix)

    code_seq = Bytecode()

    for i in range(available_code_size):
        value = (2**256 - 1) >> (i % 256)
        clz_op = Op.CLZ(value) + Op.POP
        if len(code_seq) + len(clz_op) > available_code_size:
            break
        code_seq += clz_op

    attack_code = code_prefix + code_seq + code_suffix
    assert len(attack_code) <= max_code_size

    tx = Transaction(
        to=pre.deploy_contract(code=attack_code),
        sender=pre.fund_eoa(),
    )

    benchmark_test(tx=tx)

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated)
...fork_Osaka-blockchain_test