@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, LOOP_GAS_THRESHOLD),
)
+ 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,
)