# EIP-2535 Diamond Multi-Facet Proxies & Storage Security

> Audit EIP-2535 Diamond multi-facet proxies: 4-byte msg.sig -> facetAddress routing, DiamondStorage structs, arbitrary init delegatecall drains, and Loupe.

Canonical: https://nftvenueledger.com/protocols/eip-2535-diamond-multi-facet-delegatecall-selector-clashes
Last updated: 2026-11-16T15:13:41.123Z

**Publication:** NFTVenue Ledger
**Category:** Erc721 Erc1155 Eip712 Permit Security
**Published:** 2026-11-13T22:20:25.915Z
**Author:** Dr. Devon Kurosawa, PhD (PhD in Distributed Systems & Cryptographic Protocol Verification)
**Reviewer:** Not recorded

## Answer-first summary

EIP-2535 Diamonds bypass Ethereum 24 KB contract size limits by routing 4-byte function selectors across modular Facet contracts—demanding strict storage and diamondCut discipline.

## Key takeaways

- EIP-2535 Diamonds route 4-byte msg.sig selectors across unlimited <=24 KB Facet contracts via DELEGATECALL while presenting a single unified protocol address.
- Because every Facet shares the Diamond address(this) execution context, one unvalidated arbitrary external call in any minor periphery Facet can drain all user ERC-20 approvals granted to the Diamond.
- Facets must declare zero root-level Solidity state variables (and avoid inheriting stateful Slot-0 base contracts), storing all state inside collision-free EIP-7201 / DiamondStorage structs.
- Reentrancy guards across multiple Facets fail completely unless every Facet reads and writes the exact same shared global lock slot (ideally via EIP-1153 TSTORE).

## Related financial entities

- **Checks-Effects-Interactions (CEI) Security Pattern** (CEI-SEC) — product: Foundational programming design pattern in smart contract development preventing reentrancy attacks by executing internal state updates before external calls.
- **Uniswap v4 Singleton & Hook Architecture** (UNI-V4) — product: Fourth-generation decentralized exchange protocol featuring a unified singleton contract and modular hooks that customize pool execution logic.

## Analysis

Under **EIP-170**, Ethereum consensus rejects deploying any smart contract whose runtime bytecode exceeds **`24,576 bytes` (`24 KB`)**. Complex cross-chain aggregators, perpetual engines, and modular NFT platforms quickly hit this ceiling when attempting to fit swap routers, bridge adapters, governance, and staking into a singleERC-1967 UUPS implementation. Standardized by Nick Mudge in **EIP-2535 (`Diamonds, Multi-Facet Proxy`)**, a single Diamond proxy contract exposes a unified external address while routing each incoming 4-byte function selector `msg.sig` via `selectorToFacetAndPosition[msg.sig]` to an unlimited fleet of specialized **Facet** implementation contracts via `DELEGATECALL`!

Anchored inside our [EIP-712, Permit2 & proxy security master guide](/protocols/eip712-permit2-erc721-royalty-proxy-timelock-security-2026), Diamonds demand extraordinary audit rigor: **over $11M+ in bridge/aggregator exploits (`most infamously the Li.Fi arbitrary calldata facet bug`)** stemmed from a single unvalidated Facet sharing `address(this)` ERC-20 token approvals with the entire Diamond!

## Shared Approval Blast Radius: Why 1 Bad Facet Compromises ALL Facets!

In a modular microservice backend, Service A cannot read Service B's database credentials; **inside an EIP-2535 Diamond, EVERY Facet executes `DELEGATECALL` inside the exact same `address(this)` EVM context**!

Consider what happened when an aggregator Diamond added a new `GasZipFacet` containing an unvalidated external `address.call(arbitraryCalldata)` helper:
1. Hundreds of thousands of users had previously granted `USDC.approve(DiamondAddress, MAX)` for legitimate swaps on `UniswapFacet`.
2. Attackers called `Diamond.depositToGasZip(...)`, which `DELEGATECALL`ed into the flawed Facet and executed `USDC.transferFrom(victim, attacker, balance)` **wearing `msg.sender == DiamondAddress`**—draining millions from pre-approved wallets in minutes!
3. **Golden Diamond Audit Rule**: Never hold lingering user ERC-20 approvals on a multi-facet Diamond! Isolate user token pulls inside an external immutable [Permit2 Witness](/protocols/uniswap-permit2-allowance-transfer-witness-phishing-audits) or [Seaport Conduit](/protocols/seaport-order-conduit-zones-bulk-merkle-cancellation-trees) helper!

