EIP-2003 EVMC precompile implementation module (EVMC modules for implementations of precompiled contracts)

No call decision · EVM & execution · EIP status Stagnant · created 2019-05-09

Defines a way to implement precompiled (built-in) contracts as separate modules shared across multiple clients, using EVMC, the common interface connecting clients and execution engines.

Why it is needed

Ethereum clients each implement precompiled contracts, which perform frequently used functions like hash operations or signature verification, directly within their own codebase. When implementations differ across clients, reuse becomes difficult, and every time a new precompile is added, every client must reimplement it from scratch. EVMC (Ethereum Client-VM Connector) is a common API between clients and execution engines, and if a precompile implementation is separated into its own module conforming to this interface, an implementation built once can be adopted as-is by multiple clients. This EIP sets out the specific behavioral specification a module must follow to make such sharing possible.

What changes

Today

After EIP-2003

Who is affected

In depth

Separation of roles from EVMC

EVMC is a common API between clients and the execution engine (VM). This EIP, based on EVMC ABI version 6, defines how to build a module dedicated solely to implementing precompiled contracts. Such a module SHOULD advertise EVMC_CAPABILITY_PRECOMPILES in get_capabilities().

The execute() validation step

The module first checks whether the incoming execution request satisfies the following: whether evmc_message::kind is EVMC_CALL, whether evmc_message::destination falls within the precompile address range defined by EIP-1352, and whether the code argument is NULL with code_size of 0 (meaning no code was supplied). If any of these three does not hold, execution is aborted with the EVMC_REJECTED status code.

Handling an existing precompile

If the destination address corresponds to an actual precompile under the requested evmc_revision, the module computes the gas cost from input_data and input_size, and obtains gas left by subtracting this cost from evmc_message::gas. If gas left is negative, it returns EVMC_OUT_OF_GAS; otherwise it executes the precompile code and returns EVMC_SUCCESS along with output_data, output_size, and gas_left.

A destination that is not a precompile

If the destination address is not within the precompile range, the module behaves as if empty code had been executed. It returns EVMC_SUCCESS, with gas left set equal to the call gas limit (evmc_message::gas).

Additional permitted error codes

A precompile implementation may also return EVMC_FAILURE (when it fails for a reason other than insufficient gas, such as an input validation error) and EVMC_REVERT (when it wants to revert without forfeiting all of the gas supplied). The original text states that, as of its writing in May 2019, no precompile used EVMC_REVERT.

A design that does not access state

A client does not need to provide a Host interface to this module. The evmc_context argument of execute() is set to NULL, and a precompile implementation MUST NOT access evmc_context. The original text gives as the reasons that precompiles rarely need to read or modify contract state, and that not requiring a Host interface significantly reduces the work needed for full EVMC integration.

Verification tooling and reference implementations

EVMC provides a tool called evmc-vmtester to check compatibility with this specification. The original text cites example_precompiles_vm.cpp, ewasm precompiles, the precompile code of Aleth and Parity, and an implementation of EIP-1962 as an EVMC precompile module as reference implementations.

Current status

This EIP's status is Stagnant, meaning it is not actively being progressed. It falls under the Interface category, which deals with client implementation interfaces rather than being a Core EIP that changes network protocol rules, and it does not change the behavioral rules of the Ethereum network itself.

Original EIP · ← EIPs