Alert Source Discuss
⚠️ Draft Standards Track: ERC

ERC-7410: ERC-20 更新 Spender 的授权额度

扩展 ERC-20,允许 spender 撤销和减少授权额度

Authors Mohammad Zakeri Rad (@zakrad), Adam Boudjemaa (@aboudjem), Mohamad Hammoud (@mohamadhammoud)
Created 2023-07-26
Discussion Link https://ethereum-magicians.org/t/eip-7410-decrease-allowance-by-spender/15222
Requires EIP-20, EIP-165

摘要

此扩展添加了一个 decreaseAllowanceBySpender 函数来减少 ERC-20 授权额度,其中 spender 可以撤销或减少特定地址的给定授权额度。此 ERC 扩展了 ERC-20

动机

目前,ERC-20 代币提供授权额度,使代币所有者能够授权 spender 代表他们使用指定数量的代币。但是,减少授权额度的过程仅限于所有者一方,如果代币所有者是国库钱包或多重签名钱包,并且已向 spender 授予了过多的授权额度,则可能会出现问题。在这种情况下,从所有者的角度减少授权额度可能既费时又具有挑战性。

为了解决这个问题并加强安全措施,此 ERC 建议允许 spender 从他们的一端减少或撤销授予的授权额度。如果未来发生潜在的黑客攻击,此功能将提供额外的安全保障。它还消除了为了减少代币所有者一方的授权额度而达成共识或执行复杂程序的需求。

规范

本文档中的关键词“必须”、“禁止”、“必需”、“应该”、“不应该”、“推荐”、“可以”和“可选”应按照 RFC 2119 中的描述进行解释。

使用此 ERC 的合约必须实现 IERC7410 接口。

接口实现

pragma solidity ^0.8.0;

/**
 * @title IERC-7410 Update Allowance By Spender Extension
 * Note: the ERC-165 identifier for this interface is 0x12860fba
 */
interface IERC7410 is IERC20 {

    /**
     * @notice Decreases any allowance by `owner` address for caller.
     * 减少调用者对 `owner` 地址的任何授权额度。
     * Emits an {IERC20-Approval} event.
     * 发出 {IERC20-Approval} 事件。
     *
     * Requirements:
     * 要求:
     * - when `subtractedValue` is equal or higher than current allowance of spender the new allowance is set to 0.
     *   当 `subtractedValue` 等于或高于 spender 当前的授权额度时,新的授权额度设置为 0。
     * Nullification also MUST be reflected for current allowance being type(uint256).max.
     * 对于当前授权额度为 type(uint256).max 的情况,也必须反映出无效化。
     */
    function decreaseAllowanceBySpender(address owner, uint256 subtractedValue) external;

}

decreaseAllowanceBySpender(address owner, uint256 subtractedValue) 函数必须是 publicexternal

当调用 decreaseAllowanceBySpender 时,必须发出 Approval 事件。

当使用 0x12860fba 调用时,supportsInterface 方法必须返回 true

理由

此 ERC 中的技术设计选择受以下因素驱动:

  • decreaseAllowanceBySpender 函数的引入通过允许 spender 自主撤销或减少授权额度来增强 spender 的能力。此设计选择符合为 spender 提供对其授权级别更多直接控制权的目标。
  • 要求 subtractedValue 低于当前授权额度可确保安全实施。此外,当 subtractedValue 等于或超过当前授权额度时,通过将新的授权额度设置为 0 来实现无效化。这种方法增加了一层额外的安全性,并简化了减少授权额度的过程。
  • 维持与 ERC-20 的授权相似的命名模式的决定,其根源在于为熟悉 ERC-20 标准的开发人员提升一致性和易于理解性。

向后兼容性

此标准与 ERC-20 兼容。

参考实现

此处 包含了一个最小实现。

安全考虑

此 ERC 的用户必须彻底考虑他们从 owner 的授权额度中减少的代币数量。

版权

通过 CC0 放弃版权和相关权利。

Citation

Please cite this document as:

Mohammad Zakeri Rad (@zakrad), Adam Boudjemaa (@aboudjem), Mohamad Hammoud (@mohamadhammoud), "ERC-7410: ERC-20 更新 Spender 的授权额度 [DRAFT]," Ethereum Improvement Proposals, no. 7410, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7410.