---
eip: 8110
label: ERC-8110
title: Domain Architecture for Diamonds
status: Draft
type: Standards Track
category: ERC
created: 2025-12-20
requires: 2535, 8042
official: https://eips.ethereum.org/EIPS/eip-8110
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8110.md
canonical: https://eips.huatuo.xyz/zh/eip-8110/
lang: zh
tldr: 一种面向 Diamond 合约的草案约定，按业务领域对存储分组，并为 ERC-8042 存储标识符、版本管理和子领域制定固定的命名方案，以减少存储冲突和升级失误。
tags: [diamond, storage, upgradeability, architecture, solidity]
---

# ERC-8110: Domain Architecture for Diamonds

> An architectural pattern that organizes Diamond storage by domain using ERC-8042 identifiers.

**TL;DR:** 一种面向 Diamond 合约的草案约定，按业务领域对存储分组，并为 ERC-8042 存储标识符、版本管理和子领域制定固定的命名方案，以减少存储冲突和升级失误。

## 它解决什么问题？

Diamond（[ERC-2535](/eip-2535/)）是一个代理，把函数选择器路由到许多逻辑合约（"facet"）。所有 facet 共享 Diamond 的存储，因此每一块状态都位于一个经过哈希的位置，例如 `keccak256("my.project.storage")`。[ERC-8042](/eip-8042/) 为这些位置标准化了人类可读的标识符，但没有规定如何选择或组织它们。

在大型项目中，这会导致漂移：团队把存储绑定到 facet、重用或写错标识符，并在升级时破坏布局，使某个 facet 悄悄损坏另一个 facet 的状态。ERC-8110 是一项纯粹的约定，不引入新接口，它的主张是：**存储属于领域，而不是 facet**。

## 它如何运作

- **领域（Domain）** = 一个职责范围（例如 `character`、`equipment`、`gamesettings`）。每个领域恰好有一个存储 struct 和一个标识符。多个 facet 可以读写同一个领域。
- **标识符格式**：最少为 `{project}.{domain-name}.{version}`；扩展形式为 `{org}.{project}.{domain-type}.{domain-name}.{version}`，其中 `domain-type` 是 `diamond`、`system` 或 `business`。省略版本表示 `v1`。
- **仅追加**：新字段加在 struct 末尾。破坏布局的变更（例如重塑嵌套 struct）需要新的版本标识符（`v2` 等）以及由项目自行处理的明确迁移。
- **子领域（Sub-domain）**：若要在不改动领域 struct 的情况下为其添加状态，可定义 `{…}.{version}.{sub-domain}`，并配以独立的 struct 和标识符。
- **注解**：每个领域 struct 必须带有 `@custom:storage-location erc8042:<id>`，以便工具找到它。
- **目录**应与领域对应（`contracts/character/storage/…`、`contracts/character/facets/…`）。

升级按其对存储的影响分类：没有新状态（只需添加选择器）、新领域（横向扩展）、现有领域中的新字段（追加或子领域），或布局破坏（新版本）。

## 示例代码

遵循规范命名的业务领域加子领域：

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

/// @custom:storage-location erc8042:acme.game.business.character.v1
bytes32 constant CHARACTER_STORAGE_POSITION = keccak256("acme.game.business.character.v1");

struct Character { uint32 level; uint256 hp; }
struct CharacterStorage { mapping(uint256 => Character) characters; }

function characterStorage() pure returns (CharacterStorage storage s) {
    bytes32 position = CHARACTER_STORAGE_POSITION;
    assembly { s.slot := position }
}

/// Sub-domain: new state isolated from the original struct
/// @custom:storage-location erc8042:acme.game.business.character.v1.mounted
bytes32 constant CHARACTER_MOUNTED_POSITION = keccak256("acme.game.business.character.v1.mounted");

struct CharacterMountedStorage { bool isMounted; }

function characterMountedStorage() pure returns (CharacterMountedStorage storage s) {
    bytes32 position = CHARACTER_MOUNTED_POSITION;
    assembly { s.slot := position }
}

// Any facet can use the domain helpers
contract CharacterFacet {
    function levelUp(uint256 id) external {
        characterStorage().characters[id].level += 1;
    }
}
```

## 需要注意

- **状态：Draft。** 命名规则仍可能变化。
- 它不改变 Diamond 执行模型中的任何内容，也不增加链上接口；它与现有的 ERC-2535 和 ERC-8042 系统兼容，可以逐步采用。共享库中已有的标识符应保持不动。
- 在向领域追加字段和添加子领域之间做选择，是团队的权衡：追加能让相关内容聚在一起，但需要对布局保持纪律；子领域则能隔离风险。
- 在线上系统中采用它时，标识符的唯一性是主要隐患：新标识符不得与现有标识符冲突。
- 对于非 Diamond 的可升级合约，类似的命名空间存储约定是 [ERC-7201](/eip-7201/)。


---

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