Skip to content

test_worst_blobhash()

Documentation for tests/zkevm/test_worst_compute.py::test_worst_blobhash@64f949d0.

Generate fixtures for these test cases for Prague with:

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

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

Source code in tests/zkevm/test_worst_compute.py
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
@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()

    code_prefix = Op.PUSH1(blob_index) + Op.JUMPDEST
    code_suffix = Op.JUMP(len(code_prefix) - 1)
    loop_iter = Op.POP(Op.BLOBHASH(Op.DUP1))
    code_body_len = (max_code_size - len(code_prefix) - len(code_suffix)) // len(loop_iter)
    code_body = loop_iter * code_body_len
    code = code_prefix + code_body + code_suffix
    assert len(code) <= max_code_size

    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=pre.deploy_contract(code=code),
        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