115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 | @pytest.mark.parametrize("access_warm", [True, False])
@pytest.mark.parametrize("storage_keys_pre_set", [True, False])
def test_sload_benchmark(
benchmark_test: BenchmarkTestFiller,
fork: Fork,
pre: Alloc,
tx_gas_limit: int,
gas_benchmark_value: int,
access_warm: bool,
storage_keys_pre_set: bool,
) -> None:
"""
Benchmark SLOAD instruction with various configurations.
Uses EIP-7702 delegation. The authority EOA delegates to:
- StorageInitializer: storage[i] = 1 (if storage_keys_pre_set)
- BenchmarkExecutor: performs the benchmark operation (SLOAD)
Variants:
- access_warm: Warm storage slots via access list
- storage_keys_pre_set: Whether the storage keys are pre-set
"""
# Initial Storage Construction
initializer_code = create_sstore_initializer(init_val=1)
initializer_addr = pre.deploy_contract(code=initializer_code)
# Actual Benchmark Execution
executor_code = create_sload_executor(key_warm=access_warm)
executor_addr = pre.deploy_contract(code=executor_code)
authority = pre.fund_eoa(amount=0)
authority_nonce = 0
delegation_sender = pre.fund_eoa()
calldata_gen = partial(executor_calldata_generator)
access_list_gen = partial(
access_list_generator, access_warm=access_warm, authority=authority
)
# Number of slots that can be processed in the execution phase
num_target_slots = sum(
executor_code.tx_iterations_by_gas_limit(
fork=fork,
gas_limit=gas_benchmark_value,
calldata=calldata_gen,
access_list=access_list_gen,
start_iteration=1,
recipient_type=RecipientType.DELEGATION_7702,
)
)
# Setup phase: initialize storage slots (if storage_keys_pre_set)
with TestPhaseManager.setup():
blocks = build_delegated_storage_setup(
pre=pre,
fork=fork,
tx_gas_limit=tx_gas_limit,
needs_init=storage_keys_pre_set,
num_target_slots=num_target_slots,
initializer_code=initializer_code,
initializer_addr=initializer_addr,
executor_addr=executor_addr,
authority=authority,
authority_nonce=authority_nonce,
delegation_sender=delegation_sender,
initializer_calldata_generator=initializer_calldata_generator,
)
# Execution phase
expected_gas_used = 0
with TestPhaseManager.execution():
exec_txs = list(
executor_code.transactions_by_gas_limit(
fork=fork,
gas_limit=gas_benchmark_value,
sender=pre.fund_eoa(),
to=authority,
calldata=calldata_gen,
start_iteration=1,
access_list=access_list_gen,
recipient_type=RecipientType.DELEGATION_7702,
)
)
expected_gas_used = sum(tx.gas_cost for tx in exec_txs)
blocks.append(Block(txs=exec_txs))
benchmark_test(
pre=pre,
blocks=blocks,
expected_benchmark_gas_used=expected_gas_used,
)
|