---
eip: 5189
label: ERC-5189
title: Account Abstraction via Endorsed Operations
status: Draft
type: Standards Track
category: ERC
created: 2022-06-29
official: https://eips.ethereum.org/EIPS/eip-5189
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5189.md
canonical: https://eips.huatuo.xyz/zh/eip-5189/
lang: zh
tldr: "无需修改协议的账户抽象：钱包向公共 mempool 提交 Operation，每个钱包对应的\"endorser\"合约告诉 bundler 每个 Operation 是否会付费，以及它依赖哪些状态。"
tags: [account-abstraction, wallets, mempool, bundlers, erc]
---

# ERC-5189: Account Abstraction via Endorsed Operations

> An account abstraction proposal that avoids protocol changes while maintaining compatibility with existing smart contract wallets.

**TL;DR:** 无需修改协议的账户抽象：钱包向公共 mempool 提交 Operation，每个钱包对应的"endorser"合约告诉 bundler 每个 Operation 是否会付费，以及它依赖哪些状态。

## 它解决什么问题？

智能合约钱包需要有人，也就是 **bundler**，把它们的交易发送上链，并获得 gas 的补偿。难点在于拒绝服务攻击。bundler 如何在不运行整个 Operation、也不必在每次状态变化后重新运行的情况下，知道某个 Operation 真的会付费？

[ERC-4337](/eip-4337/) 用固定的 `UserOperation` 格式、共享的 EntryPoint，以及对 opcode 和存储的严格验证规则来回答这个问题。现有钱包必须采用这种模型。ERC-5189 走了另一条路。它的目标是**原样支持已经部署的钱包**，无需共识层变更，也不限制钱包代码能做什么。取而代之的是，每个钱包开发者提供一个合约，为自己钱包的 Operation 担保。

## 它如何运作

**Operation。** 发送到专用 mempool 的链下结构体。字段包括 `entrypoint` + `callData`（调用什么，通常是钱包本身）、`fixedGas` 和 `gasLimit`、类似 [EIP-1559](/eip-1559/) 的费用字段（`maxFeePerGas`、`priorityFeePerGas`）、带缩放系数以便用 ERC-20 付费的 `feeToken`、`chainId`，以及要咨询的 `endorser`。

**Endorser。** 由钱包开发者部署的合约。bundler 在链下**模拟**对它的调用，从不在链上调用它：

- `simulationSettings(op)` 返回模拟前要应用的代码和存储覆盖。
- `isOperationReady(op)` 返回 `readiness` 以及该 Operation 的**依赖项**。依赖项包括全局的（base fee、时间戳、区块号、`maxBlockNumber` 等）和按地址的（余额、代码、nonce、特定存储槽，或称为 `constraints` 的取值范围）。

如果 `readiness` 为 true，该 Operation 必须执行，并且至少要向 bundler 支付：

```
gasUnits  = fixedGas + min(gasUsed, gasLimit)
feePerGas = min(maxFeePerGas, baseFee + priorityFeePerGas)
repayment = gasUnits * feePerGas * feeScalingFactor / feeNormalizationFactor
```

bundler 只在某个依赖项变化时才重新检查 Operation。它在纳入之前，会在真实区块内进行最后一次模拟。如果 endorser 说"ready"，而 Operation 随后失败或支付不足，bundler 会**封禁该 endorser**，并丢弃它的所有 Operation。为了让丢弃 endorser 变得代价高昂，它们可以在 `EndorserRegistry` 中**销毁 ETH**，每个 mempool 运营者自行决定要求销毁多少。

对于 endorser 无法完全检查的代码路径，它可以触发 `UntrustedStarted` / `UntrustedEnded`。在该区间内，bundler 会自动把每一次状态访问记录为依赖项。

## 示例代码

规范中的注册表合约（略有精简）：

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

contract EndorserRegistry {
    event Burned(address indexed endorser, address indexed sender, uint256 added, uint256 total);
    mapping(address => uint256) public burn;

    function addBurn(address endorser) external payable returns (uint256 total) {
        total = burn[endorser] + msg.value;   // ETH is locked here forever
        burn[endorser] = total;
        emit Burned(endorser, msg.sender, msg.value, total);
    }
}
```

bundler 的准入检查（伪代码）：

```python
settings = endorser.simulationSettings(op)                     # eth_call
ready, glob, deps = simulate(endorser.isOperationReady, op, overrides=settings)
if ready and registry.burn(op.endorser) >= MIN_ENDORSER_BURN:
    mempool.add(op, watch=deps, valid_until=(glob.maxBlockNumber, glob.maxBlockTimestamp))
```

## 需要注意

- **状态：Draft。** 实际上，生态系统大多选择了 [ERC-4337](/eip-4337/)，而对于 EOA 则选择了 [EIP-7702](/eip-7702/)。
- 规范没有定义重放保护或钱包部署逻辑。这些仍由各个钱包及其 entrypoint 负责。
- 安全性取决于 bundler 自己的策略：最低销毁量、依赖项上限、重新评估次数上限和 endorser 封禁。规范建议了 `MAX_ENDORSER_GAS` 和 `MIN_ENDORSER_BURN` 之类的常量，但没有给出具体值。
- 一个 Operation 可能被执行多次，协议并不阻止这一点。重放保护由钱包负责，例如使用作为依赖项出现的 nonce。


---

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