-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trufflecon - Presentations and demo files added (#425)
* Makefile: target test-proof => test-prove * Makefile, media/201905-exercise-k-workshop: add EthNYC Workshop * media/201905-exercise-k-workshop: flesh out rest of presentation * media/201905-exercise-k-workshop: updates * media/201905-exercise-k-workshop: final updates * Makefile, media/201908-trufflecon-workshop: add initial trufflecon presentation * .gitignore: ignore generated pdfs * media/201908-trufflecon: shorten and simplify for trufflecon * media/201908-trufflecon: more updates to presentation * media/201908-trufflecon: update instructions for KLab * Makefile, media/201908-trufflecon-firefly: firefly presentation/demo slides * media/images/k-overview: updated image * add-spec: add relevant file * media/201908-trufflecon-workshop: update instructions * add-*-spec.k: more specs * kevm-ltl: add LTL example * addition: add example addition program * kevm, kevm-ltl, addition.evm: LTL instrumentation * kevm: remove ltl command * media/201908-trufflecon-workshop: update slides * media/201908-trufflecon-workshop: Update title * media/201808-trufflecon-workshop: update presentation with docker instructions * media/201908-trufflecon: add proxy dockerhub account * media/201908-trufflecon-workshop: update instructions * kevm-ltl, addition: labeled event sets in trace * media/201908-trufflecon-firefly: update presentation * kevm-ltl: event collection done as a monitor too * media/201908-trufflecon-firefly: updated demo slides * kevm-ltl: add invalid event * kevm-ltl: manually set exit code to 0 * kevm: allow overriding KEVM_DEFN_DIR * * => media/201908-trufflecon: move files to subdirectory * media/201908-trufflecon: update documentation * media/201908-trufflecon: update documentation * Jenkinsfile: test-proof => test-prove * README: fix path .build/k => deps/k
- Loading branch information
Showing
14 changed files
with
744 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/src | ||
/package/pkg | ||
/package/src | ||
/media/*.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
--- | ||
title: 'K Workshop' | ||
subtitle: 'Understanding the K Prover' | ||
author: | ||
- Everett Hildenbrandt | ||
institute: | ||
- Runtime Verification | ||
- ConsenSys | ||
date: '\today' | ||
theme: metropolis | ||
fontsize: 8pt | ||
--- | ||
|
||
Overview | ||
-------- | ||
|
||
- Install KEVM and KLab on your machine | ||
- Simple uses of the `./kevm` script | ||
- (Brief) introduction to KEVM | ||
- Verification examples: KEVM lemma proofs, ERC20 `transfer` function | ||
- Open verification challenge | ||
|
||
Install KEVM | ||
------------ | ||
|
||
### KEVM | ||
|
||
- Branch `kevm-lemmas` of KEVM: <https://github.com/kframework/evm-semantics> | ||
- Build instructions in README. | ||
|
||
```sh | ||
make deps | ||
make build-java | ||
make build-ocaml | ||
``` | ||
|
||
- Should be able to run: | ||
|
||
```sh | ||
make test-prove-verified | ||
make test-prove-gen -j3 | ||
``` | ||
|
||
. . . | ||
|
||
### KLab | ||
|
||
- Branch `master` of KLab: <https://github.com/dapphub/klab> | ||
- Build instructions in README. | ||
|
||
```sh | ||
make deps-npm | ||
``` | ||
|
||
- Should be able to run (in KEVM repo with `klab/bin` on your `PATH`): | ||
|
||
```sh | ||
make tests/specs/verified/kevm-lemmas-spec.k | ||
./kevm klab-prove tests/specs/verified/kevm-lemmas-spec.k --boundary-cells k,pc | ||
``` | ||
|
||
`./kevm help` | ||
------------- | ||
|
||
```sh | ||
$ ./kevm help | ||
usage: ./kevm (run|kast) [--backend (ocaml|java|llvm|haskell)] <pgm> <K args>* | ||
./kevm interpret [--backend (ocaml|llvm)] <pgm> | ||
./kevm prove [--backend (java|haskell)] <spec> <K args>* | ||
./kevm klab-(run|prove) <spec> <K args>* | ||
./kevm run : Run a single EVM program | ||
./kevm interpret : Run JSON EVM programs without K Frontend (external parser) | ||
./kevm prove : Run an EVM K proof | ||
./kevm klab-(run|prove) : Run or prove a spec and launch KLab on the execution graph. | ||
Note: <pgm> is a path to a file containing an EVM program/test. | ||
<spec> is a K specification to be proved. | ||
<K args> are any arguments you want to pass to K when executing/proving. | ||
KLab: Make sure that the 'klab/bin' directory is on your PATH to use this option. | ||
``` | ||
|
||
`./kevm` examples | ||
----------------- | ||
|
||
> - Run a test: `MODE=... SCHEDULE=... ./kevm run tests/etheremu-tests/...` | ||
> - Interpret a test (fast): `MODE=... SCHEDULE=... ./kevm interpret tests/etheremu-tests/...` | ||
> - Run a proof: `./kevm prove tests/specs/*-spec.k` | ||
> - Run a test under KLab: `MODE=... SCHEDULE=... ./kevm klab-run tests/ethereum-tests/...` | ||
> - Run a proof under KLab: `./kevm klab-prove tests/ethereum-tests/...` | ||
|
||
Introduction to KEVM | ||
-------------------- | ||
|
||
- File [data.md](../data.md) defines data-structures of EVM. | ||
- File [evm.md](../evm.md) defines the semantics itself. | ||
- File [driver.md](../driver.md) defines the testing harness. | ||
- File [edsl.md](../edsl.md) defines a DSL for aiding specification for proofs. | ||
|
||
Verification Examples | ||
--------------------- | ||
|
||
### KEVM Lemmas | ||
|
||
- File [kevm-lemmas-spec.md](../kevm-lemmas-spec.k) | ||
- Summaries of the "positive" cases of arithmetic opcodes and push | ||
- Work through how to use KLab to discover preconditions | ||
- Complete the push, push, add specification | ||
|
||
```sh | ||
make test-prove-verified | ||
``` | ||
|
||
. . . | ||
|
||
### ERC20 `transfer` functions | ||
|
||
- Run proof. | ||
|
||
```sh | ||
make test-prove-gen | ||
``` | ||
|
||
- Explain ini file format of [ds-token-erc20-spec.ini](../tests/specs/ds-token-erc20/ds-token-erc20-spec.ini) | ||
- Delete all except the `transfer` blocks | ||
- Remove `requires` clauses to explore result in KLab | ||
|
||
Open Verification Challenge | ||
--------------------------- | ||
|
||
Rest of time. | ||
|
||
- Work on `transferFrom` function? | ||
- Try to setup your own contract? | ||
|
||
Thanks! | ||
------- | ||
|
||
- ConsenSys for hosting us! | ||
- You all for attending! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
--- | ||
title: 'Firefly' | ||
subtitle: 'Solidity testing using KEVM' | ||
author: | ||
- Everett Hildenbrandt | ||
- Grigore Rosu | ||
institute: | ||
- Runtime Verification | ||
date: '\today' | ||
theme: metropolis | ||
fontsize: 8pt | ||
--- | ||
|
||
Overview | ||
-------- | ||
|
||
- (Brief) Introduction to KEVM | ||
- Introduction to Firefly | ||
- Firefly Demo | ||
- Future Directions | ||
|
||
(Brief) Introduction to KEVM | ||
---------------------------- | ||
|
||
- Repository: <https://github.com/kframework/evm-semantics> | ||
- Considered the canonical spec of EVM: <https://ethereum-magicians.org/t/jello-paper-as-canonical-evm-spec/2389> | ||
- All K tooling is derived automatically: | ||
- Reference EVM interpreter | ||
- Symbolic execution engine | ||
- EVM bytecode formal verification engine | ||
- Several EVM bytecode debugger options | ||
|
||
Introduction to Firefly | ||
----------------------- | ||
|
||
- `npm` package here: <https://www.npmjs.com/package/kevm-ganache-cli>. | ||
- Drop-in replacement for `ganache-cli`, can be used directly by Truffle. | ||
|
||
Instead of: | ||
|
||
```sh | ||
npx ganache-cli | ||
``` | ||
|
||
run: | ||
|
||
```sh | ||
npx kevm-ganache-cli | ||
``` | ||
|
||
. . . | ||
|
||
### Why?? | ||
|
||
- Higher confidence in results (run tests with both!). | ||
- More features to come: | ||
- Test coverage metrics. | ||
- Automated property verification. | ||
- Test generation. | ||
- Contract symbolic execution. | ||
- ... your ideas?? | ||
|
||
Firefly Demo - Setup | ||
-------------------- | ||
|
||
Instructions from <https://www.npmjs.com/package/kevm-ganache-cli>: | ||
|
||
. . . | ||
|
||
### Install KEVM (once) | ||
|
||
**TODO**: Update release URL. | ||
|
||
```sh | ||
sudo apt install nodejs npm curl git | ||
curl --location 'https://github.com/kframework/evm-semantics/releases/download/v1.0.0-a47e4b2/kevm_1.0.0_amd64.deb' \ | ||
--output kevm_1.0.0_amd64.deb | ||
sudo apt install ./kevm_1.0.0_amd64.deb | ||
``` | ||
|
||
. . . | ||
|
||
### Install `npx` (once) | ||
|
||
```sh | ||
sudo npm install -g npx | ||
``` | ||
|
||
Firefly Demo - Run OpenZeppelin Tests | ||
------------------------------------- | ||
|
||
### Start `kevm-ganache-cli` | ||
|
||
```sh | ||
npx kevm-ganache-cli \ | ||
--gasLimit 0xfffffffffff \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000" \ | ||
--account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000" | ||
``` | ||
|
||
. . . | ||
|
||
### Run OpenZeppelin tests | ||
|
||
```sh | ||
git clone 'https://github.com/OpenZeppelin/openzeppelin-contracts.git' | ||
cd openzeppelin-contracts | ||
git checkout b8c8308 | ||
npm install | ||
npx truffle test test/token/ERC20/ERC20.test.js | ||
``` | ||
|
||
KEVM Extensions - Event Monitoring | ||
---------------------------------- | ||
|
||
Compile semantics with additional file `media/201908-trufflecon/kevm-ltl.md`. | ||
|
||
```k | ||
syntax LTLEvent ::= "overflow" | ||
// ------------------------------ | ||
rule <k> ADD W0 W1 ... </k> | ||
<events> EVENTS (.Set => SetItem(overflow)) </events> | ||
requires notBool overflow in EVENTS | ||
andBool W0 +Word W1 =/=Int W0 +Int W1 | ||
[priority(24)] | ||
syntax LTLEvent ::= "revert" | ||
// ---------------------------- | ||
rule <k> REVERT _ _ ... </k> | ||
<events> EVENTS (.Set => SetItem(revert)) </events> | ||
requires notBool revert in EVENTS | ||
[priority(24)] | ||
``` | ||
|
||
- Monitors built-in to the KEVM semantics as an extension. | ||
- Can build arbitrary LTL formula over the monitors. | ||
|
||
KEVM Extensions - LTL Model Checking | ||
------------------------------------ | ||
|
||
### Input file `addition.evm` | ||
|
||
```evm | ||
load { "gas" : 10000000 | ||
// Query: always ((~ overflow) \/ eventually revert) | ||
// , "code" : UNSAFEADD(100 , 100) // True | ||
// , "code" : UNSAFEADD(maxUInt256 , 100) // False | ||
// , "code" : SAFEADD(100 , 100) // True | ||
, "code" : SAFEADD(maxUInt256 , 100) // True | ||
} | ||
start | ||
``` | ||
. . . | ||
### Query | ||
```sh | ||
./kevm run --backend llvm media/201908-trufflecon/addition.evm -cLTLFORMULA='always (overflow -> eventually revert)' | ||
``` | ||
Truffle Firefly Plugin | ||
---------------------- | ||
- Developed with help from Truffle devs today as plugin! | ||
- Modified OpenZeppelin test-suite which links to `truffle-plugin-firefly`. | ||
```sh | ||
npx truffle run firefly SafeMath 'always (overflow -> eventually revert)' | ||
``` | ||
Oops, something went wrong.