MODULE 1 OF 3DETECTIVE

ERC-2535 Diamond Standard: Multi-Facet Architectures

~1 MIN READAdvanced Proxy & Upgradeability Standards

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.

  1. Facet A: Voting & Delegation.
  2. Facet B: Treasury & Yield.
  3. Facet C: Metadata & URI.
  4. Task: List at least 3 function selectors that would belong to Facet B.
  5. Logic: Why is keeping "Facet C" separate from "Facet B" better for security?