Skip to content
High level KSpecification for the MCD System by Runtime Verification and Maker Foundation
Python Makefile Shell Dockerfile
Branch: master
Clone or download
ehildenb and iamchrissmith Initial assertions in emitted Solidity (#162)
* kmcd-prelude: dont generate exceptional Pot . join

* kmcd-prelude: take snapshots

* kmcd-prelude: allow GenSteps not in first position

* mcd-pyk: take snapshots before and after generated steps

* mcd-pyk: print out minimized state delta

* mcd-pyk, kmcd-driver, kmcd-props: less fragile labelling

* kmcd-preldue, mcd-pyk: handle GenStep, GenStepFailed, Exception

* mcd-pyk: initial extraction of assertions

* mcd-pyk: only rap in `address` for arguments

* mcd-pyk.py: initial changes to assertions

* update .expected files to include the new kmcd-snapshots

Co-authored-by: Chris Smith <1408372+iamchrissmith@users.noreply.github.com>
Latest commit 03b821e Feb 13, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
deps Update dependency: deps/k (#154) Feb 7, 2020
tests Initial assertions in emitted Solidity (#162) Feb 13, 2020
.gitignore Id solidity test output (#161) Feb 13, 2020
.gitmodules Deploy to github pages automatically on `master` (#26) Sep 11, 2019
Dockerfile Dockerfile: no need for ocaml/opam setup (#146) Jan 27, 2020
Jenkinsfile Fail early when violation detected (#145) Jan 28, 2020
LICENSE Publication cleanup (#131) Dec 18, 2019
Makefile
README.md Cleanup docs (#159) Feb 11, 2020
_config.yml Deploy to github pages automatically on `master` (#26) Sep 11, 2019
cat.md Same key rules for map accesses (#108) Nov 16, 2019
dai.md Generate random inputs from mcd-pyk script (#112) Nov 22, 2019
end.md Same key rules for map accesses (#108) Nov 16, 2019
flap.md unique names for bid types (#147) Jan 28, 2020
flip.md unique names for bid types (#147) Jan 28, 2020
flop.md
gem.md Randomly generated witnesses to 4 lucash attacks (#109) Nov 19, 2019
join.md Bytes witnesses of generated attacks (#111) Nov 20, 2019
jug.md Lucash flip end - fixes to semantics and new test case (#92) Nov 6, 2019
kmcd Makefile, kmcd: remove java backend (#133) Jan 10, 2020
kmcd-driver.md Initial assertions in emitted Solidity (#162) Feb 13, 2020
kmcd-prelude.md Initial assertions in emitted Solidity (#162) Feb 13, 2020
kmcd-props.md Initial assertions in emitted Solidity (#162) Feb 13, 2020
kmcd.md Factoring out properties (#104) Nov 13, 2019
mcd-pyk.py Initial assertions in emitted Solidity (#162) Feb 13, 2020
pot.md pot: add underflow check to Pot . exit (#141) Jan 16, 2020
spot.md Bytes witnesses of generated attacks (#111) Nov 20, 2019
vat.md Same key rules for map accesses (#108) Nov 16, 2019
vow.md Same key rules for map accesses (#108) Nov 16, 2019

README.md

KMCD - Multi-Collateral Dai (MCD) KSpecification

Useful Links

Structure

The semantics is broken into several sub-modules.

Utility Files

  • kmcd-driver - common functionality in all modules.
  • kmcd - union all sub-modules.
  • kmcd-props - statement of properties that we would like to hold for the model.
  • kmcd-prelude - random testing harness.

Accounting System

  • vat - tracks deposited collateral, open CDPs, and borrowed Dai.
  • pot - interest accumulation for saved Dai.
  • jug - stability fee collection.

Collateral

  • dai - Dai ERC20 token standard.
  • spot - price feed for collateral.
  • gem - abstract implementation of collateral.
  • join - plug collateral into MCD system.

Liquidation/Auction Houses

  • cat - forcible liquidation of an over-leveraged CDP.
  • vow - manage and trigger liquidations.
  • flap - surplus auctions (Vat Dai for sale, bid increasing Gem MKR).
  • flop - deficit auctions (Gem MKR for sale, lot decreasing Vat Dai).
  • flip - general auction (Vat Gem for sale, bid increasing Vat Dai, lot decreasing Vat Dai).

Global Settlement

  • end - close out all CDPs and auctions, attempt to re-distribute gems fairly according to internal accounting.

Building

After installing all the dependencies needed for K Framework, you can run:

make deps
make build -j4

If you are on Arch Linux, add K_BUILD_TYPE=Release to make deps, as the Debug and FastBuild versions do not work.

Whenever you update the K submodule (which happens regularly automatically on CI), you may need to do:

rm -rf deps
git submodule update --init --recursive
make deps
make build -j4

Running Simple Tests

In directory tests/, we have some example runs of the system. You can run on these simulations directly to get an idea of what the output of the system looks like.

./kmcd run --backend llvm tests/attacks/lucash-flip-end.mcd

If you want to run all the attack tests (and check their output), run:

make test-execution -j4

Running Random Tester

Environment Setup

Make sure that pyk library is on PYTHONPATH, and krun is on PATH:

export PYTHONPATH=./deps/k/k-distribution/target/release/k/lib
export PATH=./deps/k/k-distribution/target/release/k/bin:$PATH

mcd-pyk.py Usage

You can ask the random tester for help:

./mcd-pyk.py random-test --help

Then you can start the random tester running, with depth 100, up to 3000 times:

./mcd-pyk.py random-test 100 3000 &> random-test.out

Then you can watch random-test.out for assertion violations it finds (search for Violation Found).

Additionally, the option --emit-solidity is supported, which will make best-effort emissions of Solidity code:

./mcd-pyk.py random-test 100 3000 --emit-solidity &> random-test.out

This emitted Solidity code can be used for conformance testing the Solidity implementation.

Speed up with kserver

By running KServer while working with mcd-pyk.py, you will see about 4x the throughput in simulations. This basically keeps a "warmed up" JVM around, so that we don't have to start over each time.

To start the KServer run:

spawn-kserver kserver.log

And to stop the KServer, run:

stop-kserver

You can make sure that the KServer is being used by running tail -F kserver.log. As mcd-pyk.py is running, you should see entries like this being added:

NGSession 10: org.kframework.main.Main exited with status 0
NGSession 12: org.kframework.main.Main exited with status 0
NGSession 14: org.kframework.main.Main exited with status 0
NGSession 16: org.kframework.main.Main exited with status 0
You can’t perform that action at this time.