ERC-2535: Breaking the 24KB Contract Limit
The Diamond Standard (ERC-2535) allows a single contract (the Diamond) to use multiple "Facets" (implementation contracts) to provide its functionality.
The Core Mechanism: delegatecall
The Diamond contract maintains a mapping of function selectors to Facet addresses. When a function is called, it performs a delegatecall to the appropriate Facet.
Key Advantages
- Infinite Modularity: No more 24KB code size limit.
- Granular Upgradeability: You can upgrade a single function (selector) without redeploying the entire contract.
- Shared Storage: All Facets read and write to the Diamond's storage.
Security Warning: Storage Collisions
Because all Facets share the same storage space, standard variable declarations (uint256 value;) are extremely dangerous. You must use Diamond Storage patterns.
🛠 Tactical Activity: Diamond Selector Mapping
Objective: Design a Facet distribution for a complex DAO.
- Facet A: Voting & Delegation.
- Facet B: Treasury & Yield.
- Facet C: Metadata & URI.
- Task: List at least 3 function selectors that would belong to Facet B.
- Logic: Why is keeping "Facet C" separate from "Facet B" better for security?