Skip to content

test_worst_blobhash()

Documentation for tests/benchmark/test_worst_compute.py::test_worst_blobhash@0f7c73a7.

Generate fixtures for these test cases for Prague with:

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

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

Source code in tests/benchmark/test_worst_compute.py
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
@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,
):
    """Test running a block with as many BLOBHASH instructions as possible."""
    env = Environment()
    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=env.gas_limit,
        max_fee_per_blob_gas=max_fee_per_blob_gas,
        blob_versioned_hashes=blob_versioned_hashes,
        sender=pre.fund_eoa(),
    )

    state_test(
        env=env,
        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