Contract Size Calculator
Calculate smart contract bytecode size and check against the 24KB EIP-170 limit
1. What is the 24KB limit?
EIP-170, implemented in the Spurious Dragon hard fork, limits smart contract bytecode size to 24,576 bytes (24 KB). This limit prevents DoS attacks and ensures network stability. Contracts exceeding this limit will fail to deploy.
2. How does it work?
Contract size is measured in bytes of deployed bytecode. Each pair of hexadecimal characters represents one byte. The size includes compiled Solidity code, constructor logic, and metadata. The tool divides hex string length by 2 to get byte count, then compares against the 24KB (24,576 bytes) limit.
Why was this limit introduced?
The 24KB limit was introduced to:
- Prevent network spam with extremely large contracts
- Limit memory requirements for nodes
- Reduce blockchain bloat
- Make it harder to create denial-of-service attacks
How to check contract size
You can check your contract size in several ways:
- Compile with Hardhat/Foundry and check the bytecode length
- Use hardhat-contract-sizer plugin for automated checking
- Query deployed contracts with eth_getCode RPC method
- Use this tool by pasting the compiled bytecode
Optimization strategies
Quick wins:
- Enable Solidity optimizer (runs: 200-1000)
- Replace require strings with custom errors
- Remove unused functions and imports
Architecture changes:
- Split logic across multiple contracts
- Use proxy patterns for upgradeability
- Extract common code to libraries
- Use minimal proxy (EIP-1167) for clones
3. Examples
OpenZeppelin ERC-20 (USDC-like)
Standard ERC-20: 5-6 KB
USDC (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48):
~13 KB with permit, minting, burning featuresUniswap V2 Pair contract
UniswapV2Pair (0xB4e16d0168e52d7dC3BA36907b029DCB3a17c8d1)
USDC/WETH: ~12.5 KB - highly optimized liquidity pairAave LendingPool (Proxy Pattern)
Main pool (0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9):
Uses UUPS proxy to exceed 24KB
Implementation splits: Core (~22KB), Interest (~8KB),
Flashloan (~6KB)