308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401 | @pytest.mark.parametrize("out_of_gas", [True, False])
def test_nested_creates(
benchmark_test: BenchmarkTestFiller,
pre: Alloc,
fork: Fork,
tx_gas_limit: int,
gas_benchmark_value: int,
out_of_gas: bool,
) -> None:
"""Benchmark chains of nested CREATE frames."""
initcode_size = 32
copy_self = Op.CODECOPY(
dest_offset=0,
offset=0,
size=Op.CODESIZE,
# gas accounting
data_size=initcode_size,
old_memory_size=0,
new_memory_size=initcode_size,
)
create_self = Op.POP(
Op.CREATE(
value=0,
offset=0,
size=Op.CODESIZE,
# gas accounting
init_code_size=initcode_size,
old_memory_size=initcode_size,
new_memory_size=initcode_size,
)
)
initcode = copy_self + create_self
if not out_of_gas:
initcode = copy_self + Conditional(
condition=Op.GT(Op.GAS, 2 * initcode.gas_cost(fork)),
if_true=create_self,
)
assert len(initcode) <= initcode_size, "initcode outgrew its padding"
initcode += Op.STOP * (initcode_size - len(initcode))
setup = Om.MSTORE(bytes(initcode), 0)
launch = Op.POP(
Op.CREATE(
value=0,
offset=0,
size=initcode_size,
# gas accounting
init_code_size=initcode_size,
old_memory_size=initcode_size,
new_memory_size=initcode_size,
)
)
if out_of_gas:
benchmark_test(
target_opcode=Op.CREATE,
code_generator=JumpLoopGenerator(setup=setup, attack_block=launch),
)
else:
driver_address = pre.deploy_contract(
code=setup + WhileGas(body=launch, fork=fork)
)
# Every level spends fifteen times more state gas than execution
# gas, so a single transaction asking for the whole budget goes
# deeper than several could: the state gas the chain spends counts
# against the budget whether a reservoir or execution gas paid it.
gas_limit = min(tx_gas_limit, gas_benchmark_value)
if fork.state_gas_reservoir_enabled():
gas_limit = gas_benchmark_value
benchmark_test(
target_opcode=Op.CREATE,
skip_gas_used_validation=True,
post={
compute_create_address(
address=driver_address, nonce=1
): Account(nonce=2, code=b""),
},
blocks=[
Block(
txs=[
Transaction(
to=driver_address,
gas_limit=gas_limit,
sender=pre.fund_eoa(),
)
]
)
],
)
|