![EIP-2535 Diamond msg.sig fallback selector lookup, DiamondStorage isolation, and diamondCut upgrade flow](/api/figure?type=flow&title=EIP-2535%20Diamond%20Selector%20Dispatch%20%26%20Storage%20Map&subtitle=4-byte%20selector%20routing%20across%20modular%20Facets%20sharing%20isolated%20keccak256%20DiamondStorage%20structs&steps=1.%20Fallback%20Lookup%3A%3ARead%20facet%20%3D%20ds.selectorToFacet%5Bmsg.sig%5D%20%28reverts%20if%200x0%29%7C2.%20Facet%20Delegatecall%3A%3AExecute%20Facet%20bytecode%20against%20Diamond%20storage%20%26%20approvals%7C3.%20DiamondStorage%3A%3AEach%20Facet%20reads%20ONLY%20its%20hashed%20struct%20slot%20%280%20state%20vars!%29%7C4.%20Timelocked%20Cut%3A%3AdiamondCut%28Add%2FReplace%2FRemove%29%20blocks%20selector%20clashes!&metrics=EIP-170%20BYPASS%3A%3AUnlimited%20KB%3A%3AEach%20Facet%20%3C%3D%2024%20KB%3B%20total%20unbounded%7CDISPATCH%20OVERHEAD%3A%3A~2%2C650%20Gas%3A%3A1%20mapping%20SLOAD%20%2B%20DELEGATECALL%7CINTROSPECTION%3A%3AIDiamondLoupe%3A%3Afacets%28%29%20%26%20facetAddress%28bytes4%29%20views%7CSELECTOR%20CLASH%3A%3AAuto-Reverted%3A%3AFacetCutAction.Add%20blocks%20duplicates!)

## Three Fatal EIP-2535 Storage & Upgrade Pitfalls

When auditing Diamond codebases across multi-chain DEX routers and gaming protocols in our [marketplaces directory](/marketplaces) (comparing modular Diamond routers against singleton designs like the [Uniswap v4 singleton](/tokens/uniswap-v4-singleton-architecture) or [Astroport](/marketplaces/astroport)), auditors run automated AST checks against three classic Diamond traps:

1. **Accidental Contract-Level State Variables in a Facet**: If `SwapFacet.sol` declares `uint256 public feeBps;` at contract root (Slot `0`) instead of inside a hashed `LibSwapStorage.Layout` struct, it overwrites Slot `0` across **every other Facet** that made the same mistake! Every Facet must contain **zero top-level mutable state variables** (enforcing [EIP-7201 namespaced storage](/protocols/eip-7201-namespaced-storage-layout-audit-upgrade-safety)).
2. **Appending vs Reordering Inside Shared `AppStorage`**: Reordering or inserting fields mid-struct inside a shared `DiamondStorage` struct shifts every subsequent field offset across live Facets.
3. **Unchecked `_init.delegatecall(_calldata)` in `diamondCut`**: `IDiamondCut.diamondCut(FacetCut _diamondCut, address _init, bytes _calldata)` executes an arbitrary `DELEGATECALL` to `_init` for state migrations—meaning `diamondCut` holds total root control and **must** sit behind a multi-day timelock!

## Architecture Comparison: UUPS Proxy vs EIP-2535 Diamond vs Singleton + Hooks

| Architecture | Max Logic Size | Upgrade Granularity | User Approval Isolation | Etherscan / Loupe Readability |
| :--- | :--- | :--- | :--- | :--- |
| [ERC-1967 UUPS Proxy](/protocols/erc-1967-transparent-vs-eip-1822-uups-proxy-storage-slots) | Hard **24.576 KB** cap | All-or-nothing full contract swap | Shared on single proxy | Native Etherscan Proxy UI |
| **EIP-2535 Diamond** | **Unlimited** (`N * 24 KB`) | Surgical per-selector `Add/Replace/Remove` | **Dangerous** if users approve Diamond! | Requires **`IDiamondLoupe`** support |
| Router + External Modules | Unlimited (`CALL`, not `DELEGATECALL`) | Swap external module pointer | High if modules lack token access | Explicit multi-contract call graph |
| [Uniswap v4 Singleton](/tokens/uniswap-v4-singleton-architecture) + Hooks | Core <24 KB + unlimited Hooks | Immutable Core + Opt-in per-pool Hooks | Isolated via `unlock` delta checks | Deterministic immutable core |

![Audit severity distribution in EIP-2535 Diamond protocols across arbitrary external calls, storage drift, and guards](/api/figure?type=bars&title=EIP-2535%20Diamond%20Exploit%20%26%20Audit%20Finding%20Taxonomy&subtitle=Share%20of%20critical%2Fhigh%20vulnerabilities%20identified%20in%20production%20multi-facet%20Diamond%20audits&steps=Arbitrary%20Call%20%2B%20Shared%20Approve%3A%3A48%25%20of%20critical%20drains%20%28Li.Fi%20pattern%20on%20unisolated%20Facet%29%7CBroken%20Cross-Facet%20Reentrancy%3A%3A24%25%20of%20bugs%20%28Facet%20A%20lock%20invisible%20to%20Facet%20B%20guard!%29%7CRoot-Slot%20Variable%20Declaration%3A%3A17%25%20of%20bugs%20%28Facet%20inherits%20OZ%20contract%20with%20Slot%200%20state%29%7COrphaned%20Selector%20After%20Upgrade%3A%3A11%25%20of%20bugs%20%28Replace%20forgets%20to%20Remove%20deprecated%20selector%29&metrics=REENTRANCY%20RULE%3A%3AShared%20Slot%20%2F%20TSTORE%3A%3AAll%20Facets%20MUST%20share%201%20lock%20slot!%7CLOUPE%20FUNCTIONS%3A%3A4%20View%20Getters%3A%3AMandatory%20on-chain%20transparency%7CFREEZE%20DIAMOND%3A%3ARemove%20diamondCut%3A%3AMakes%20any%20Facet%20or%20whole%20Diamond%20immutable%7CCOLLISION%20GUARD%3A%3AAction.Add%20!%3D%200x0%3A%3ALibDiamond%20rejects%20existing%20bytes4)

