Skip to content

test_worst_blobhash()

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

Generate fixtures for these test cases for Osaka with:

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

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

Source code in tests/benchmark/test_worst_compute.py
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
@pytest.mark.valid_from("Cancun")
@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_Cancun-state_test-no blobs 0 0
...fork_Cancun-state_test-one blob and accessed 0 1
...fork_Cancun-state_test-one blob but access non-existent index 1 1
...fork_Cancun-state_test-six blobs, access latest 5 6
...fork_Cancun-blockchain_test_from_state_test-no blobs 0 0
...fork_Cancun-blockchain_test_from_state_test-one blob and accessed 0 1
...fork_Cancun-blockchain_test_from_state_test-one blob but access non-existent index 1 1
...fork_Cancun-blockchain_test_from_state_test-six blobs, access latest 5 6
...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