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 Devcon3.
- KEVM 1.0 technical report, especially sections 3 and 5.
To get support for KEVM, please join our Riot Room.
There are two backends of K available, the OCAML backend for concrete execution and the Java backend for symbolic reasoning and proofs.
This repository generates the build-products for both backends in .build/java/
and .build/ocaml/
.
The following are needed for building/running KEVM:
- Pandoc >= 1.17 is used to generate the
*.k
files from the*.md
files. - 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 repository
also requiresrsync
.
On Ubuntu >= 15.04 (for example):
sudo apt-get install make gcc maven openjdk-8-jdk flex opam pkg-config libmpfr-dev autoconf libtool pandoc zlib1g-dev
To run proofs, you will also need Z3 prover; on Ubuntu:
sudo apt-get install z3
If you also want to build the Jello Paper, you'll additionally need:
- Sphinx Documentation Generation tool, and
- The K Editor Support Python
pygments
package.
sudo apt-get install python-pygments python-sphinx
git clone 'https://github.com/kframework/k-editor-support'
cd k-editor-support/pygments
sudo easy_install .
On ArchLinux:
sudo pacman -S base-devel rsync opam pandoc jre8-openjdk mpfr maven z3
On OSX, using Homebrew, after installing the command line tools package:
brew tap caskroom/cask caskroom/version
brew cask install java8
brew install automake libtool gmp mpfr pkg-config pandoc maven opam z3
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, the following command will build submodule dependencies and then KEVM:
make deps
make
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.
- analysis.md contains any automated analysis tools we develop.
- 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
.
Read the ./kevm
script for examples of the actual invocations of krun
that ./kevm
makes.
Run the file tests/ethereum-tests/VMTests/vmArithmeticTest/add0.json
:
./kevm run tests/ethereum-tests/VMTests/vmArithmeticTest/add0.json
Run the same file as a test:
./kevm test tests/ethereum-tests/VMTests/vmArithmeticTest/add0.json
To run proofs, you can similarly use ./kevm
.
For example, to prove the specification tests/proofs/specs/vyper-erc20/totalSupply-spec.k
:
./kevm prove tests/proofs/specs/vyper-erc20/totalSupply-spec.k
Finally, if you want to debug a given program (by stepping through its execution), you can use the debug
option:
./kevm debug tests/ethereum-tests/VMTests/vmArithmeticTest/add0.json
...
KDebug> s
1 Step(s) Taken.
KDebug> p
... Big Configuration Here ...
KDebug>
The tests are run using the supplied Makefile
.
First, run 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 vm-test
: VMTests from the Ethereum Test Set.make bchain-test
: Subset of BlockchainTests from the Ethereum Test Set.make proof-test
: Proofs from the Verified Smart Contracts.make interactive-test
: Tests of the./kevm
command and of analysis tools.
Any pull requests into this repository will not be reviewed until at least some conditions are met. Here we'll accumulate the standards that this repository is held to.
Code style guidelines, while somewhat subjective, will still be inspected before going to review. In general, read the rest of the definition for examples about how to style new K code; we collect a few common flubs here.
Writing tests and more contract proofs is always appreciated. Tests can come in the form of proofs done over contracts too :).
These are hard requirements (must be met before review), and they must be true for every commit in the PR.
-
If a new feature is introduced in the PR, and later a bug is fixed in the new feature, the bug fix must be squashed back into the feature introduction. The only exceptions to this are if you want to document the bug because it was quite tricky or is something you believe should be fixed about K. In these exceptional cases, place the bug-fix commit directly after the feature introduction commit and leave useful commit messages. In addition, mark the feature introduction commit with
[skip-ci]
if tests will fail on that commit so that we know not to waste time testing it. -
No tab characters, 4 spaces instead. Linux-style line endings; if you're on a Windows machine make sure to run
dos2unix
on the files. No whitespace at the end of any lines.
These are hard requirements (must be met before review), but they only have to be true for the tip of the PR before review.
- Every test in the repository must pass.
We will test this with
make split-tests ; make test -j12
.
These are soft requirements (review may start without these being met), and they will be considered for every commit in the PR.
-
Comments do not live in the K code blocks, but rather in the surrounding Markdown (unless there is a really good reason to localize the comment).
-
You should consider prefixing "internal" symbols (symbols that a user would not write in a program) with a hash (
#
). -
Place a line of
-
after each block of syntax declarations.syntax Foo ::= "newSymbol" // -------------------------- rule <k> newSymbol => . ... </k>
Notice that if there are rules immediately following the syntax declaration, a commented-out line of
-
is inserted afterward. Notice that the width of the line of-
matches that of the preceding line. -
Place spaces around parentheses and commas in K's pretty functional-style syntax declarations.
syntax Foo ::= newFunctionalSyntax ( Int , String ) // ---------------------------------------------------
-
When multiple structurally-similar rules are present, line up as much as possible (and makes sense).
rule <k> #do1 => . ... </k> <cell1> not-done => done </cell1> rule <k> #do1Longer => . ... </k> <cell1> not-done => done-longer </cell1> rule <k> #do2 => . ... </k> <cell2> not-done => done2 </cell2> rule <k> #doShort => . ... </k> <cell2> nd => done2 </cell2>
This makes it simpler to make changes to entire groups of rules at a time using sufficiently modern editors. Notice that if we break alignment (eg. from the
#do1
group above to the#do2
group), we put an extra line between the groups of rules. -
Line up the
r
inrequires
with thel
inrule
(if it's not all on one line). Similarly, line up the end ofandBool
for extra side-conditions with the end ofrequires
.rule <k> A => B ... </k> SOME_LARGE_CONFIGURATION requires A > 3 andBool isPrime(A)
- EVM Yellowpaper: Original specification of EVM.
- LEM Semantics of EVM
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.