Skip to content

test_tstore()

Documentation for tests/benchmark/compute/instruction/test_storage.py::test_tstore@02aafd78.

Generate fixtures for these test cases for Bogota with:

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

Benchmark TSTORE against a growing transient store.

GAS gives a unique key per write with no memory counter, and COINBASE a nonzero value, so every write inserts an entry instead of being elided.

Source code in tests/benchmark/compute/instruction/test_storage.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@pytest.mark.repricing(fixed_key=False, tload="none")
@pytest.mark.parametrize("fixed_key", [True, False])
@pytest.mark.parametrize("tload", ["none", "hit", "miss"])
def test_tstore(
    benchmark_test: BenchmarkTestFiller,
    fixed_key: bool,
    tload: str,
) -> None:
    """
    Benchmark TSTORE against a growing transient store.

    GAS gives a unique key per write with no memory counter, and COINBASE a
    nonzero value, so every write inserts an entry instead of being elided.
    """
    assert Environment().fee_recipient != Address(0), (
        "coinbase must be nonzero so the TSTORE value is nonzero"
    )

    key = Op.PUSH0 if fixed_key else Op.GAS
    setup = Bytecode()
    value = Op.COINBASE
    match tload:
        case "hit":
            # Seed the value and feed each read into the next TSTORE so
            # the TLOAD is not discarded. Stack carries [value].
            setup = Op.COINBASE
            attack_block = key + Op.SWAP1 + Op.DUP2 + Op.TSTORE + Op.TLOAD
        case "miss":
            # Read a fresh, never-written key: a miss on a growing store.
            attack_block = Op.TSTORE(key, value) + Op.POP(Op.TLOAD(Op.GAS))
        case "none":
            attack_block = Op.TSTORE(key, value)
        case _:
            raise ValueError(f"Unknown tload mode: {tload}")

    benchmark_test(
        target_opcode=Op.TSTORE,
        code_generator=JumpLoopGenerator(
            setup=setup,
            attack_block=attack_block,
        ),
    )

Parametrized Test Cases

This test generates 6 parametrized test cases across 4 forks.