Skip to content

Commit

Permalink
Trufflecon - Presentations and demo files added (#425)
Browse files Browse the repository at this point in the history
* 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
ehildenb authored Aug 6, 2019
1 parent 31446e7 commit bb75ac3
Show file tree
Hide file tree
Showing 14 changed files with 744 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/src
/package/pkg
/package/src
/media/*.pdf
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pipeline {
sh '''
nprocs=$(nproc)
[ "$nprocs" -gt '6' ] && nprocs='6'
make test-proof -j"$nprocs"
make test-prove -j"$nprocs"
'''
}
}
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export LUA_PATH
defn java-defn ocaml-defn node-defn haskell-defn llvm-defn \
test test-all test-conformance test-slow-conformance test-all-conformance \
test-vm test-slow-vm test-all-vm test-bchain test-slow-bchain test-all-bchain \
test-proof test-klab-prove test-parse test-failure \
test-prove test-klab-prove test-parse test-failure \
test-interactive test-interactive-help test-interactive-run test-interactive-prove test-interactive-search test-interactive-firefly \
media media-pdf sphinx metropolis-theme
.SECONDARY:
Expand Down Expand Up @@ -448,7 +448,7 @@ test-bchain: $(quick_bchain_tests:=.run)
proof_specs_dir:=tests/specs
proof_tests=$(wildcard $(proof_specs_dir)/*/*-spec.k)

test-proof: $(proof_tests:=.prove)
test-prove: $(test_prove_specs:=.prove)
test-klab-prove: $(smoke_tests_prove:=.klab-prove)

# Parse Tests
Expand Down Expand Up @@ -497,7 +497,10 @@ media: sphinx media-pdf

### Media generated PDFs

media_pdfs:=201710-presentation-devcon3 201801-presentation-csf
media_pdfs := 201710-presentation-devcon3 \
201801-presentation-csf \
201905-exercise-k-workshop \
201908-trufflecon-workshop 201908-trufflecon-firefly

media/%.pdf: media/%.md media/citations.md
@echo "== media: $@"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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:

```sh
./.build/k/k-distribution/src/main/scripts/bin/k-configure-opam-dev
./deps/k/k-distribution/src/main/scripts/bin/k-configure-opam-dev
```

Finally, you can install repository specific dependencies and build the semantics:
Expand Down Expand Up @@ -146,7 +146,7 @@ On Arch, you'll also need `crypto++` package.
And you need to setup Rust:

```sh
.build/k/llvm-backend/src/main/native/llvm-backend/install-rust
./deps/k/llvm-backend/src/main/native/llvm-backend/install-rust
```

Additionally, you need to setup the remaining LLVM dependencies.
Expand Down
2 changes: 1 addition & 1 deletion kevm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ shopt -s extglob

kevm_dir="${KEVM_DIR:-.}"
build_dir="$kevm_dir/.build"
defn_dir="$build_dir/defn"
defn_dir="${KEVM_DEFN_DIR:-$build_dir/defn}"
lib_dir="$build_dir/local/lib"
k_release_dir="${K_RELEASE:-$kevm_dir/deps/k/k-distribution/target/release/k}"

Expand Down
142 changes: 142 additions & 0 deletions media/201905-exercise-k-workshop.md
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!
180 changes: 180 additions & 0 deletions media/201908-trufflecon-firefly.md
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)'
```
Loading

0 comments on commit bb75ac3

Please sign in to comment.