EIPs Explained

ERC-1616 · Stagnant(停滞) · ERC · 2018-11-23

ERC-1616: Attribute Registry Standard

一个只有四个函数的只读接口,适用于为每个地址、每种类型分配一个规范的 uint256 属性值的注册表,使合约可以从单一可信来源检查诸如 KYC 状态之类的信息。

它解决什么问题?

合约有时需要了解某个地址的某些信息:它是否通过了 KYC,是否是合格投资者,是否在白名单中?早期的声明(claim)标准(ERC-735 和 ERC-780)允许多个发行者针对同一主题给同一个地址附加声明。验证者就必须决定信任哪些发行者,以及如何解决相互冲突的声明。

ERC-1616 把这一信任决策上移了一层。由经过策划的**属性注册表(Attribute Registry)**汇总它所信任的各种来源,并给出唯一的答案。验证者只需要信任注册表,而不必关心信息是如何获得的。

它如何运作

属性是每个账户一份扁平的 uint256 → uint256 键值存储,并有一条关键规则:每种属性类型在每个地址上恰好只有一个值(而不是每个发行者一个)。接口如下:

函数 行为
hasAttribute(account, typeId) 若已分配且当前有效则返回 true。绝不能 revert;外部调用的错误要被捕获并返回 false
getAttributeValue(account, typeId) 返回该值。如果 hasAttribute 会返回 false,则必须 revert
countAttributeTypes() 注册表定义的属性类型数量。不得 revert
getAttributeTypeID(index) 某个索引处的类型 ID;仅在超出范围时 revert

两个查询函数都必须是确定性的:使用相同参数的两次连续调用,无论调用者或 tx.origin 是谁,都返回相同的结果。注册表还必须支持 ERC-165,并报告接口 ID 0x5f46473f。

属性如何发放、撤销或过期,被有意排除在范围之外。高级注册表可以把布尔表达式编码进类型 ID,让值指向链下元数据,或者在不改变接口的情况下委托给其他注册表。

示例代码

一个只允许向持有某项属性的账户转账的代币:

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

interface IAttributeRegistry {
    function hasAttribute(address account, uint256 attributeTypeID) external view returns (bool);
    function getAttributeValue(address account, uint256 attributeTypeID) external view returns (uint256);
    function countAttributeTypes() external view returns (uint256);
    function getAttributeTypeID(uint256 index) external view returns (uint256);
}

contract GatedVault {
    IAttributeRegistry public immutable registry;
    uint256 public immutable requiredType; // e.g. an "approved investor" attribute ID

    constructor(IAttributeRegistry r, uint256 typeId) {
        registry = r;
        requiredType = typeId;
    }

    modifier onlyAttested(address who) {
        require(registry.hasAttribute(who, requiredType), "missing attribute");
        _;
    }

    function deposit() external payable onlyAttested(msg.sender) {
        // ...
    }
}

需要注意

  • 状态为 Stagnant。规范把 TPL(Transaction Permission Layer)合约指为该接口的一个更复杂的实现。
  • 把信任集中在注册表的策划者手中正是这一设计的本意:谁控制注册表,谁就控制谁能通过检查。
  • 由于 hasAttribute 不得 revert,调用其他合约的注册表必须包装这些调用,并在失败时返回 false。
  • 该标准除了值之外没有为属性添加任何元数据;命名方案留给可能出现的未来 EIP。一个相关的合规检查设计是 ERC-2009。

#identity #registry #attributes #compliance #stagnant

详细信息

作者
0age (@0age), Santiago Palladino (@spalladino), Leo Arias (@elopio), Alejo Salles (@fiiiu), Stephane Gosselin (@thegostep)
状态
Stagnant(停滞)
类型
Standards Track / ERC
创建日期
2018-11-23
依赖的提案

机器可读数据: Markdown · JSON