EIP-2997 · Stagnant · Core · 2020-09-24
EIP-2997: IMPERSONATECALL Opcode
Proposed an IMPERSONATECALL opcode that lets a contract make calls as derived sub-addresses (from its own address plus a salt), enabling multi-user wallets without deploying a contract per user.
What problem does it solve?
Services that give every user a non-custodial smart wallet usually rely on counterfactual deployment: each user has a predictable CREATE2 address, and the wallet contract is deployed only when needed. But as soon as the user wants to move ETH or tokens out, the sponsor must pay to deploy that user's contract (or a proxy), which the author estimates at least 42,000 gas per user.
EIP-2997 proposes a multi-user wallet: one contract that controls many user addresses directly, authorizing actions with EIP-712 signed messages, with no per-user deployment. It also enables batching many users' transfers while keeping normal Ethereum addresses.
How it works
A new opcode IMPERSONATECALL (0xf6) behaves like CALL but the callee sees a different sender: an address derived from the real caller and a salt.
Operands (7): gas, to, in_offset, in_size, ret_offset, ret_size, salt.
The impersonated sender is:
sender = keccak256(0xff ++ caller ++ salt ++ zeros32)[12:]
calleris the 20-byte address of the contract executing the opcode;saltis 32 bytes;zeros32is 32 zero bytes.- This mirrors CREATE2 derivation but the trailing zero bytes keep it in a separate address space from real contracts.
In the call:
CALLERreturns the impersonated address.- If value is non-zero, ETH is taken from the impersonated account's balance, so the wallet can move funds that were sent to a user's derived address.
- Gas is charged exactly as for
CALL. - No code runs "inside" the impersonated account; if a contract happens to exist there, its code is not executed.
Sample code
Off-chain derivation of a user's impersonated address (ethers v6), matching the spec's formula:
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)
A multi-user wallet would, after checking the user's EIP-712 signature, execute IMPERSONATECALL(gas, token, ..., salt = userId) so the token sees the user's own address as msg.sender.
Things to know
- Status is Stagnant. The opcode was never added to Ethereum.
- The derived addresses are controlled solely by the wallet contract's code. Users must trust that code, since anything it does can move their funds.
- Related ideas for giving accounts programmable behavior include EIP-2803 (rich transactions), ERC-4337 smart accounts, and EIP-7702, which is the path Ethereum actually shipped for EOAs.
- The spec notes address collisions with real contracts or EOAs are possible in theory but practically infeasible, as with CREATE2.