Skip to content

test_sload_bloated()

Documentation for tests/benchmark/stateful/bloatnet/test_single_opcode.py::test_sload_bloated@b314d18e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/stateful/bloatnet/test_single_opcode.py::test_sload_bloated --gas-benchmark-values 1

Benchmark SLOAD opcodes targeting an EOA with storage bloated.

The storage is assumed to be filled from 0-N linearly, where each slot has the value of the key. If this is not the storage layout of the target account, then the existing_slots parameter will not be correct.

Source code in tests/benchmark/stateful/bloatnet/test_single_opcode.py
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
@pytest.mark.repricing
@pytest.mark.stub_parametrize("token_name", "bloated_eoa_")
@pytest.mark.parametrize("existing_slots", [False, True])
@pytest.mark.parametrize("cache_strategy", [CacheStrategy.NO_CACHE])
def test_sload_bloated(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_benchmark_value: int,
    tx_gas_limit: int,
    token_name: str,
    existing_slots: bool,
    cache_strategy: CacheStrategy,
) -> None:
    """
    Benchmark SLOAD opcodes targeting an EOA with storage bloated.

    The storage is assumed to be filled from 0-N linearly, where
    each slot has the value of the key. If this is not the
    storage layout of the target account, then the existing_slots
    parameter will not be correct.
    """
    slot_access = (
        Op.DUP1  # [index, index]
        + Op.SLOAD  # [s[index], index]
        + Op.POP  # [index]
    )
    # CACHE_TX: access each slot twice so the second hit is uncached
    if cache_strategy == CacheStrategy.CACHE_TX:
        slot_access *= 2

    runtime_code = (
        Op.PUSH0  # [0]
        + Op.SLOAD  # [index], s[0] = index
        + While(
            body=(
                slot_access
                + Op.PUSH1(1)  # [1, index]
                + Op.ADD  # [index+1]
            ),
            condition=Op.GT(Op.GAS, 0xFFFF),
        )
        + Op.PUSH0  # [0, index+1]
        + Op.SSTORE  # s[0] = index+1
    )

    run_bloated_eoa_benchmark(
        benchmark_test=benchmark_test,
        pre=pre,
        fork=fork,
        gas_benchmark_value=gas_benchmark_value,
        tx_gas_limit=tx_gas_limit,
        authority=pre.stub_eoa(token_name),
        existing_slots=existing_slots,
        runtime_code=runtime_code,
        cache_strategy=cache_strategy,
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 3 forks.