8000 GitHub - ethers/eth2.0-dafny: Eth2.0 spec in Dafny
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ethers/eth2.0-dafny

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status License

made-for-VSCode

lemmas Checks

Overview

Objectives

The objective of this project is to write a formal specification of the Eth2.0 specification in the verification-aware programming language Dafny.

More specifically, our goals in this project are many-fold:

  1. Write a formal (non-ambiguous) specification of the Eth2.0 specification. This specification is written using pre/post-conditions using the Hoare logic style proof.
  2. Write an implementation for each function to demonstrate that the specification can be implemented, in other words, it is not inconsistent.
  3. Formally prove that our implementation satisfies the specification. The formal proof is provided in the form of mathematical proofs of lemmas written in Dafny.

To achieve this, we use the capabilities of the verification-aware programming language Dafny to write the specification, the implementation, and the proofs.

Expected Results

Dafny provides extensive support for automated reasoning leveraging the power of state-of-start automated reasoning engines (SMT-solvers). As a result, Dafny can assist in proving the lemmas that specify correctness. Moreover, as the lemmas are written as Dafny programs, they provide a non-ambiguous mathematical proof that the code is correct with respect to a specification. All the proofs can be mechanically verified using theorem provers.

Current State

We are gradually adding the specifications, implementations and proofs. Our current focus in on Phase 0 of the Eth2 specifications: SSZ, Merkleisation and Beacon chain.

Background & Context

The Eth2.0 specifications are rather complex. As a consequence bugs, glitches or inconsistencies can creep into the specification and the implementation code.

Testing and code peer reviews can help keeping the bugs count low. However, testing can find some bugs but in general cannot guarantee the absence of bugs (Edsger W. Dijkstra).

These bugs remain uncovered ... until they manifest, resulting in crashes. Worse, they can be exploited as security vulnerabilities. An example of critical vulnerability is the OutOfBounds exception where a non-existent index in an array is accessed. This is one of the most common zero day attacks, and can occur in heavily tested code bases e.g. in the web browser Chromium.

Related Work

Runtime Verification Inc. have reported some work on:

More recently, a security audit was performed by LeastAuthority. The code was manually reviewed and some potential security vulnerabilities highlighted.

Our work aims to complement the previous work by providing a thorough formal verification of the Eth2.0 phase 0 specifications.

Useful Resources

  • Eth2.0 resources, specifications and implementations.
  • Dafny, install and learn.
  • Other, K-framework resources.

How to check the proofs?

Using a Docker container

Pre-requisites:

  1. a working installation of Docker,
  2. a fork or clone of this repository.

A simple way to check the proofs is to use a pre-configured installation of Dafny on a Docker container.

On Unix-based system, cd to the root directory of your working copy of this repository.

/home/user1/ $ git clone git@github.com:PegaSysEng/eth2.0-dafny.git
/home/user1/ $ cd eth2.0-dafny
/home/user1/eth2.0-dafny $ 

The next commands will start a Docker container with Dafny pre-installed, and mount your local working directory as a volume in the Docker machine (this way you can access it from the running Docker machine):

/home/user1/eth2.0-dafny $ docker run -v /home/user1/eth2.0-dafny:/eth2.0-dafny -it franck44/linux-dafny /bin/bash
root@749938cb155d:/# cd eth2.0-dafny/
root@749938cb155d:/eth2.0-dafny# dafny /dafnyVerify:1 /compile:0 src/dafny/utils/MathHelpers.dfy 
Dafny 2.3.0.10506

Dafny program verifier finished with 13 verified, 0 errors
root@749938cb155d:/eth2.0-dafny# 

Install Dafny on your computer

Pre-requisites:

Assuming you have a running Dafny compiler, you may use the following command line to check a *.dfy file:

> dafny /dafnyVerify:1 /compile:0  /timeLimit:60 src/dafny/utils/MathHelpers.dfy
Dafny 2.3.0.10506

Dafny program verifier finished with 13 verified, 0 errors

The test folder contains some tests. The purpose of this directory is to demonstrate that we can extract an implementation and run it (indeed, once we have proved the code, there is no need to test it). To run the tests, you can issue the following command from the root directory (it collects all the files in the test folder, compile them and run them):

> ./scripts/runAllTests.sh

For an even better experience you may install VSCode and the Dafny plugin see our Daf 4B1E ny wiki.

About

Eth2.0 spec in Dafny

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0