KEVM: Semantics of EVM in K
Get started with installation
Last updated
Get started with installation
Last updated
bash <(curl https://kframework.org/install)
: install .
kup install kevm
: install KEVM.
kup list kevm
: list available KEVM versions.
kup update kevm
: update to latest KEVM version.
NOTE: The first run will take longer to fetch all the libraries and compile sources. (30m to 1h)
These may be useful for learning KEVM and K (newest to oldest):
, a nice presentation of this repository.
at .
, especially sections 3 and 5.
.
To get support for KEVM, please join our .
If you want to start proving with KEVM, refer to VERIFICATION.md
.
There are two backends of K available: LLVM for concrete execution and Haskell for symbolic execution. This repository generates the build-products for each backend in .build/usr/lib/kevm
.
First install the following tools:
Installing Z3
On macOS, it is easiest to install Z3 from Homebrew. If you wish to install from the source, install it to an appropriate prefix (e.g. /usr/local
on Intel machines).
Ubuntu
On Ubuntu >= 22.04 (for example):
On Ubuntu < 18.04, you'll need to skip libsecp256k1-dev
and instead build it from source (via our Makefile
):
Arch Linux
On ArchLinux:
macOS
NOTE: It is recommended to use the homebrew version of flex
and XCode.
If the build on macOS still fails, you can also try adding the following lines to the top of your Makefile
under UNAME_S
:
Haskell Stack (all platforms)
To upgrade stack
(if needed):
K Framework
The Makefile
and kevm
will work with either a (i) globally installed K or a (ii) K submodule included in this repository. For contributing to kevm
, it is highly recommended to go with (ii) because some of the build scripts might not work otherwise. Follow these instructions to get and build the K submodule:
If you don't need either the LLVM or Haskell backend, there are flags to skip them:
On an Apple Silicon machine, an additional flag to make
is required to correctly build the Haskell backend:
Blockchain Plugin
You also need to get the blockchain plugin submodule and install it.
You need to set up a virtual environment using Poetry with the prerequisites python 3.8.*
, pip >= 20.0.2
, poetry >= 1.3.2
:
Finally, you can build the semantics.
You can build specific targets using build-llvm
, build-Haskell
, or build-foundry
. For more information, refer to the Makefile.
The tests are run using the supplied Makefile
. Run make build-prove
to generate tests from the markdown files.
The following subsume all other tests:
make test
: All of the quick tests.
make test-all
: All of the quick and slow tests.
These are the individual test-suites (all of these can be suffixed with -all
to also run slow tests):
make test-interactive
: Tests of the kevm
command.
When running tests with the Makefile
, you can specify the TEST_CONCRETE_BACKEND
(for concrete tests), or TEST_SYMBOLIC_BACKEND
(for proofs).
If built from the source, the kevm
executable will be in the .build/usr/bin
directory. To make sure you are using the correct kevm
, add this directory to your PATH
:
Alternatively, if you work on multiple checkouts of evm-semantics
or other semantics, you could add the relative path .build/usr/bin
to your PATH
. Do note, however, that this is a security concern.
You can call kevm help
to get a quick summary of how to use the script.
Run the file tests/ethereum-tests/LegacyTests/Constantinople/VMTests/vmArithmeticTest/add0.json
:
To enable the debug symbols for the llvm backend, build using this command:
To debug a conformance test, add the --debugger
flag to the command:
Always have your build up-to-date.
If using the kup package manager, run kup install kevm --version .
to install the local version.
If building from source:
make poetry
needs to be re-run if you touch any of the kevm-pyk
code.
make build
needs to be re-run if you touch any of this repos files.
make deps
needs to be re-run if there is an update of the K submodule (you did git submodule update --init --recursive -- deps/k
and it actually did something).
If both deps
and build
need to be re-run, you need to do deps
first.
make clean
is a safe way to remove the .build
directory, but then you need to re-run make deps
(should be quick this time) and make build
.
This is needed to expose the Nix 2.0 CLI and flakes support that are hidden behind feature-flags.
To build KEVM, run:
This will build all of KEVM and K and put a link to the resulting binaries in the result/
folder.
NOTE: Mac users, especially those running M1/M2 Macs may find nix segfaulting on occasion. If this happens, try running the nix command like this: GC_DONT_GC=1 nix build .
If you want to temporarily add the kevm
binary to the current shell, run
Nix can also be used to quickly profile different versions of the Haskell backend. Simply run:
replacing <HASH>
with the commit you want to run profiling against.
If you want to profile against a working version of the Haskell backend repository, simply cd
into the root of the repo and run:
To compare profiles, you can use:
This will produce a nice table with the times for both versions of the haskell-backend. Note that #profile
pre-pends the output of kore-exec --version
to the profile run, which is then used as a tag by the #compare-profiles
script. Therefore, any profiled local checkout of the haskell-backend will report as dirty-ghc8107
in the resulting table.
For the presentations in the media
directory, you'll need pdflatex
, commonly provided with texlive-full
, and pandoc
.
To build all the PDFs (presentations and reports) available in the media/
directory, use:
GNU , , and .
GNU and .
version 4.12.1
KEVM requires Z3 version 4.12.1, which you may need to install from a source build if your package manager supplies a different version. To do so, follow the instructions after checking out the correct tag in the Z3 repository:
After installing the Command Line Tools, , and getting the blockchain plugin, run:
If you are building on an Apple Silicon machine, ensure that your PATH
is set up correctly before running make deps
or make k-deps
. You can do so using by copying macos-envrc
to .envrc
, then running direnv allow
.
. Note that the version of the stack
tool provided by your package manager might not be recent enough. Please follow installation instructions from the Haskell Stack website linked above.
To execute tests from the , the submodule needs to be fetched first.
make test-vm
: VMTests from the .
make test-bchain
: Subset of BlockchainTests from the .
make test-proof
: Proofs from the .
We now support building KEVM using . To set up nix flakes you will need to be on nix
2.4 or higher and follow the instructions .
For example, if you are on a standard Linux distribution, such as Ubuntu, first and then enable flakes by editing either ~/.config/nix/nix.conf
or /etc/nix/nix.conf
and adding:
By default, Nix will build the project and its transitive dependencies from source, which can take up to an hour. We recommend setting up to speed up the build process significantly.
This repository can build two pieces of documentation for you, the and the presentation.