---
eip: 7779
label: ERC-7779
title: Interoperable Delegated Accounts
status: Draft
type: Standards Track
category: ERC
created: 2024-10-02
requires: 7201, 7702
official: https://eips.ethereum.org/EIPS/eip-7779
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7779.md
canonical: https://eips.huatuo.xyz/zh/eip-7779/
lang: zh
tldr: 草案接口：让 EIP-7702 委托的 EOA 报告自己使用了哪些存储区域，并可选地进行清理，使用户在切换钱包实现时不会发生存储冲突。
tags: [account-abstraction, eip-7702, wallets, storage, interoperability]
---

# ERC-7779: Interoperable Delegated Accounts

> Interface for delegated externally owned accounts to enable better redelegation between wallets.

**TL;DR:** 草案接口：让 EIP-7702 委托的 EOA 报告自己使用了哪些存储区域，并可选地进行清理，使用户在切换钱包实现时不会发生存储冲突。

## 它解决什么问题？

借助 [EIP-7702](/eip-7702/)，EOA 可以把自己的代码指向某个智能账户实现，获得批量交易、gas 代付等功能。然而账户的**存储**仍然属于该地址。如果用户从钱包 A 的实现迁移到钱包 B 的实现，B 的代码就会在 A 留在存储里的内容之上运行。

如果两者的布局有重叠，结果可能是账户被锁死、逻辑损坏，或者留下一个被故意隐藏的额外签名者。EOA 用户习惯在不同钱包之间自由迁移助记词；ERC-7779 试图为被委托的 EOA 保留这种自由。

## 它如何运作

两个接口：

**`IInteroperableDelegatedAccount`**（必需）

- `accountId()` 返回实现的自由格式名称，例如版本加钱包名称。新钱包可以显示"从钱包 A 迁移到钱包 B"。
- `accountStorageBases()` 返回该地址在它被委托过的所有实现中用过的每一个基础存储槽。
  - 基础槽必须用 `keccak256` 计算（采用 [ERC-7201](/eip-7201/) 风格的命名空间存储）。
  - 该列表是一个只追加的 `bytes32[]`，存放在 `keccak(keccak('InteroperableDelegatedAccount.ERC.Storage') - 1) & ~0xff`。每个新实现在初始化时追加自己的基础槽。
  - 使用外部存储合约的实现，返回重复作为前缀的 ERC 编号，后面跟着该合约的地址。

**`IRedelegableDelegatedAccount`**（可选）

- `onRedelegation()` 由所有者在切换实现之前调用。它应当在可行范围内尽可能清空账户的存储，并执行钱包特定的准备工作。

准备重新委托的钱包会读取存储基础槽，检查自己的基础槽是否冲突；如有冲突，则检查可疑的值，并且可以拒绝这次委托。

## 示例代码

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

interface IInteroperableDelegatedAccount {
    function accountId() external view returns (string memory);
    function accountStorageBases() external view returns (bytes32[] memory);
}

interface IRedelegableDelegatedAccount {
    function onRedelegation() external returns (bool);
}
```

钱包在重新委托之前检查某个地址（ethers v6）：

```ts
import { Contract, keccak256, toUtf8Bytes } from "ethers";

const acct = new Contract(eoa, [
  "function accountId() view returns (string)",
  "function accountStorageBases() view returns (bytes32[])",
], provider);

const myBase = keccak256(toUtf8Bytes("WalletB.Account.v1")); // whatever your impl uses
const [id, bases] = await Promise.all([acct.accountId(), acct.accountStorageBases()]);
if (bases.includes(myBase)) {
  console.warn(`Storage base already used by ${id}; inspect storage before delegating`);
}
```

## 需要注意

- 状态为 **Draft**。
- 协议无法强制合规。恶意实现可以谎报自己的存储基础槽，或把数据留在原处。规范建议确认账户运行的是已知且经过审计的实现，并在重要场合扫描存储。
- `onRedelegation()` 必须验证所有者身份，且不得重置重放保护（nonce），否则旧签名可能被重放。
- 清理之后，旧的初始化函数不能被其他任何人调用，否则攻击者可能重新初始化账户。
- 这种做法借鉴了 Diamond facet 存储检查（[ERC-2535](/eip-2535/)）等实践，适用于任何使用自定义存储槽的合约，而不仅仅是 7702 账户。


---

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