Skip to content

Test EXTCODESIZE Bytecode Sizes

Documentation for tests/benchmark/stateful/bloatnet/test_extcodesize_bytecode_sizes.py@20373115.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/stateful/bloatnet/test_extcodesize_bytecode_sizes.py --gas-benchmark-values 1

Test EXTCODESIZE with parametrized bytecode sizes using CREATE2 factory.

This benchmark measures the performance impact of EXTCODESIZE operations on contracts of varying sizes (0.5KB to 24KB). It stresses client state loading by maximizing cold EXTCODESIZE calls.

Designed for execute mode only - contracts must be pre-deployed.

Gas-Based Loop Strategy

The attack contract uses a gas-based loop exit (per Jochem's suggestion): 1. Reads current salt from storage slot 0 2. Loops while gas > 50K, calling EXTCODESIZE on CREATE2 addresses 3. Saves final salt to storage slot 0 when exiting 4. Next TX automatically resumes from where previous left off

This eliminates manual gas calculations - the contract self-regulates.

Test Block Structure

┌───────────────────────────────────────────────────────────────┐ │ Test Block │ ├───────────────────────────────────────────────────────────────┤ │ TX1: Attack (~16M gas) │ │ └─> Loops EXTCODESIZE until gas < 50K, saves salt │ │ │ │ TX2: Attack (~16M gas) │ │ └─> Resumes from TX1's salt, continues looping │ │ │ │ TX3: Attack (~16M gas) │ │ └─> Resumes from TX2's salt, continues looping │ └───────────────────────────────────────────────────────────────┘

Post-state verification checks attack contract's slot 1 for expected size.

Execute a Single Size

uv run execute remote \\
  --fork Osaka \\
  --rpc-endpoint http://127.0.0.1:8545 \\
  --rpc-seed-key <SEED_KEY> \\
  --rpc-chain-id 1337 \\
  --address-stubs tests/benchmark/stateful/bloatnet/stubs.json \\
  -- --gas-benchmark-values 60 \\
  tests/benchmark/stateful/bloatnet/test_extcodesize_bytecode_sizes.py \\
  -k '24KB' -v

Execute All Sizes

uv run execute remote \\
  --fork Osaka \\
  --rpc-endpoint http://127.0.0.1:8545 \\
  --rpc-seed-key <SEED_KEY> \\
  --rpc-chain-id 1337 \\
  --address-stubs tests/benchmark/stateful/bloatnet/stubs.json \\
  -- --gas-benchmark-values 60 \\
  tests/benchmark/stateful/bloatnet/test_extcodesize_bytecode_sizes.py -v

Test Functions Overview

Name Type Cases (Amsterdam) Description
test_extcodesize_bytecode_sizes blockchain_test 6 Execute EXTCODESIZE benchmark against pre-deployed contracts.