---
eip: 7582
label: ERC-7582
title: Modular Accounts with Delegated Validation
status: Draft
type: Standards Track
category: ERC
created: 2023-12-25
requires: 4337
official: https://eips.ethereum.org/EIPS/eip-7582
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7582.md
canonical: https://eips.huatuo.xyz/zh/eip-7582/
lang: zh
tldr: 为 ERC-4337 智能账户添加插件的一种草案性的最小化方法：UserOperation 的 nonce 高 192 位的 key 指定一个 validator 合约，账户把该操作的验证交给它。
tags: [account-abstraction, erc4337, smart-accounts, plugins, modular]
---

# ERC-7582: Modular Accounts with Delegated Validation

> Extends ERC-4337 interface with nonce-based plugins

**TL;DR:** 为 ERC-4337 智能账户添加插件的一种草案性的最小化方法：UserOperation 的 nonce 高 192 位的 key 指定一个 validator 合约，账户把该操作的验证交给它。

## 它解决什么问题？

智能合约账户原则上可以实现社交恢复、支出限额、会话密钥、定时支付等等。但在实践中，每项功能都需要自定义的验证逻辑，添加它通常意味着升级或迁移账户。虽然存在更大的模块化账户标准，但它们会增加许多新函数和约定。

ERC-7582（"Modular Accounts with Delegated Validation"，MADV）采取了相反的思路。它完全不添加新函数。它展示了一个已经实现 [ERC-4337](/eip-4337/) `IAccount` 接口的账户，如何只使用 ERC-4337 已有的字段，把验证委托给插件合约。

## 它如何运作

ERC-4337 的 EntryPoint 把 nonce 跟踪为 192 位的 **key** 加 64 位的 **sequence**。每个 key 有自己的计数器，因此 key 不同的操作互不阻塞。MADV 把这个 key 复用为指针：

1. 用户构建一个 `nonce` 的 key 非零（即 nonce 大于 `type(uint64).max`）的 UserOperation。
2. 在 `validateUserOp` 中，账户从 key 中提取一个 validator 标识符。它可以直接就是 validator 的地址，也可以是指向存储中某个地址的指针；由账户决定。
3. 账户把 UserOperation（最好是整个）转发给该 validator。
4. validator 返回标准的 ERC-4337 `validationData`，账户原样将其返回给 EntryPoint。
5. key 为 0 的 nonce 会退回到账户正常的签名检查。

为什么用 nonce 而不是 `signature` 字段？它不需要额外的 calldata，`getNonce(sender, key)` 已经为每个插件提供了独立的重放计数器，而且 `UserOperationEvent` 会记录 nonce，因此可以通过现有事件追踪插件的使用。

## 示例代码

一个简化的 MADV 账户（参考实现还会先检查所有者的签名）：

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

import {IAccount} from "account-abstraction/interfaces/IAccount.sol";
import {PackedUserOperation} from "account-abstraction/interfaces/PackedUserOperation.sol";

contract MADVAccount is IAccount {
    address public immutable entryPoint;

    constructor(address ep) { entryPoint = ep; }

    function validateUserOp(
        PackedUserOperation calldata userOp,
        bytes32 userOpHash,
        uint256 missingAccountFunds
    ) external returns (uint256 validationData) {
        require(msg.sender == entryPoint, "not EntryPoint");

        if (userOp.nonce > type(uint64).max) {
            uint192 key = uint192(userOp.nonce >> 64);
            address validator = address(uint160(key));   // key encodes the plugin
            // (a real account should check `validator` is installed/allowed)
            validationData = IAccount(validator).validateUserOp(userOp, userOpHash, missingAccountFunds);
        } else {
            validationData = _validateOwnerSignature(userOp, userOpHash);
        }

        if (missingAccountFunds > 0) {
            (bool ok, ) = payable(msg.sender).call{value: missingAccountFunds}("");
            (ok);
        }
    }

    function _validateOwnerSignature(PackedUserOperation calldata, bytes32)
        internal view virtual returns (uint256) { /* ECDSA check */ return 0; }
}
```

在链下，某个插件的下一个 nonce 是 `entryPoint.getNonce(account, BigInt(validatorAddress))`。

## 需要注意

- 状态：**Draft**。
- 规范把标识符到 validator 的映射以及任何允许列表都留给账户开发者。盲目信任 key 中任何地址的账户，会让任何人都能为其操作选择 validator，因此要限制可使用的 validator。
- validator 在 ERC-4337 的验证阶段内运行，必须遵守其规则（存储访问和 opcode 限制），否则 bundler 会丢弃该操作。
- 如需带有安装、钩子和执行模块的更丰富的模块系统，请参见 [ERC-7579](/eip-7579/) 和 [ERC-6900](/eip-6900/)。


---

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