Skip to content

test_storage_access_cold_benchmark()

Documentation for tests/benchmark/compute/instruction/test_storage.py::test_storage_access_cold_benchmark@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_storage.py::test_storage_access_cold_benchmark --gas-benchmark-values 1

Benchmark cold storage slot accesses using code generator.

Each iteration accesses a different storage slot (incrementing key) to ensure cold access costs are measured.

Source code in tests/benchmark/compute/instruction/test_storage.py
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
@pytest.mark.repricing
@pytest.mark.parametrize(
    "storage_action",
    [
        pytest.param(StorageAction.READ, id="SLOAD"),
        pytest.param(StorageAction.WRITE_SAME_VALUE, id="SSTORE_same"),
        pytest.param(StorageAction.WRITE_NEW_VALUE, id="SSTORE_new"),
    ],
)
def test_storage_access_cold_benchmark(
    benchmark_test: BenchmarkTestFiller,
    storage_action: StorageAction,
) -> None:
    """
    Benchmark cold storage slot accesses using code generator.

    Each iteration accesses a different storage slot (incrementing key)
    to ensure cold access costs are measured.
    """
    if storage_action == StorageAction.READ:
        attack_block = Op.SLOAD(Op.GAS)
    elif storage_action == StorageAction.WRITE_SAME_VALUE:
        attack_block = Op.SSTORE(Op.GAS, Op.PUSH0)
    elif storage_action == StorageAction.WRITE_NEW_VALUE:
        attack_block = Op.SSTORE(Op.GAS, Op.GAS)

    benchmark_test(
        target_opcode=Op.SLOAD
        if storage_action == StorageAction.READ
        else Op.SSTORE,
        code_generator=ExtCallGenerator(attack_block=attack_block),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 3 forks.