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).
The EVMC module with implementations of precompiled contracts SHOULD:
execute()(opens new window) method in the following way:
Validate the incoming execution request requirements:
There is no code provided (the
If the requirements are not fulfilled, abort execution with the
EVMC_REJECTED(opens new window) status code.
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
execute()(opens new window).
If yes, execute as follows:
Compute the amount of gas left after execution by subtracting the gas cost from the call gas limit (
evmc_message::gas(opens new window)).
If gas left is negative, abort execution with the
EVMC_OUT_OF_GAS(opens new window) status code.
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)).
Precompiled contract implementations are allowed to return two more EVMC error codes:
EVMC_FAILURE(opens new window) if the failure was caused due to something other than out of gas (e.g. input validation error)
EVMC_REVERT(opens new window) if the precompile doesn't want to forfeit all supplied gas (as of May 2019 no such precompile exists)
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
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.
- Example of Precompiles VM implementation (opens new window)
- ewasm precompiles (opens new window)
- Aleth code for precompiles
- Parity code for precompiles
- EIP-1962 implemented as an EVMC precompile module (opens new window)
- EVMC – Ethereum Client-VM Connector API (opens new window)
- EVMC documentation (opens new window)
- EVMC VM Implementation Guide (opens new window)
- EIP 1352: Specify restricted address range for precompiles/system contracts
Copyright and related rights waived via CC0 (opens new window).