2021-05-10 05:59:09 +00:00
|
|
|
# Nim EVMC - Ethereum VM binary compatible interface
|
2018-09-05 04:34:46 +00:00
|
|
|
|
|
|
|
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
|
|
|
|
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
2021-05-08 02:13:04 +00:00
|
|
|
![Stability: unstable](https://img.shields.io/badge/stability-unstable-yellow.svg)
|
2023-04-20 09:12:01 +00:00
|
|
|
![Github action](https://github.com/status-im/nim-evmc/workflows/CI/badge.svg)
|
2018-05-28 21:29:31 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
## Introduction to EVMC
|
2018-02-02 09:44:16 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
Nim EVMC - Ethereum Virtual Machine binary compatible interface.
|
2018-04-04 13:18:10 +00:00
|
|
|
|
2021-05-07 22:37:15 +00:00
|
|
|
This the Nim version of EVMC, the [Ethereum Client-VM Connector
|
2021-05-10 05:56:03 +00:00
|
|
|
API](https://github.com/ethereum/evmc), whose description says:
|
2018-05-28 21:29:31 +00:00
|
|
|
|
2021-05-07 22:37:15 +00:00
|
|
|
> The EVMC is the low-level ABI between Ethereum Virtual Machines (EVMs) and
|
|
|
|
> Ethereum Clients. On the EVM side it supports classic EVM1 and
|
|
|
|
> [ewasm](https://github.com/ewasm/design). On the Client-side it defines the
|
|
|
|
> interface for EVM implementations to access Ethereum environment and state.
|
2018-05-28 21:29:31 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
EVMC provides a way for Ethereum applications (like
|
|
|
|
[Nimbus](https://github.com/status-im/nimbus-eth1),
|
|
|
|
[Geth](https://github.com/ethereum/go-ethereum) and
|
|
|
|
[OpenEthereum](https://github.com/openethereum/openethereum)) which use EVM
|
|
|
|
functionality to "plug in" different implementations of the EVM (or EWASM).
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
The interface is binary compatible, allowing different EVMs to be loaded as
|
|
|
|
shared libraries or statically linked in. This supports innovation from
|
|
|
|
different teams in areas like performance, new operations and hard fork
|
|
|
|
support. "Precompiles" can be loaded as separate libraries as well. (These are
|
|
|
|
specially optimised contracts, generally for cryptography support.)
|
|
|
|
|
|
|
|
The interface also makes a good module boundary between the EVM and other parts
|
|
|
|
of a full Ethereum implementation. EVMC has [detailed
|
|
|
|
documentation](https://evmc.ethereum.org/). It is mainly of interest to
|
|
|
|
developers of Ethereum clients and Ethereum Virtual Machines, but you can learn
|
|
|
|
interesting things about how the EVM fits into the Ethereum system from what
|
|
|
|
kinds of calls are in this API.
|
|
|
|
|
2021-05-08 02:11:49 +00:00
|
|
|
## Current status
|
|
|
|
|
2021-06-27 13:52:44 +00:00
|
|
|
__2021-06-27__
|
|
|
|
- Supports EVMC API version 9.0.0. This API is suitable for transactions up to
|
|
|
|
and including Ethereum *London*.
|
|
|
|
|
2021-05-08 05:34:55 +00:00
|
|
|
__2021-05-08__
|
|
|
|
- Supports EVMC API version 8.0.0. This API is suitable for transactions up to
|
|
|
|
and including Ethereum *Berlin*, the current version on mainnet at the time of
|
|
|
|
writing. *Berlin* went live on 15<sup>th</sup> April 2021.
|
|
|
|
|
2021-05-08 02:11:49 +00:00
|
|
|
__2021-05-06__
|
|
|
|
- Supports EVMC API version 7.5.0. This API is suitable for transactions up to
|
|
|
|
and including Ethereum *Istanbul*. That's everything up to 15<sup>th</sup>
|
|
|
|
April 2021 on mainnet. It recognises the later Ethereum *Berlin* but does not
|
|
|
|
have all the functions necessary to run *Berlin*.
|
|
|
|
|
|
|
|
__2019-12-16__
|
|
|
|
- Supports EVMC API version 7.1.0.
|
|
|
|
|
|
|
|
__2018-02-02__
|
|
|
|
- Initial version for EVMJIT. EVMC API doesn't have a version yet.
|
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
## Used by
|
2021-05-07 22:37:15 +00:00
|
|
|
|
|
|
|
Nim EVMC is a core component of
|
2021-05-10 05:56:03 +00:00
|
|
|
**[Nimbus Eth1](https://github.com/status-im/nimbus-eth1)**, an Ethereum
|
2021-05-07 22:37:15 +00:00
|
|
|
client written in Nim, designed to use minimal system resources and run on
|
2021-05-10 05:56:03 +00:00
|
|
|
smaller devices. Because EVMC provides a fairly clean module boundary between
|
|
|
|
the EVM and other parts of a full Ethereum implementation, after studying the
|
|
|
|
performance and other characteristics, Nimbus Eth1 decided to adopt EVMC as a
|
|
|
|
first class module boundary inside the project, using some extensions to get
|
|
|
|
extra functionality not in the base EVMC definition.
|
|
|
|
|
|
|
|
(See also its sibling project
|
2021-05-07 22:37:15 +00:00
|
|
|
[Nimbus Eth2](https://github.com/status-im/nimbus-eth1), which is very
|
|
|
|
active on the Ethereum 2 proof-of-stake network already!)
|
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
Nim EVMC by itself does not have a large test suite, just a basic one.
|
|
|
|
But it is tested by daily extensive use with Nimbus Eth1.
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
It has also been used in the past with [The Ethereum EVM
|
|
|
|
JIT](https://github.com/ethereum/evmjit). EVMJIT is no longer maintained, and
|
|
|
|
we don't use it any more. (Fun fact: EVMC was originally part of EVMJIT until
|
2021-05-07 22:37:15 +00:00
|
|
|
it was forked off to support many EVMs).
|
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
See [the EVMC main page](https://github.com/ethereum/evmc) for a more recent
|
|
|
|
list of other EVMs and clients that work with EVMC, and can in principle be
|
|
|
|
used with each other.
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
## Installation and test
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
Nim EVMC can be fetched and used as a standard Nimble package, `nim-evm`.
|
|
|
|
The main API is found in the file `evmc/evmc.nim` which is well commented, and
|
|
|
|
imported into other programs just with `import evmc/evmc`.
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
All the EVMC types, enums and functions are available, with the standard names
|
|
|
|
defined in the [EVMC Documentation](https://github.com/ethereum/evmc).
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
Additional "glue" functions for an EVM to use are available through `import
|
|
|
|
evmc/evmc_nim`. However, `evmc/evmc_nim` is not used by Nimbus Eth1 so
|
|
|
|
it's mainly useful as an example. It is used by the tests in this package
|
|
|
|
though.
|
2021-05-07 22:37:15 +00:00
|
|
|
|
|
|
|
To run this package's tests, simply run `nimble test`. It exercises calls
|
|
|
|
between C and Nim in both directions and of course everything should pass.
|
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
It's not a thorough test of EVM functionality, which would be very complex.
|
2021-05-07 22:37:15 +00:00
|
|
|
There's no need, because there are other extensive EVM testsuites, not designed
|
2021-05-10 05:56:03 +00:00
|
|
|
specially for EVMC, that can be used with Nim EVMC due to its plugin
|
|
|
|
nature.
|
2021-05-07 22:37:15 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
## Building EVMJIT and other EVMs
|
|
|
|
|
|
|
|
We used to test with EVMJIT, but EVMJIT is no longer maintained. The old
|
|
|
|
version should still work, although it will be out of date for current Ethereum
|
|
|
|
developments.
|
|
|
|
|
|
|
|
To use EVMJIT, you will need to build it as a shared library by replacing
|
|
|
|
```add_library(evmjit ${SOURCES} gen/BuildInfo.gen.h)``` with
|
|
|
|
`add_library(evmjit SHARED ${SOURCES} gen/BuildInfo.gen.h)` in file
|
2021-05-07 22:37:15 +00:00
|
|
|
`libevmjit/CMakeLists`.
|
2018-05-28 21:29:31 +00:00
|
|
|
|
2021-05-10 05:56:03 +00:00
|
|
|
Other EVM implementations can be used, if you can build them as a shared
|
|
|
|
library. Once you have done this, copy or modify the file `evmc/evmjit.nim` in
|
|
|
|
Nim EVMC with appropriate names changed. Alternatively you can look at
|
|
|
|
the [Nimbus Eth1 implementation](https://github.com/status-im/nimbus-eth1)
|
|
|
|
which is more feature complete.
|
|
|
|
|
2018-09-05 04:34:46 +00:00
|
|
|
## License
|
2018-05-28 21:29:31 +00:00
|
|
|
|
2021-05-07 22:38:12 +00:00
|
|
|
This package is licensed under either of
|
2018-09-05 18:47:47 +00:00
|
|
|
|
2021-05-07 22:38:12 +00:00
|
|
|
- Apache License, version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2))
|
|
|
|
- MIT license ([LICENSE-MIT](LICENSE-MIT))
|
2018-09-05 18:47:47 +00:00
|
|
|
|
2021-05-07 22:38:43 +00:00
|
|
|
at your option. The files in this package (except those mentioned below) may
|
|
|
|
not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
Files under subdirectory `tests/evmc_c` are third-party files from [Ethereum
|
|
|
|
Client-VM Connector API (EVMC)](https://github.com/ethereum/evmc), and may only
|
|
|
|
be used, copied, modified or distributed according to the licensing terms of
|
|
|
|
that distribution. Those terms are the Apache License, version 2.0,
|
|
|
|
([LICENSE-APACHEv2](LICENSE-APACHEv2)).
|