EIP2003 - EVMC modules for implementations of precompiled contracts

# Abstract

EVMC (opens new window) 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 (opens new window).

# Specification

For the complete EVMC (opens new window) specification visit the EVMC documentation (opens new window) first. This EIP is based on and is compatible with EVMC ABI version 6.

The EVMC module with implementations of precompiled contracts SHOULD:

  1. Advertise the EVMC_CAPABILITY_PRECOMPILES (opens new window) capability in the get_capabilities() (opens new window) method.

  2. Implement the execute() (opens new window) method in the following way:

    1. Validate the incoming execution request requirements:

      1. The message kind (evmc_message::kind (opens new window)) is a call (EVMC_CALL (opens new window)).

      2. The call destination address (evmc_message::destination (opens new window)) is within the range of precompiled contracts defined by EIP-1352.

      3. There is no code provided (the code argument is NULL and code_size argument is 0).

      If the requirements are not fulfilled, abort execution with the EVMC_REJECTED (opens new window) status code.

    2. Check if the call destination address (evmc_message::destination (opens new window)) targets existing precompiled contract. Consider the EVM revision (evmc_revision (opens new window)) requested by the rev parameter of execute() (opens new window).

      If yes, execute as follows:

      1. Inspect the input data (evmc_message::input_data (opens new window), evmc_message::input_size (opens new window)) and calculate the gas cost of the execution.

      2. Compute the amount of gas left after execution by subtracting the gas cost from the call gas limit (evmc_message::gas (opens new window)).

      3. If gas left is negative, abort execution with the EVMC_OUT_OF_GAS (opens new window) status code.

      4. Otherwise, execute the code of the precompiled contract, return the EVMC_SUCCESS (opens new window) status code, the output and gas left (evmc_result::output_data (opens new window), evmc_result::output_size (opens new window), evmc_result::gas_left (opens new window)).

    3. Otherwise, emulate execution of empty code by returning the EVMC_SUCCESS (opens new window) status code and gas left equal the call gas limit (evmc_message::gas (opens new window)).

Precompiled contract implementations are allowed to return two more EVMC error codes:

The Client is not required to provide the Host interface ([evmc_context] argument of execute() (opens new window) is set to NULL). Therefore, the precompiled contracts implementation MUST NOT access the evmc_context.

# Rationale

It is very unlikely that any precompile will need to access or modify a contract state. Not requiring the Client to implement the EVMC Host interface removes the big portion of work needed for full EVMC integration.

# Test Cases

EVMC provides the evmc-vmtester (opens new window) tool for checking compatibility with the EVMC specification.

# Implementations

# References

Copyright and related rights waived via CC0 (opens new window).

▲ Powered by Vercel