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
ENTRYPOINTat0x4a. It takes no stack inputs and pushes the transaction's originaltoaddress, left-padded to 256 bits. - It costs
G_base, the same asORIGIN(0x32). - During contract creation there is no
to, so it returns the zero address. - Interaction with EIP-3074's
AUTHCALL: if anAUTHCALLis on the call stack,ENTRYPOINTreturns the target of the nearestAUTHCALLinstead. This prevents the opcode from being used to tell externally owned accounts and contracts apart (for example by checkingENTRYPOINT == ADDRESS). - The author states that
ENTRYPOINTshould only be introduced together with EIP-3508'sORIGINDATA*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
AUTHCALLthis proposal defers to, was Withdrawn; account delegation went to EIP-7702 instead. - Byte
0x4ais now used byBLOBBASEFEE, 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.