EIP-1109 The PRECOMPILEDCALL opcode (PRECOMPILEDCALL opcode (Remove CALL costs for precompiled contracts))
No call decision · EVM & execution · EIP status Stagnant · created 2018-05-22
A proposal to create a dedicated opcode, PRECOMPILEDCALL (0xfb), that only calls precompiled contracts, charging just the base 2 gas plus the precompile's own gas, without the 700-gas overhead attached to a regular CALL.
Why it is needed
Calling a precompiled contract (a contract built into the EVM to handle specific operations at a low level, such as SHA256 or ECADD) currently requires using the regular CALL opcode. Because CALL itself consumes 700 gas, even a precompile with an intrinsic cost of 60 gas, like SHA256, or 500 gas (50 gas under the EIP-1108 proposal), like ECADD, ends up costing at least 700 gas to actually call. As a result, it is effectively impossible to design a precompile whose effective cost is cheaper than 700 gas. This EIP aims to remove this unnecessary overhead by providing a separate call path dedicated to precompiles.
What changes
Today
- Precompile calls also use the regular CALL (0xf1)
- The precompile's own gas is added on top of CALL's own 700 gas
- Even when a precompile's intrinsic cost is low, the actual call cost is always at least 700 gas
- Designing a precompile cheaper than 700 gas is impossible
After EIP-1109
- The dedicated PRECOMPILEDCALL (0xfb) opcode becomes available for precompiles
- Cost is only Gbase (2 gas) plus the precompile's own gas
- Designing a precompile with an effective cost below 700 gas becomes possible
- Calling precompiles via the existing CALL still works as before
Who is affected
- Smart contract developers: Gas costs can be reduced for contracts that call precompiles frequently
- Client and EVM implementation teams: The new opcode 0xfb, its 5 stack inputs, and success/failure (1/0) return logic must be implemented
- Precompile designers: Room opens up to design precompiles with an effective cost below 700 gas
In depth
Opcode definitions
The new opcode PRECOMPILEDCALL has the value 0xfb, taking the number immediately after STATICCALL (0xfa). The original text states it activates when block.number >= XXXXX, but the actual block number remains an unconfirmed placeholder (XXXXX).
Stack inputs and outputs
The opcode takes 5 values from the stack. mu_s[0] is the address of the precompile to call, mu_s[1] is the memory pointer to the input parameters, mu_s[2] is the length of the input parameters in bytes, mu_s[3] is the memory pointer where the output is stored, and mu_s[4] is the length of the output buffer. After execution, only a single word is returned on the stack: 1 on success, 0 on failure.
Gas cost calculation
Gas cost equals Gbase (2) plus the intrinsic gas cost defined in the given precompile contract. Since precompiles do not execute EVM opcodes, there is no need to pass a separate gas parameter on the stack as with a normal CALL. If the remaining gas is less than 2 plus the intrinsic gas, the context immediately halts with an Out of Gas error.
Failure conditions and absence of stack check
There are two cases where the call returns 0: when mu_s[0] points to an undefined precompile address, or when the precompile itself fails according to its own definition (for example, due to invalid input parameters). The spec states explicitly that this opcode has no stack check.
Calling a regular address or contract
If PRECOMPILEDCALL is used to call a regular account or a regular smart contract, it is treated as a call to an undefined precompile. The VM MUST NOT execute that address, and the opcode MUST return 0x0.
Backward compatibility
Calling a precompile via the existing CALL (0xf1) still works exactly as before, and this EIP is backward compatible. Only contracts that use the new opcode get the reduced cost; existing contracts are unaffected.
Current status
This EIP is in Stagnant status, and its Implementation entry still reads Not implemented yet, meaning it has not been implemented. The activation block number is also only given as a placeholder (XXXXX), so the source material does not state whether it has actually been adopted or included in any specific hard fork.