EIPs Explained

EIP-1109 · Stagnant · Core · 2018-05-22

EIP-1109: PRECOMPILEDCALL opcode (Remove CALL costs for precompiled contracts)

Proposed a PRECOMPILEDCALL opcode (0xfb) that calls precompiled contracts without the overhead of a regular CALL, so cheap precompiles could cost less than the CALL fee itself; it was never adopted.

What problem does it solve?

Precompiled contracts (SHA-256, ecrecover, elliptic-curve operations and so on) live at fixed low addresses and each has its own gas price. To use one, a contract has to issue an ordinary CALL or STATICCALL, and at the time that call alone cost 700 gas before the precompile's own fee.

The spec's example: SHA-256 costs 60 gas and the alt_bn128 addition was being cut to 50 gas in EIP-1108, yet each call still paid 700 gas of call overhead. That made it impossible to offer any precompile whose effective cost was below 700 gas, even when the underlying work was trivial.

How it works

The proposal adds a dedicated opcode:

  • Opcode 0xfb, named PRECOMPILEDCALL (the next free slot after STATICCALL).
  • Gas: 2 (Gbase) plus the precompile's own price. There is no separate gas argument, because precompiles do not run EVM code and their cost is known up front.
  • Stack in (5 words): precompile address, input memory offset, input length, output memory offset, output length.
  • Stack out (1 word): 1 on success, 0 if the address is not a defined precompile or the precompile itself fails (for example on invalid input).
  • If there is not enough gas for 2 plus the precompile's cost, execution stops with out-of-gas.
  • Calling a normal contract or account with PRECOMPILEDCALL is treated as an undefined precompile: nothing executes and the result is 0.

Existing CALLs to precompiles keep working exactly as before, so the change is backwards compatible.

Sample code

Illustrative EVM assembly: hash 32 bytes at memory 0 with the SHA-256 precompile (address 0x02) and write the result to memory 32. This opcode does not exist on any network, so it will not assemble with real tools.

PUSH1 0x20      // output length
PUSH1 0x20      // output offset
PUSH1 0x20      // input length
PUSH1 0x00      // input offset
PUSH1 0x02      // precompile address (SHA-256)
PRECOMPILEDCALL // 0xfb; pushes 1 on success, 0 on failure

Compared with today's equivalent, which needs a gas argument and pays the call overhead:

(bool ok, bytes memory out) = address(0x02).staticcall(abi.encodePacked(data));

Things to know

  • Status is Stagnant. The opcode was never included in a hard fork, and 0xfb is not assigned to it.
  • A similar goal was later pursued in EIP-2046, which proposed cutting the base cost of STATICCALL to precompiles from 700 to 40 gas instead of adding an opcode.
  • Under EIP-2929 (Berlin), precompile addresses are always treated as "warm", so calling one today costs far less than the 700 gas this EIP was reacting to.
  • The spec leaves the activation block as a placeholder and lists test cases but no implementation.

#evm #opcode #precompile #gas #core

Details

Authors
Jordi Baylina (@jbaylina)
Status
Stagnant
Type
Standards Track / Core
Created
2018-05-22
Required by

Machine-readable: Markdown · JSON