## Cross-Facet Reentrancy Guard Trap & Selector Collision Math

Watch out for the **Cross-Facet Reentrancy Trap** violating the [CEI security pattern](/tokens/cei-smart-contract-security-pattern): if `LendingFacet` uses its own private reentrancy boolean at `keccak256("lending.lock")` while `CollateralFacet` uses `keccak256("collateral.lock")`, an attacker reentering `CollateralFacet.withdraw` during `LendingFacet.borrow` **bypasses both `nonReentrant` modifiers**! All Facets in a Diamond must share **one unified EIP-1153 transient lock slot** (`or single DiamondStorage lock`):

```formula
1) 4-Byte Selector Birthday-Paradox Clash Probability Across M Functions:
 Space Size S = 2^32 = 4,294,967,296 selectors
 Prob_Accidental_Clash(M) approx 1 - exp( - M * (M - 1) / (2 * 2^32) )
 For a massive 400-selector Diamond: Prob_Clash = 1 - exp(-159,600 / 8.5899e9) = 0.00186% (Caught deterministically by LibDiamond Action.Add!)
 WARNING: An adversarial Facet author CAN mine a deliberate 4-byte collision in <4 seconds on 1 GPU (~2^31 hashes)!

2) Unified Cross-Facet Transient Reentrancy Guard Invariant (Cancun EIP-1153):
 bytes32 constant DIAMOND_REENTRANCY_SLOT = keccak256("diamond.global.reentrancy.lock");
 modifier globalNonReentrant {
 assembly { if tload(DIAMOND_REENTRANCY_SLOT) { revert(0, 0) } tstore(DIAMOND_REENTRANCY_SLOT, 1) }
 _;
 assembly { tstore(DIAMOND_REENTRANCY_SLOT, 0) }
 }
```

## Making Diamonds Immutable or Timelocked

A unique superpower of EIP-2535 is **progressive ossification**: once core Facets mature, governance can pass `FacetCutAction.Remove` on `IDiamondCut.diamondCut.selector` itself (making the entire Diamond permanently immutable!) or lock `diamondCut` behind a 7-day timelock—inspect quorum and emergency veto mechanics next in [TimelockController multisig & guardian vetoes](/protocols/timelockcontroller-multisig-quorum-emergency-guardian-veto) inside our [EIP-712, Permit2 & Proxy Security hub](/topics/erc721-erc1155-eip712-permit-security).

## Frequently asked questions

### How did the 2024 Li.Fi Diamond exploit drain user wallets without stealing private keys?

Users had granted infinite ERC-20 approvals directly to the main Diamond address; a newly added periphery Facet lacked calldata validation on an external call, allowing attackers to invoke token.transferFrom wearing the Diamond identity.

### Why does inheriting standard OpenZeppelin ReentrancyGuard inside two Diamond Facets fail?

Legacy Slot-based ReentrancyGuard or per-facet storage structs create separate _status slots, allowing cross-function reentrancy from Facet A into Facet B unless both Facets point to one shared global lock slot.

### What is IDiamondLoupe and why is it mandatory in EIP-2535?

Because Etherscan cannot read a single implementation slot on a multi-facet proxy, IDiamondLoupe exposes four standard on-chain view functions (facets, facetFunctionSelectors, facetAddresses, facetAddress) to audit every active selector.

### Can an EIP-2535 Diamond ever be made permanently non-upgradeable?

Yes. Executing a final diamondCut that removes the 4-byte selector for diamondCut itself permanently deletes all upgrade capability while keeping every active Facet running.


## Source URLs

- https://eips.ethereum.org/EIPS/eip-2535
- https://eips.ethereum.org/EIPS/eip-170
- https://eips.ethereum.org/EIPS/eip-1153

## Citation

- APA: Dr. Devon Kurosawa, PhD. (2026). EIP-2535 Diamond Multi-Facet Proxies: Selector Routing, DiamondStorage & Arbitrary Delegatecall. NFTVenue Ledger. https://nftvenueledger.com/protocols/eip-2535-diamond-multi-facet-delegatecall-selector-clashes
- Canonical article: [EIP-2535 Diamond Multi-Facet Proxies: Selector Routing, DiamondStorage & Arbitrary Delegatecall](https://nftvenueledger.com/protocols/eip-2535-diamond-multi-facet-delegatecall-selector-clashes)
- Site research index: [NFTVenue Ledger](https://nftvenueledger.com/llms-full.txt)
