Bytecode Size Limit Remediation
Overview
Related Detector: Bytecode Size Limit
EIP-170 caps deployed contract bytecode at 24,576 bytes; a contract over the limit simply cannot be deployed on mainnet or most EVM chains. The remediation is to reduce code size — enable the optimizer, split logic across libraries or modules, or adopt a proxy/diamond architecture that spreads functionality across multiple contracts.
Recommended Fix
Options, roughly in order of effort:
1. Enable the optimizer (and tune runs) — often recovers several KB.
settings: { optimizer: { enabled: true, runs: 200 } }
2. Move reusable logic into external `library` contracts (linked, not inlined).
3. Split the contract into modules behind a proxy, or use the EIP-2535
diamond pattern so a single address routes to many facet contracts,
each under the 24,576-byte limit.
// Extract heavy pure/view logic into a library deployed separately.
library PricingLib {
function quote(uint256 x, uint256 y) external pure returns (uint256) { /* ... */ }
}
contract Market {
using PricingLib for uint256; // logic lives in the linked library, not inline
}
Prefer real modularization over shrinking readable code; a diamond keeps each facet small and independently upgradeable.
Common Mistakes
- Deleting error strings and comments to save bytes while leaving the real bloat (duplicated logic) in place.
- Cranking optimizer
runsvery high for size when a low value produces smaller code. - Splitting into a diamond without a storage-layout discipline, trading a size problem for a storage-collision problem.