test_extcodesize_bytecode_sizes()
Documentation for tests/benchmark/stateful/bloatnet/test_account_query.py::test_extcodesize_bytecode_sizes@26332146.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/benchmark/stateful/bloatnet/test_account_query.py::test_extcodesize_bytecode_sizes --gas-benchmark-values 1
Execute EXTCODESIZE benchmark against pre-deployed contracts.
Source code in tests/benchmark/stateful/bloatnet/test_account_query.py
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632 | @pytest.mark.parametrize(
"bytecode_size_kb",
[0.5, 1.0, 2.0, 5.0, 10.0, 24.0],
ids=lambda size: f"{size}KB",
)
def test_extcodesize_bytecode_sizes(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
bytecode_size_kb: float,
gas_benchmark_value: int,
tx_gas_limit: int,
) -> None:
"""Execute EXTCODESIZE benchmark against pre-deployed contracts."""
expected_size_bytes = int(bytecode_size_kb * 1024)
# Get factory stub name for this size
factory_stub = get_factory_stub_name(bytecode_size_kb)
# Deploy factory stub (address comes from stub file)
factory_address = pre.deploy_contract(
code=Bytecode(), # Empty bytecode - address from stub
stub=factory_stub,
)
# Build and deploy the attack contract
attack_code = build_attack_contract(factory_address)
attack_address = pre.deploy_contract(code=attack_code)
# Calculate how many transactions we need to fill the block
num_attack_txs = gas_benchmark_value // tx_gas_limit
if num_attack_txs == 0:
num_attack_txs = 1
# Fund the sender
sender = pre.fund_eoa()
# Build transactions
txs = []
# Attack transactions: all identical, no calldata needed
for _ in range(num_attack_txs):
attack_tx = Transaction(
gas_limit=tx_gas_limit,
to=attack_address,
sender=sender,
)
txs.append(attack_tx)
# Create block with all transactions
block = Block(txs=txs)
# Post-state verification:
# Attack contract slot 1 = expected size (last EXTCODESIZE result)
# Slot 0 can be any value (final salt depends on gas used)
attack_storage = Storage({1: expected_size_bytes}) # type: ignore[dict-item]
attack_storage.set_expect_any(0)
post = {
attack_address: Account(storage=attack_storage),
}
blockchain_test(
pre=pre,
post=post,
blocks=[block],
)
|
Parametrized Test Cases
This test generates 6 parametrized test cases across 3 forks.