EIP-2997 An opcode for sender impersonation calls (IMPERSONATECALL Opcode)

No call decision · EVM & execution · EIP status Stagnant · created 2020-09-24

A proposal to add a new opcode, IMPERSONATECALL (0xf6), that makes the callee see a fake (impersonated) address derived from the caller's address and a salt as the sender, instead of the real caller.

Why it is needed

Building a multi-user wallet where one contract acts on behalf of many users currently requires deploying a separate smart contract (or proxy) for each user in advance. Even with counterfactual contract creation, where only the address is precomputed and actual deployment is deferred, the contract must ultimately be deployed the moment a user first sends out ether or tokens, costing at least 42000 gas per user. This cost is a burden especially for sponsoring companies that want to deploy non-custodial wallets for users for free. Without actually deploying a contract, IMPERSONATECALL lets the callee see a different sender address, supporting metatransactions driven by EIP-712 signed messages and rollup-like batched transfers under the ordinary address scheme.

What changes

Today

After EIP-2997

Who is affected

In depth

Opcode and operands

IMPERSONATECALL is opcode 0xf6, taking from the stack the same six operands as CALL (gas, to, in_offset, in_size, ret_offset, ret_size) plus one additional 32-byte salt, for seven operands total. gas is the amount of gas available for execution, to is the destination address holding the code to run, in_offset/in_size are the input memory location and size, and ret_offset/ret_size are the memory location and size for writing the result.

Computing the impersonated sender address

The impersonated sender address is computed as the last 20 bytes ([12:]) of keccak256(0xff ++ address ++ salt ++ zeros32). address is the real caller contract's 20-byte address, salt is a 32-byte value, and zeros32 is 32 zero bytes. This scheme mimics CREATE2's address derivation but is designed to avoid substantively colliding with the CREATE2 address space. The original text also mentions an alternative that omits zeros32 to shorten the preimage to 53 bytes, and explains that this case likewise produces no address collisions.

Gas cost and CALLER behavior

IMPERSONATECALL behaves identically to CALL in terms of gas consumption. The Rationale notes that hashing three words does add 180 gas, but explains that accounting for this separately would add implementation complexity without a commensurate benefit. In the called context, CALLER (0x33) returns the computed impersonated address rather than the real caller.

Characteristics of value transfer

If the value included in the call is nonzero, that value moves from the impersonated account rather than the real caller. This property can be used to move ether out of the impersonated account.

Existing contracts and SELFDESTRUCT handling

Even if a contract is already deployed at the impersonated address, IMPERSONATECALL executes the same way and that existing code is not run. SELFDESTRUCT (0xff) cannot be executed directly via IMPERSONATECALL, because no opcode is ever executed in the impersonated account's context in the first place.

Backward compatibility

0xf6 is currently an unused opcode, and executing it raises an out-of-gas (OOG) exception. Solidity uses INVALID (0xfe, called ABORT in EIP-1803) to trigger OOG, so 0xf6 does not appear in ordinary Solidity programs. It is also noted that EVM assembly programmers have long been advised not to put this opcode in their code, so there is no backward compatibility risk.

Security considerations and current status

It explains that the address derivation scheme is designed to avoid address collisions with already-deployed contracts or externally owned accounts (EOAs). This proposal was written on 2020-09-24 and its current status is Stagnant (discussion has halted), and it has not been included in any fork.

Original EIP · ← EIPs