Giter Club home page Giter Club logo

eth-isabelle's Introduction

Formalization of Ethereum Virtual Machine in Lem

Build Status CircleCI

This repository contains

  • an EVM implementation in Lem lem/evm.lem
  • a Keccak-256 implementation in Lem lem/keccak.lem
  • a form of functional correctness defined in Lem lem/evmNonExec.lem
  • a relational semantics that captures the environment's nondeterministic behavior RelationalSem.thy
  • some example verified contracts in example
  • a parser that parses hex code and emits an Isabelle/HOL expression representing the program parser/hexparser.rb

When you see \<Rightarrow> in the source, try using the Isabelle2017 interface. There you see โ‡’ instead.

Lem?

Lem is a language that can be translated into Coq, Isabelle/HOL, HOL4, OCaml, HTML and LaTeX.

Prerequisites

  • Isabelle2017
  • lem
  • OCaml 4.02.3
  • opam 1.2.2
  • Some opam packages: use opam install ocamlfind batteries yojson bignum easy-format bisect_ppx ocamlbuild sha secp256k1
  • ECC-OCaml from mrsmkl
  • secp256k1
    • On Ubuntu Artful, apt install secp256k1-0 secp256k1-dev is enough
    • On older versions of Ubuntu, installation from the current master branch is necessary
    • configure option --enable-module-recovery is needed

How to read the proofs

First translate the Lem definitions into Isabelle/HOL:

$ make lem-thy

Then, use Isabelle2017 to open ./examples/AlwaysFail.thy. The prerequisite Isabelle/HOL files are automatically opened.

How to run VM tests and state tests

Make sure the tests submodule is cloned

$ git submodule init tests
$ git submodule update tests

Extract the OCaml definitions

$ make lem-ocaml

And move to tester directory.

$ cd tester

One way is to run the VM Test.

$ sh compile.sh
$ ./runVmTest.native

(When ./runVmTest.native takes an argument, it executes only the test cases whose names contain the argument as a substring.)

Another way is to run the VM Test and measure the coverage.

$ sh measure_coverage.sh

Moreover, it's possible to run Blockchain Tests.

$ ./runBlockchainTest.native

Makefile goals

  • make doc produces output/document.pdf as well as lem/*.pdf.
  • make lem-thy compiles the Lem sources into Isabelle/HOL
  • make lem-hol compiles the Lem sources into HOL4
  • make lem-coq; cd lem; make compiles the Lem sources into Coq (and then compiles the Coq sources)
  • make lem-pdf compiles some of the Lem sources into PDF through LaTeX
  • make all-isabelle checks all Isabelle/HOL sources (but not the ones compiled from Lem)
  • make does everything above
  • script/gen_coq.sh generates a distribution useful for Coq users

Links

eth-isabelle's People

Contributors

mbegel avatar mrsmkl avatar pirapira avatar seed avatar

Stargazers

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

Watchers

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

eth-isabelle's Issues

Allow annotations before JUMPDEST

Currently, when when an annotation appears before JUMPDEST, this breaks JUMPs to that destination. This issue keeps track of fixing this.

Try encoding a program as (pc => instruction) to see if it's more efficient

Currently an account's program is represented as a single list of instructions. With this representation I face a performance problem in Isabelle/HOL when the program has more than 100 instructions. Isabelle/HOL cannot display the intermediate goals within 10 minutes. This issue keeps track of implementing the program as a function from the program counter to an instruction. The hope is that the program is not going to be copied around and the intermediate goals stay small enough to display.

Interface for importing invariants for DELEGATECALL

We can reason about what happens during a CALL, using the invariant we establish. For DELEGATECALL, we need to import the invariant from somewhere else. This issue keeps track of designing and implementing an interface for that.

Decompose variable_env record in the performance critical paths

A while ago I attended a talk about implementing some complicated procedure in Isabelle/HOL the only thing I remember was "decompose records and pass the individual members in a long list of arguments". The speaker didn't want to do that but that was necessary for performance improvements. Apply this technique in ContractSem.thy.

Try relational semantics

This task keeps track of trying a relational version of program_sem and see if that makes the proof one line or not.

Optimize the size of the proof goals

Currently the sizes of the proof goals seem to grow rapidly when the program under verification is bigger. This issue keeps track of making the goals smaller.

Verify a pair of a precondition and a postcondition for a whole invocation

Currently RelationalSem.thy defines a predicate no_assertion_failure that uses an invariant. This issue keeps track of generalizing this predicate so that the precondition and the postcondition can be different. This would allow, for example, to prove that a contract does not change its status unless it is called by a particular address.

Fix the proof in Deed.thy

Currently Deed.thy tries to verify that the code of the account never changes but sometimes it becomes empty. This issue keeps track of fixing this problem by changing the statement.

Streamline the definition of `jump`

In the definition of jump in ContractSem.thy, a variable_env is copied into two subterms. This issue keeps track of streamlining the occurrences so that the variable_env does not need to be copied.

Verify programs with loops

The current approaches do not work for programs that contain loops. For verifying programs with loops we need

  1. a framework that composes Hoare triples
  2. the rule for loops in that Hoare logic
  3. proof of soundness of the Hoare logic with respect to the operational semantics
  4. an example verification of a program with loops

Performance issue around 500 bytes of program

When I try to write a proof about a ~500 byte proof, the simp tactic does not finish.

Things I can try:

  • write a more efficient parser in Isabelle/HOL (spent a few hours on it)
  • write an external parser in another language (try this next)
  • find an Isabelle/HOL command that forces some normalization

Optimize the speed of simplification

In AlwaysFails.thy it takes less than a second to execute one instruction symbolically, while in Deed.thy it takes a few minutes (#11). This issue keeps track of solving this performance problem.

  • compare the simplification trace in AlwaysFails.thy and in Deed.thy and identify if any superfluous rewriting is happening.
  • make sure the program is not parsed every time an instruction is executed

Remove `let` from the definitions

The let expression is not expanded by default, and it is dangerous to tell Isabelle/HOL to do so. This issue keeps track of cleaning ContractSem.thy file so that it does not contain let expressions.

Implement gas

Implement the gas mechanism so that out-of-gas happens. Also make GAS return the correct value.

Consider making return_result richer

Currently return_result record contains the balance of all accounts, then, conceptually speaking, the record should also contain the storage of the account under verification. This issue keeps track of answering this suggestion.

Fix the semantics of `selfdestruct`

After a contract destroys itself, currently, its account state does not change. The code should become empty and the balance should become zero.

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.