GithubHelp home page GithubHelp logo

nunofernandes-plight / bitml-maude Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitml-lang/bitml-maude

0.0 1.0 0.0 189 KB

License: GNU General Public License v3.0

Shell 5.68% Python 94.32%

bitml-maude's Introduction

bitml-maude

Model-checking verification of Bitml, a specification language for Bitcoin Smart Contracts.

Download Maude with Strategies support

Download the latest version of Maude from http://maude.sip.ucm.es/strategies/: this is an alpha version of Maude that supports the definition of rewriting strategies. See the link above for details.

Test that everything is working executing ./maude model-checker.maude /<path>/bitml.maude. The REPL starts and the output should be similar to this:

$ maude model-checker.maude bitml.maude
                     \||||||||||||||||||/
                   --- Welcome to Maude ---
                     /||||||||||||||||||\
           Maude alpha120+strat built: Jan 11 2019 12:00:00
            Copyright 1997-2018 SRI International
                   Fri Jan 11 11:35:46 2019
Maude> 

Note the version number alpha120+strat.

Structure

Modules tagged as (internal) are meant to be used only within the same file, not outside. Their name may change. Modules tagged as (external) are meant to be imported by other modules in other files. Their name should never change.

bitml-syntax.maude

Define the bitml syntax.

  • BITML-SORTS (internal)
  • BITML-SYNTAX-CONS (internal)
  • BITML-STREQ (internal)
  • BITML-SYNTAX (external)

bitml-aux.maude

Define some auxiliary operations. Depend on bitml-syntax.maude and define the module:

  • BITML-AUX (external)

bitml-predicate.maude

Define predicates evaluation. Depend on bitml-aux.maude and define the module:

  • BITML-PREDICATE-SAT (external)

bitml.maude

Define the abstract semantic of bitml and the rewriting strategy. Depend on bitml-predicate.maude and define the modules:

  • BITML-SEM (internal)
  • BITML (external)
  • BITML-STRAT (internal)
  • BITML-PREDS (internal)
  • BITML-CHECK (external)

Example

Start maude ./maude model-checker.maude /<path>/bitml.maude and type the following example:

mod Examples-LIQUIDITY is
    protecting BITML .

    ops A B C : -> Participant .
    op v : -> Value .
    ops a b : -> Secret .
    ops t t' N M : -> Nat .
    op LOTTERY : -> SemConfiguration .
    op LIQUID-LOTTERY : -> SemConfiguration .
    op S : Contract -> SemConfiguration .
    ops WIN WIN' : -> Contract .

    eq t = 10 .
    eq t' = 15 .
    eq N = 1 .
    eq M = 1 .

    *** lottery
    
    eq LOTTERY = S(WIN) .
    eq LIQUID-LOTTERY = S(WIN') .
    
    eq S(WIN:Contract) = 
        toSemConf
        < split(
            2 BTC ~> ( reveal b if const(0) <= | ref(b) | <= const(1) . withdraw B + after t : withdraw A )
            2 BTC ~> ( reveal a . withdraw A + after t : withdraw B )
            2 BTC ~> WIN:Contract
            ), 6 BTC > 'x
        | { A : a # N } 
        | { B : b # M } .

    eq WIN = reveal (a, b) if | ref(a) | == | ref(b) | . withdraw A
           + reveal (a, b) if | ref(a) | != | ref(b) | . withdraw B .

    eq WIN' = WIN
            + (after t' : reveal a . withdraw A)
            + (after t' : reveal b . withdraw B) .

    *** strategies

    *** A never locks her secrets
    eq strategy(S:SemConfiguration, A lock-reveal a:Secret) = false .

    *** A never locks her authorizations
    eq strategy(S:SemConfiguration, A lock D:GuardedContract in x:Name) = false .

    *** No one destroys a deposit
    ***eq strategy(S:SemConfiguration, A:Participant authorize-destroy-of x:Name) = false .

    *** A reveals any secret (default any participant reveals any secret)
    ***eq strategy(S:SemConfiguration, A reveal a:Secret) = true .

    *** B does not reveal any secret
    ***eq strategy(S:SemConfiguration, B reveal a:Secret) = false .

    *** No one reveal a secret
    ***eq strategy(S:SemConfiguration, A:Participant reveal a:Secret) = false .

    *** B authorizes any contract
    ***eq strategy(S:SemConfiguration, B authorize D:GuardedContract in y:Name) = true .

    *** No one authorize any contract
    ***eq strategy(S:SemConfiguration, A:Participant authorize D:Contract in y:Name) = false .
endm

smod Examples-LIQUIDITY-CHECK is
    protecting BITML-CHECK .
    including Examples-LIQUIDITY .
endsm

Model-check liquidity:

reduce in Examples-LIQUIDITY-CHECK : modelCheck(LOTTERY, <> contract-free, 'bitml) .           *** false
reduce in Examples-LIQUIDITY-CHECK : modelCheck(LIQUID-LOTTERY, <> contract-free, 'bitml) .    *** true
reduce in Examples-LIQUIDITY-CHECK : modelCheck(LIQUID-LOTTERY, []<> A has-deposit>= 4 BTC, 'bitml) .   *** true

bitml-maude's People

Contributors

natzei avatar stefanolande avatar

Watchers

 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.