GithubHelp home page GithubHelp logo

isabella232 / dafny-sc-fmics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from consensys/dafny-sc-fmics

0.0 0.0 0.0 14 KB

Verification of Smart Contracts with Dafny – FMICS paper examples

License: Apache License 2.0

Dafny 100.00%

dafny-sc-fmics's Introduction

Verification examples

This repository contains examples of smart contracts specified and verified with Dafny.

How to check the proofs?

We have checked the proofs with Dafny 3.5.0. To mechanically check the proofs, it suffices to run the Dafny verifier on the contracts. We explain in this section how to do so.

Pre-requisites:

If you use the VsCode plugin, opening the *.dfy file should autoamtically start the verification process.

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

> dafny /dafnyVerify:1 /compile:0  filename.dfy
...

Dafny program verifier finished with 10 verified, 0 errors

For some examples, it is also possible to run a program (or test) and the command is:

> dafny /noVerify /compile:4 filename.dfy
...

This will compile (in memory) and run the Main method in filename.dfy.

Example: the Token contract.

To verify and run the Token contract versions in the terminal use the following commands:

> dafny /dafnyVerify:1 /compile:0 token/token.dfy 
...
> dafny /dafnyVerify:1 /compile:0 token/token-with-revert.dfy 
...
Dafny program verifier finished with 9 verified, 0 errors
> dafny /dafnyVerify:1 /compile:0 token/token-with-revert-external.dfy 
...
>dafny /noVerify:1 /compile:4 token/token-with-callback-example.dfy
Dafny program verifier did not attempt verification
Running...

This is an example of exploit of re-entrancy
Token K : TokenK created
Token K : TokenK mints 200
Contract TokenK total amount:200
c2.bal initially: 200
TokenK.transfer#1 from BadGuy2 for 200 to BadGuy1
TokenK notifies BadGuy1
BadGuy1 calls BadGuy2.help  gas left:7
BadGuy2 calls TokenK.transfer for 200 to BadGuy1 gas left:6
TokenK.transfer#2 from BadGuy2 for 200 to BadGuy1
TokenK notifies BadGuy1
BadGuy1 calls BadGuy2.help  gas left:4
BadGuy2 calls TokenK.transfer for 200 to BadGuy1 gas left:3
TokenK.transfer#3 from BadGuy2 for 200 to BadGuy1
TokenK notifies BadGuy1
BadGuy1 calls BadGuy2.help  gas left:1
BadGuy2 calls TokenK.transfer for 200 to BadGuy1 gas left:0
TokenK.transfer#4 reverting gas: 0
TokenK.transfer#3 completed
TokenK.transfer#2 completed
TokenK.transfer#1 completed
Contract TokenK total amount:200
c1.bal final: 600
c2.bal final: 0
c1.bal + c2.bal: 600
>

dafny-sc-fmics's People

Contributors

franck44 avatar

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.