Single contract design for minimal-overhead storage benchmarking with parametrized operations.
This implementation uses ONE contract that:
- Is pre-deployed with 500 filled storage slots
- Accepts parameters via calldata for flexible operation
- Performs storage operations with minimal loop overhead (~30-40 gas per slot)
Bytes 0-31: Number of slots to write (uint256)
Bytes 32-63: Starting slot index (uint256)
Bytes 64-95: Value to write (uint256)
- 500 slots pre-filled with value
0xDEADBEEF - Enables testing all transition types without redeployment
- Single contract instance for all benchmarks
- Start: Slot 500 (beyond prefilled range)
- Operation: Write new value to empty slots
- Gas Cost: ~20,000 gas per slot (most expensive)
- Use Case: Initial storage allocation
- Start: Slot 0 (within prefilled range)
- Operation: Write zeros to clear existing values
- Gas Cost: ~2,900 gas per slot + refund
- Use Case: Storage cleanup/deletion
- Start: Slot 0 (within prefilled range)
- Operation: Update existing values
- Gas Cost: ~2,900 gas per slot
- Use Case: Typical storage updates
Per iteration:
- DUP operations: 12 gas (4 × 3 gas)
- ADD operation: 3 gas
- LT comparison: 3 gas
- ISZERO: 3 gas
- JUMPI/JUMP: 18 gas (8 + 10)
- SSTORE: Variable (based on transition)
Total overhead: ~39 gas per slot
- Basic loop contract: ~100 bytes
- Well under EIP-3860 limit (24,576 bytes)
- Can handle thousands of operations per call
| Transition Type | Gas per Slot | Notes |
|---|---|---|
| 0 → non-zero | 20,000 | Cold slot, initial write |
| non-zero → 0 | 2,900 + refund | Max 20% refund of total gas |
| non-zero → non-zero | 2,900 | Warm slot update |
| Loop overhead | ~39 | Minimal per-slot overhead |
# Run benchmarks with stateful marker
uv run fill tests/benchmark/stateful/vector_storage/test_vector_storage.py \
-m stateful --fork Prague# Direct execution
uv run consume direct --input fixtures/ --client-bin /path/to/geth
# Via Engine API
uv run consume engine --input fixtures/ --engine-endpoint http://localhost:8551- Single Deployment: One contract handles all scenarios
- Consistent Overhead: Same loop structure for all operations
- Flexible Testing: Parametrized via calldata
- Realistic Patterns: Mimics real smart contract storage patterns
- Accurate Benchmarking: Minimal overhead ensures accurate gas measurements
- num_slots: [1, 10, 50, 100, 200] - Number of slots per operation
- batch_size: [10, 25, 50] - For batch operation tests
- Pre-filled slots: 500 - Consistent across all tests
The contract can be called with raw calldata:
# Write 100 values starting at slot 500
calldata = (
(100).to_bytes(32, 'big') + # num_slots
(500).to_bytes(32, 'big') + # start_slot
(0x1234).to_bytes(32, 'big') # value
)This design provides the most accurate storage benchmarking with minimal overhead and maximum flexibility.