---
eip: 2535
label: ERC-2535
title: Diamonds, Multi-Facet Proxy
status: Final
type: Standards Track
category: ERC
created: 2020-02-22
official: https://eips.ethereum.org/EIPS/eip-2535
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2535.md
canonical: https://eips.huatuo.xyz/eip-2535/
lang: en
tldr: "The Diamond standard: one proxy contract that routes each function selector to a different implementation contract (facet), giving a single address with no size limit and fine-grained upgrades."
tags: [proxy, upgradeability, diamond, solidity, architecture]
---

# ERC-2535: Diamonds, Multi-Facet Proxy

> Create modular smart contract systems that can be extended after deployment.

**TL;DR:** The Diamond standard: one proxy contract that routes each function selector to a different implementation contract (facet), giving a single address with no size limit and fine-grained upgrades.

## What problem does it solve?

A contract's deployed code is capped at 24 KB, and a normal contract cannot be changed after deployment. Large systems end up split across many addresses, and classic proxies can swap the whole implementation at once but nothing finer.

A **diamond** is a single contract address whose external functions are supplied by many separate contracts called **facets**. Functions can be added, replaced or removed individually, there is no practical size limit, and users always interact with the same address. A diamond can also be made immutable later.

## How it works

- The diamond stores a mapping from **function selector → facet address**.
- Any call that is not defined directly in the diamond hits its `fallback`, which looks up the facet for `msg.sig` and runs it with `delegatecall`. The facet's code runs against the **diamond's storage**, and `msg.sender` / `msg.value` are unchanged.
- **`diamondCut`** (interface `IDiamondCut`) changes the mapping. Each `FacetCut` names a facet, an action (`Add`, `Replace`, `Remove`) and a list of selectors. Adding an existing selector, replacing with the same facet, or removing an unset selector all revert. Optionally `_init` / `_calldata` is run via `delegatecall` afterwards for initialization.
- A **`DiamondCut` event** must be emitted for every change, including immutable functions at deployment, so the full upgrade history is on-chain.
- **Loupe functions** (`IDiamondLoupe`) let tools inspect the diamond: `facets()`, `facetFunctionSelectors(facet)`, `facetAddresses()`, `facetAddress(selector)`.
- Facets share state by agreeing on storage layout. The standard does not mandate one, but points to patterns such as Diamond Storage and AppStorage.
- Supporting [ERC-165](/eip-165/) `supportsInterface` is optional.

## Sample code

The fallback router at the heart of a diamond (simplified):

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract MiniDiamond {
    mapping(bytes4 => address) internal selectorToFacet;

    fallback() external payable {
        address facet = selectorToFacet[msg.sig];
        require(facet != address(0), "Diamond: function does not exist");
        assembly {
            calldatacopy(0, 0, calldatasize())
            let ok := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch ok
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }
}
```

Listing a diamond's facets with ethers v6:

```ts
import { Contract, JsonRpcProvider } from "ethers";

const loupe = new Contract(
  diamondAddress,
  ["function facets() view returns (tuple(address facetAddress, bytes4[] functionSelectors)[])"],
  new JsonRpcProvider(process.env.RPC_URL),
);
for (const f of await loupe.facets()) {
  console.log(f.facetAddress, f.functionSelectors.length, "selectors");
}
```

## Things to know

- **Access control is your job.** `diamondCut` can run arbitrary code against the diamond's storage; whoever controls it controls everything. The standard does not define ownership.
- **Storage collisions** between facets are the main source of bugs. Use a disciplined layout pattern and never reorder shared structs.
- Avoid `selfdestruct` in facets.
- Block explorers cannot show a diamond's ABI from source alone; tools rely on the loupe functions and `DiamondCut` events.
- It builds on the withdrawn [ERC-1538](/eip-1538/). For simpler single-implementation upgrades, a standard proxy using the [ERC-1967](/eip-1967/) storage slots is often enough.
- The spec links a reference implementation; start from an audited implementation rather than the sketch above.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2535
