---
eip: 2003
label: EIP-2003
title: EVMC modules for implementations of precompiled contracts
status: Stagnant
type: Standards Track
category: Interface
created: 2019-05-09
requires: 1352
official: https://eips.ethereum.org/EIPS/eip-2003
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2003.md
canonical: https://eips.huatuo.xyz/eip-2003/
lang: en
tldr: Specifies how to package Ethereum precompiled contracts as EVMC modules, so clients can load precompile implementations through the same plug-in API used for EVM engines.
tags: [evmc, precompiles, clients, interface]
---

# EIP-2003: EVMC modules for implementations of precompiled contracts

> [EVMC] specifies a generic API for Ethereum execution engines. This EIP specifies a way of providing implementations of Ethereum precompiled contracts using the [EVMC VM API].

**TL;DR:** Specifies how to package Ethereum precompiled contracts as EVMC modules, so clients can load precompile implementations through the same plug-in API used for EVM engines.

## What problem does it solve?

[EVMC](https://github.com/ethereum/evmc) is a C API that lets an Ethereum client plug in an execution engine (for example evmone) as a separate module. Precompiled contracts, the special addresses that run native code for things like hashing and elliptic-curve math, were still hard-coded in each client.

EIP-2003 defines how a precompile implementation can be shipped as an **EVMC module** too. A client that already speaks EVMC can then swap in a different or faster set of precompiles, or test new ones such as [EIP-1962](/eip-1962/), without changing its own code.

## How it works

A precompiles module is an ordinary EVMC VM (ABI version 6) with a few rules:

1. It advertises the `EVMC_CAPABILITY_PRECOMPILES` capability in `get_capabilities()`.
2. Its `execute()` first validates the request:
   - the message kind is a plain call (`EVMC_CALL`);
   - the destination is inside the precompile address range defined by [EIP-1352](/eip-1352/);
   - no code is passed (`code == NULL`, `code_size == 0`).
   If any check fails it returns `EVMC_REJECTED`.
3. If a precompile exists at that address for the requested EVM revision, it computes the gas cost from the input. If the gas limit is too low it returns `EVMC_OUT_OF_GAS`; otherwise it runs, returning `EVMC_SUCCESS`, the output and the gas left.
4. If no precompile exists there, it behaves like empty code: `EVMC_SUCCESS` with all gas returned.

It may also return `EVMC_FAILURE` (for example invalid input) or `EVMC_REVERT` if a precompile should not consume all gas.

Importantly, the client **does not need to provide the EVMC Host interface**: the context argument is `NULL`, and the module must not touch it. Precompiles never need to read or change state, so this saves clients most of the work of a full EVMC integration.

## Sample code

Illustrative skeleton of a module's `execute` (field names as in EVMC ABI 6; later EVMC versions renamed some):

```c
static struct evmc_result execute(struct evmc_vm* vm,
                                  const struct evmc_host_interface* host,
                                  struct evmc_host_context* ctx,   /* NULL */
                                  enum evmc_revision rev,
                                  const struct evmc_message* msg,
                                  const uint8_t* code, size_t code_size)
{
    struct evmc_result res = {.status_code = EVMC_REJECTED};
    if (msg->kind != EVMC_CALL || code != NULL || code_size != 0 ||
        !in_precompile_range(&msg->destination))
        return res;

    const struct precompile* p = lookup(&msg->destination, rev);
    if (p == NULL) {                       /* behave like empty code */
        res.status_code = EVMC_SUCCESS;
        res.gas_left = msg->gas;
        return res;
    }

    int64_t cost = p->gas_cost(msg->input_data, msg->input_size);
    if (cost > msg->gas) { res.status_code = EVMC_OUT_OF_GAS; return res; }

    res = p->run(msg->input_data, msg->input_size);  /* sets output */
    res.gas_left = msg->gas - cost;
    return res;
}
```

## Things to know

- **Status: Stagnant.** It is an interface convention between client software components; it does not change consensus rules or anything visible on-chain.
- It is tied to EVMC ABI version 6. Newer EVMC releases changed some field names and signatures, so check the version you build against.
- [EIP-1352](/eip-1352/), which defines the precompile address range it relies on, is itself Stagnant.
- EVMC ships a `evmc-vmtester` tool that can check a module for API compliance.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2003
