KEVM: Semantics of EVM in K
In this repository we provide a model of the EVM in K.
These may be useful for learning KEVM and K (newest to oldest):
- Jello Paper, generated using Sphinx Documentation Generation.
- 20 minute tour of the semantics at 2017 Devcon3.
- KEVM 1.0 technical report, especially sections 3 and 5.
- KEVM Paper at CSF'18/FLoC.
To get support for KEVM, please join our Riot Room.
There are four backends of K available, the OCAML and (experimental) LLVM backends for concrete execution, and the Java and (experimental) Haskell backends for symbolic reasoning and proofs.
This repository generates the build-products for both non-experimental backends in
The following are needed for building/running KEVM:
- Pandoc >= 1.17 is used to generate the
*.kfiles from the
- GNU Bison, Flex, and Autoconf.
- GNU libmpfr and libtool.
- Java 8 JDK (eg. OpenJDK)
- Opam, important: Ubuntu users prior to 15.04 must build from source, as the Ubuntu install for 14.10 and prior is broken.
opam repositoryalso requires
On Ubuntu >= 18.04 (for example):
sudo apt install \ autoconf bison flex gcc git libmpfr-dev libsecp256k1-dev \ libtool libz3-dev make maven opam openjdk-8-jdk pandoc \ pkg-config z3 zlib1g-dev
On Ubuntu < 18.04, you'll need to skip
libsecp256k1-dev and instead build it from source (via our
sudo pacman -S \ base base-devel boost clang cmake crypto++ curl git gmp \ jdk-openjdk jemalloc libsecp256k1 lld llvm maven mpfr \ opam python rustup stack yaml-cpp z3 zlib
On OSX, using Homebrew, after installing the command line tools package:
brew tap caskroom/cask brew cask install adoptopenjdk8 brew install automake libtool gmp mpfr pkg-config pandoc maven opam z3 libffi make libsecp256k1
NOTE: a previous version of these instructions required the user to run
brew link flex --force.
After fetching this revision, you should first run
brew unlink flex, as it is no longer necessary and will cause an error if you have the homebrew version of flex installed instead of the xcode command line tools version.
After installing the above dependencies, make sure the submodules are setup:
git submodule update --init --recursive
If you haven't already setup K's OCaml dependencies more recently than February 1, 2019, then you also need to setup the K OCaml dependencies:
Finally, you can install repository specific dependencies and build the semantics:
make deps make build
OPTIONAL: K LLVM/Haskell Backends
The K LLVM/Haskell backends, currently under development, require extra dependencies to work.
- Haskell Stack.
Note that the version of the
stacktool provided by your package manager might not be recent enough. Please follow installation instructions from the Haskell Stack website linked above.
stack (if needed):
stack upgrade export PATH=$HOME/.local/bin:$PATH
The LLVM backend has additional dependencies:
sudo apt install cmake clang-6.0 clang++-6.0 llvm-6.0 lld-6.0 libboost-test-dev libgmp-dev libyaml-cpp-dev libjemalloc-dev curl protobuf-compiler libprotobuf-dev
On Arch, you'll also need
And you need to setup Rust:
Additionally, you need to setup the remaining LLVM dependencies.
make LIBFF_CC=clang LIBFF_CXX=clang++ llvm-deps
After installing the above dependencies, the following command will build the extra backends into K:
make haskell-deps: additionally build the Haskell backend into K.
make llvm-deps: additionally build the LLVM backend into K.
make all-deps: additionally build both the Haskell and LLVM backends into K.
Following this dependency setup, you can also now
kompile the LLVM and Haskell backends:
make build-haskell make build-llvm
The following files constitute the KEVM semantics:
- krypto.md sets up some basic cryptographic primitives.
- data.md provides the (functional) data of EVM (256 bit words, wordstacks, etc...).
- evm.md is the main KEVM semantics, containing the configuration and transition rules of EVM.
These additional files extend the semantics to make the repository more useful:
- driver.md is an execution harness for KEVM, providing a simple language for describing tests/programs.
- edsl.md defines high-level notations of eDSL, a domain-specific language for EVM specifications, for formal verification of EVM bytecode using K Reachability Logic Prover.
After building the definition, you can run the definition using
./kevm script for examples of the actual invocations of
Run the file
./kevm run tests/ethereum-tests/VMTests/vmArithmeticTest/add0.json
To run proofs, you can similarly use
For example, to prove one of the specifications:
./kevm prove tests/specs/ds-token-erc20/transfer-failure-1-a-spec.k -m VERIFICATION
The tests are run using the supplied
make split-tests to generate some of the 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-vm: VMTests from the Ethereum Test Set.
make test-bchain: Subset of BlockchainTests from the Ethereum Test Set.
make test-proof: Proofs from the Verified Smart Contracts.
make test-interactive: Tests of the
When running tests with the
Makefile, you can specify the
TEST_CONCRETE_BACKEND (for concrete tests), or
TEST_SYMBOLIC_BACKEND (for proofs).
If you also want to build the Jello Paper, you'll additionally need:
sudo apt install python-pygments python-sphinx python-recommonmark git clone 'https://github.com/kframework/k-editor-support' cd k-editor-support/pygments easy_install --user .
For the 2017 Devcon3 presentation, you'll need
pdflatex, commonly provided with
sudo apt install texlive-full
The Makefile supplies targets for building:
- All media in this list:
- Jello Paper documentation:
- 2017 Devcon3 presentation:
For more information about The K Framework, refer to these sources:
- The K Tutorial
- Semantics-Based Program Verifiers for All Languages
- Reachability Logic Resources
- Matching Logic Resources
- Logical Frameworks: Discussion of logical frameworks.