Skip to content

test_storage_access_warm_benchmark()

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

Generate fixtures for these test cases for Amsterdam with:

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

Benchmark warm storage slot accesses using code generator.

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

Source code in tests/benchmark/compute/instruction/test_storage.py
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
@pytest.mark.repricing
@pytest.mark.parametrize(
    "storage_action",
    [
        pytest.param(StorageAction.READ, id="SLOAD"),
        pytest.param(StorageAction.WRITE_SAME_VALUE, id="SSTORE same value"),
        pytest.param(StorageAction.WRITE_NEW_VALUE, id="SSTORE new value"),
    ],
)
def test_storage_access_warm_benchmark(
    benchmark_test: BenchmarkTestFiller,
    storage_action: StorageAction,
) -> None:
    """
    Benchmark warm storage slot accesses using code generator.

    Each iteration accesses a different storage slot (incrementing key)
    to ensure warm access costs are measured.
    """
    match storage_action:
        case StorageAction.WRITE_SAME_VALUE:
            # Timestamp is nonzero (no txs run in Genesis block),
            # Always writes to the zero key a nonzero, constant value
            attack_block = Op.SSTORE(Op.PUSH0, Op.TIMESTAMP)
        case StorageAction.WRITE_NEW_VALUE:
            attack_block = Op.SSTORE(Op.PUSH0, Op.GAS)
        case StorageAction.READ:
            attack_block = Op.SLOAD(Op.PUSH0)
        case _:
            raise ValueError("Unspecified storage action")

    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.