EIP-3508 Transaction data opcodes

No call decision · EVM & execution · EIP status Stagnant · created 2021-04-16

Three opcodes, ORIGINDATALOAD, SIZE, and COPY, let a contract read the data of the original transaction (or the arguments of an AUTHCALL) directly, rather than the calldata of an intermediate call.

Why it is needed

Complex multi-contract systems often use large data structures, but passing data between contracts in the EVM requires copying it into calldata on every call. This copying is gas-expensive, and when the data is large, execution can become impossible within the gas limit. The ORIGINDATA opcodes reduce this cost by letting any point in the call chain read the original transaction's data (or the args of an EIP-3074 AUTHCALL) directly, without intermediate relaying. This is especially useful for building trustless verification structures such as Merkle Patricia trie verification or EVM-based layer 2s.

What changes

Today

After EIP-3508

Who is affected

In depth

Definitions of the three opcodes

ORIGINDATALOAD (0x47) behaves identically to CALLDATALOAD (0x35), ORIGINDATASIZE (0x48) behaves identically to CALLDATASIZE (0x36), and ORIGINDATACOPY (0x49) behaves identically to CALLDATACOPY (0x37). The only difference is that the target is the original transaction data (or the args of the nearest AUTHCALL), not the calldata of the current call.

Gas cost

ORIGINDATALOAD consumes G_verylow, ORIGINDATASIZE consumes G_base, and ORIGINDATACOPY consumes G_base + G_verylow * (number of words copied, rounded up). These are the same gas costs as the corresponding CALLDATALOAD, CALLDATASIZE, and CALLDATACOPY, since the opcodes do the same work and the same values were carried over directly.

Interaction with AUTHCALL

EIP-3074's AUTHCALL (0xf7) replaces the transaction's ORIGIN with the context variable authorized. In the same spirit, the ORIGINDATA* opcodes are also made to point to the calldata specified by the args parameter of the nearest AUTHCALL on the call stack. This is necessary to prevent some contracts from discriminating against non-EOA callers by relying solely on ORIGINDATA.

Naming conventions and opcode address space

The ORIGIN prefix follows the existing CALL-prefix naming convention, mirroring how ORIGIN (0x32) corresponds to CALLER (0x33). Since the 0x30-0x3f address space is already exhausted, the range 0x46-0x4f following EIP-1344's CHAINID (0x46) was reserved and used for additional transaction-related data.

Security: cannot be trusted alone

The values returned by ORIGINDATALOAD and ORIGINDATACOPY can be easily manipulated by constructing a call chain in which the entry contract supplies whatever function signature and arguments it wants, so they are not safe to rely on in isolation. Implementations must always assume that tx.data can differ from calldata, and must not use these opcodes alone to perform introspection.

Security: DoS concerns and the limits of gas savings

Nodes must supply additional transaction data to the EVM, increasing memory usage, but since transaction data is already held in memory during processing, the increase is assessed as negligible. The gas savings for multi-contract systems also apply only to memory arguments and not to the storage-based data that is actually commonly used, so the overall savings are expected to be minor.

Current status

Status is Stagnant and type is Standards Track · Core. The Test Cases section remains a TODO, so the specification is incomplete, and there is no record of it being included in any specific fork, nor in call notes.

Original EIP · ← EIPs