EIPs Explained

EIP-3520 · Stagnant · Core · 2021-04-16

EIP-3520: Transaction Destination Opcode

A stagnant proposal for an ENTRYPOINT opcode that returns the transaction's original `to` address, so contracts could inspect which top-level call they are part of.

What problem does it solve?

A contract deep inside a call chain knows who called it (CALLER) and who signed the transaction (ORIGIN), but not which contract the transaction was sent to or what that first call was trying to do. A token, for example, cannot tell whether a transfer is part of adding liquidity to a DEX or opening a loan.

EIP-3520 adds the missing piece: the address the transaction entered through. Paired with EIP-3508, which proposed opcodes to read the original transaction's calldata, a contract could reconstruct the top-level intent and react to it.

How it works

  • New opcode ENTRYPOINT at 0x4a. It takes no stack inputs and pushes the transaction's original to address, left-padded to 256 bits.
  • It costs G_base, the same as ORIGIN (0x32).
  • During contract creation there is no to, so it returns the zero address.
  • Interaction with EIP-3074's AUTHCALL: if an AUTHCALL is on the call stack, ENTRYPOINT returns the target of the nearest AUTHCALL instead. This prevents the opcode from being used to tell externally owned accounts and contracts apart (for example by checking ENTRYPOINT == ADDRESS).
  • The author states that ENTRYPOINT should only be introduced together with EIP-3508's ORIGINDATA* opcodes; alone it has little value.

Sample code

Illustrative EVM assembly (the opcode was never adopted, so no compiler supports it): revert unless the transaction entered through a trusted router.

ENTRYPOINT            ; 0x4a (proposed) -> original tx `to`, or nearest AUTHCALL target
PUSH20 <router>       ; trusted, immutable entry contract
EQ
PUSH1 ok
JUMPI
PUSH0
PUSH0
REVERT
ok:
JUMPDEST
; ... continue, optionally inspecting the original calldata via EIP-3508's ORIGINDATALOAD

Things to know

  • Status is Stagnant, and so is its companion EIP-3508. Neither was scheduled for a fork.
  • EIP-3074, whose AUTHCALL this proposal defers to, was Withdrawn; account delegation went to EIP-7702 instead.
  • Byte 0x4a is now used by BLOBBASEFEE, so this opcode number is no longer free.
  • The spec warns that introspection is only meaningful for pre-approved, immutable contracts: a user-supplied entry contract can make the transaction look like anything.
  • Test cases were never written.

#evm #opcodes #introspection #core

Details

Authors
Alex Papageorgiou (@alex-ppg)
Status
Stagnant
Type
Standards Track / Core
Created
2021-04-16
Requires

Machine-readable: Markdown · JSON