Skip to content

test_worst_blobhash()

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

Generate fixtures for these test cases for Osaka with:

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

Test running a block with as many BLOBHASH instructions as possible.

Source code in tests/benchmark/test_worst_compute.py
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
@pytest.mark.parametrize(
    "blob_index, blobs_present",
    [
        pytest.param(0, 0, id="no blobs"),
        pytest.param(0, 1, id="one blob and accessed"),
        pytest.param(1, 1, id="one blob but access non-existent index"),
        pytest.param(5, 6, id="six blobs, access latest"),
    ],
)
def test_worst_blobhash(
    fork: Fork,
    state_test: StateTestFiller,
    pre: Alloc,
    blob_index: int,
    blobs_present: bool,
    gas_benchmark_value: int,
):
    """Test running a block with as many BLOBHASH instructions as possible."""
    max_code_size = fork.max_code_size()
    max_stack_height = fork.max_stack_height()

    # Contract that contains a collection of BLOBHASH instructions.
    opcode_sequence = Op.BLOBHASH(blob_index) * max_stack_height
    assert len(opcode_sequence) <= max_code_size

    target_contract_address = pre.deploy_contract(code=opcode_sequence)

    # Contract that contains a loop of STATICCALLs to the target contract.
    calldata = Bytecode()
    attack_block = Op.POP(Op.STATICCALL(Op.GAS, target_contract_address, 0, 0, 0, 0))
    code = code_loop_precompile_call(calldata, attack_block, fork)
    assert len(code) <= max_code_size

    code_address = pre.deploy_contract(code=code)

    # Create blob transaction if blobs are present.
    tx_type = TransactionType.LEGACY
    blob_versioned_hashes = None
    max_fee_per_blob_gas = None
    if blobs_present > 0:
        tx_type = TransactionType.BLOB_TRANSACTION
        max_fee_per_blob_gas = fork.min_base_fee_per_blob_gas()
        blob_versioned_hashes = add_kzg_version(
            [i.to_bytes() * 32 for i in range(blobs_present)],
            BlobsSpec.BLOB_COMMITMENT_VERSION_KZG,
        )

    tx = Transaction(
        ty=tx_type,
        to=code_address,
        gas_limit=gas_benchmark_value,
        max_fee_per_blob_gas=max_fee_per_blob_gas,
        blob_versioned_hashes=blob_versioned_hashes,
        sender=pre.fund_eoa(),
    )

    state_test(
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) blob_index blobs_present
...fork_Prague-state_test-no blobs 0 0
...fork_Prague-state_test-one blob and accessed 0 1
...fork_Prague-state_test-one blob but access non-existent index 1 1
...fork_Prague-state_test-six blobs, access latest 5 6
...fork_Prague-blockchain_test_from_state_test-no blobs 0 0
...fork_Prague-blockchain_test_from_state_test-one blob and accessed 0 1
...fork_Prague-blockchain_test_from_state_test-one blob but access non-existent index 1 1
...fork_Prague-blockchain_test_from_state_test-six blobs, access latest 5 6
...fork_Osaka-state_test-no blobs 0 0
...fork_Osaka-state_test-one blob and accessed 0 1
...fork_Osaka-state_test-one blob but access non-existent index 1 1
...fork_Osaka-state_test-six blobs, access latest 5 6
...fork_Osaka-blockchain_test_from_state_test-no blobs 0 0
...fork_Osaka-blockchain_test_from_state_test-one blob and accessed 0 1
...fork_Osaka-blockchain_test_from_state_test-one blob but access non-existent index 1 1
...fork_Osaka-blockchain_test_from_state_test-six blobs, access latest 5 6