Git Product home page Git Product logo

k-dss's Introduction

K-DSS: K Specification of Multi-Collateral Dai

This repo contains the formal specification and verification of multicollateral dai. The behavior of the contracts is specified in a literate format at dss.md, which generates a series of reachability claims defining succeeding and reverting behavior for each function of each contract. These reachability claims are then tested against KEVM.

Installation and Running

Setup Solidity Compiler and Dapp Tools

First you'll need to install the Nix packager.

curl -L https://nixos.org/nix/install | sh

Then you can install the Solidity compiler:

nix-env -f https://github.com/dapphub/dapptools/archive/master.tar.gz -iA solc-static-versions

And finally, install the DappHub toolkit.

curl https://dapp.tools/install | sh

Setup KLab and KEVM

Using external install of KLab/KEVM:

  • Follow the install instructions of KLab, including following the instructions for setting up KEVM included there.
  • Make sure that the bin directory inside the KLab repo is on PATH here.
  • Make sure that KLAB_EVMS_PATH is set as instructed if you are building KEVM from source (not needed if installed from package).

From-source builds in submodule:

If you want to build KEVM and KLab from source, you can:

  • Install the system dependencies of KEVM and of KLab.

  • Make sure that PATH is setup to include $(pwd)/deps/klab/bin.

  • Make sure that KLAB_EVMS_PATH is setup to include $(pwd)/deps/evm-semantics.

  • Run the following:

    git submodule update --init --recursive
    touch include.mak
    make klab dapp
    make include.mak -B
    make kevm -j3

Running the Proofs

To run all the proofs, you can use the prove target in the Makefile:

make prove -j8

You can optionally override the KLAB variable to set timeouts on each proof:

make prove -j12 KLAB='timeout 300 klab'

A common strategy is to run with a small timeout first, and then a much larger timeout:

make prove -j12 -k KLAB='timeout 300 klab'
make prove -j8     KLAB='timeout 7200 klab'

Make sure to adjust the parallelism (-jNNN) option as appropriate for the running machine.

Running Individual Proofs

You may use the Makefile to do several things (for a given proof SPEC):

  • make out/built/SPEC: Prove any dependencies of SPEC and then construct the specification for SPEC.
  • make out/accept/SPEC: Additionally prove the specification SPEC itself.
  • make out/gas/SPEC.raw: Additionally extract a pretty-formatted string with the <gas> expression for SPEC.
  • make out/accept/SPEC.dump: Prove SPEC (after dependencies) and dump data needed for KLab debugger.
  • make SPEC.klab-view: Open the proof of SPEC in the KLab debugger, assumes you have already dumped needed debug data.

Repository Information

ACT Specification Format

The format used in dss.md provides a concise way of specifying the behavior of a contract method. See act-mode for a simple emacs major mode for .act specs.

Let's break down the specification of the behavior of the function heal in the contract Vat:

behaviour heal of Vat
interface heal(bytes32 u, bytes32 v, int256 rad)

types

    Can   : uint256
    Dai_v : uint256
    Sin_u : uint256
    Debt  : uint256
    Vice  : uint256

storage

    #Vat.wards(CALLER_ID) |-> Can
    #Vat.dai(v)           |-> Dai_v => Dai_v - rad
    #Vat.sin(u)           |-> Sin_u => Sin_u - rad
    #Vat.debt             |-> Debt  => Debt - rad
    #Vat.vice             |-> Vice  => Vice - rad

iff

    Can == 1

iff in range uint256

    Dai_v - rad
    Sin_u - rad
    Debt - rad
    Vice - rad

This snippet of code will generate two reachability claims, Vat_heal_succ_pass_rough.k and Vat_heal_fail_rough.k. Both of these claims will refer to the bytecode of the contract Vat and use the function signature of heal(bytes32,bytes32,int256) as the first 4 bytes of calldata (keeping the rest of the calldata abstract). In the success spec, the conditions under the iff headers are postulated, while in the fail spec their negation is.

The interesting part of this particular function happens under the storage header. The meaning of the line #Vat.dai(v) |-> Dai_v => Dai_v - rad is that in the success case, the value at the storage location which we call #Vat.dai(v) will be updated from Dai_v to Dai_v - rad.

To prove this reachability claim, the K prover explores all possible execution paths starting from the precondition (whats on the left hand side of a =>) and the claim is proven if they all end in a state satisfying the postcondition (right hand side of the =>).

More information about how the K prover and the K Framework in general works can be found at Semantics-Based Program Verifiers for All Languages. A detailed description of the semantics of EVM defined in K is given in KEVM: A Complete Semantics of the Ethereum Virtual Machine.

License

All applicable work in this repository is licensed under AGPL-3.0. Authors:

  • Lev Livnev
  • Denis Erfurt
  • Martin Lundfall
  • Everett Hildenbrandt

k-dss's People

Contributors

andy8052 avatar ehildenb avatar endorphin avatar gbalabasquer avatar hermetic-himbo avatar icetan avatar kmbarry1 avatar livnev avatar mhhf avatar mrchico avatar nanexcool avatar rainbreak avatar wilfredta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

k-dss's Issues

KEVM Upgrade Path

Overall goal: Want to get Maker KLab pointed a relatively recent version of KEVM, get things working (maybe 98% of the proofs), then turn on auto-updates of KEVM.

Inevitable Changes

  • Point CI at Kurt's KLab fork.
  • Pin a version of Z3. (4.6.0 or 4.8.6).
  • Run makerdao/k-dss with new CI setup (done?).
  • Get regression test merged into KEVM master (with paired down rules file and smt prelude).

Changes we need to actually check for

  • Change the way that memory specs are generated (check with Daejun on that).
  • Use paired down rules file and smt prelude on fork of KLab.
  • Updating to latest KEVM master.
  • Move all lemmas out of KLab to k-dss repo.
  • Use version of KEVM pegged in k-dss repo
  • Auto-update of KEVM submodule of Maker KLab.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.