---
eip: 2997
label: EIP-2997
title: IMPERSONATECALL Opcode
status: Stagnant
type: Standards Track
category: Core
created: 2020-09-24
official: https://eips.ethereum.org/EIPS/eip-2997
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2997.md
canonical: https://eips.huatuo.xyz/zh/eip-2997/
lang: zh
tldr: 提议新增 IMPERSONATECALL 操作码，让合约以派生子地址（由自身地址加 salt 得出）的身份发起调用，从而无需为每个用户部署合约即可实现多用户钱包。
tags: [opcode, wallet, meta-transactions, account-abstraction, core]
---

# EIP-2997: IMPERSONATECALL Opcode

> Add a new opcode, IMPERSONATECALL at 0xf6, which is similar in idea to CALL (0xF1), except that it impersonates a sender, i.e. the callee sees a sender different from the real caller. The impersonated sender address is derived from the real caller address and a salt.

**TL;DR:** 提议新增 IMPERSONATECALL 操作码，让合约以派生子地址（由自身地址加 salt 得出）的身份发起调用，从而无需为每个用户部署合约即可实现多用户钱包。

## 它解决什么问题？

为每个用户提供非托管智能钱包的服务，通常依赖反事实部署（counterfactual deployment）：每个用户有一个可预测的 [CREATE2](/eip-1014/) 地址，钱包合约只在需要时才部署。但一旦用户想要转出 ETH 或代币，赞助方就必须支付部署该用户合约（或代理）的费用，作者估计每个用户至少需要 42,000 gas。

EIP-2997 提议一种**多用户钱包**：一个直接控制许多用户地址的合约，用 [EIP-712](/eip-712/) 签名消息授权操作，无需为每个用户单独部署。它还能在保留普通以太坊地址的同时，批量处理许多用户的转账。

## 它如何运作

新操作码 `IMPERSONATECALL`（`0xf6`）的行为类似 `CALL`，但被调用方看到的是**另一个发送者**：由真实调用者和 salt 派生出的地址。

操作数（7 个）：`gas`、`to`、`in_offset`、`in_size`、`ret_offset`、`ret_size`、`salt`。

被模拟的发送者为：

```
sender = keccak256(0xff ++ caller ++ salt ++ zeros32)[12:]
```

- `caller` 是执行该操作码的合约的 20 字节地址；`salt` 为 32 字节；`zeros32` 是 32 个零字节。
- 这沿用了 CREATE2 的派生方式，但末尾的零字节使其处于与真实合约不同的地址空间。

在调用中：

- `CALLER` 返回被模拟的地址。
- 如果 value 非零，ETH 取自**被模拟账户的余额**，因此钱包可以转移发送到用户派生地址的资金。
- Gas 的收取与 `CALL` 完全相同。
- 被模拟的账户"内部"不会运行任何代码；即使该处恰好存在合约，其代码也不会被执行。

## 示例代码

按规范公式，在链下派生用户的模拟地址（ethers v6）：

```ts
import { keccak256, concat, getAddress, ZeroHash } from "ethers";

function impersonatedAddress(wallet: string, salt: string): string {
  const hash = keccak256(concat(["0xff", wallet, salt, ZeroHash]));
  return getAddress("0x" + hash.slice(-40));
}

// Spec test vector: caller = 0x00..00, salt = 0x00..00
console.log(impersonatedAddress("0x0000000000000000000000000000000000000000", ZeroHash));
// expected per spec: 0xFFC4F52F884A02BCD5716744CD622127366F2EDF (checksummed)
```

多用户钱包在验证用户的 EIP-712 签名后，会执行 `IMPERSONATECALL(gas, token, ..., salt = userId)`，这样代币看到的 `msg.sender` 就是用户自己的地址。

## 需要注意

- 状态为 **Stagnant**。该操作码从未被加入以太坊。
- 派生地址完全由钱包合约的代码控制。用户必须信任这段代码，因为它做的任何事情都可能转移他们的资金。
- 让账户具有可编程行为的相关想法包括 [EIP-2803](/eip-2803/)（富交易）、[ERC-4337](/eip-4337/) 智能账户，以及 [EIP-7702](/eip-7702/)，后者是以太坊实际为 EOA 推出的路径。
- 规范指出，与真实合约或 EOA 发生地址碰撞在理论上是可能的，但与 CREATE2 一样，在实践中不可行。


---

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