Giter Club home page Giter Club logo

verisol's Introduction

We are no longer actively maintaining the tool as of 2021

Build Status

VeriSol

VeriSol (Verifier for Solidity) is a Microsoft Research project for prototyping a formal verification and analysis system for smart contracts developed in the popular Solidity programming language. It is based on translating programs in Solidity language to programs in Boogie intermediate verification language, and then leveraging and extending the verification toolchain for Boogie programs. The following blog provides a high-level overview of the initial goals or VeriSol.

The following paper describes the design of VeriSol and application of smart contract verification for Azure Blockchain:

Formal Specification and Verification of Smart Contracts for Azure Blockchain, Yuepeng Wang, Shuvendu K. Lahiri, Shuo Chen, Rong Pan, Isil Dillig, Cody Born, Immad Naseer, https://arxiv.org/abs/1812.08829

INSTALL

Instructions for installing and running VeriSol can be found here.

VeriSol Code Contracts library

The code contract library VeriSolContracts.sol is present here. This allows adding specifications in the form of pre/post conditions, loop invariants, contract invariants, modifies clauses, and extending the assertion language with constructs such as old, sum, etc.

License

VeriSol is licensed under the MIT license.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

verisol's People

Contributors

cs0317 avatar ellab123 avatar garbervetsky avatar kferles avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar robertkowalski avatar rongpan avatar shenshan avatar shuvendu-lahiri avatar verabe avatar xinxingliu avatar yuepeng-wang avatar yxliang01 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  avatar  avatar  avatar  avatar

verisol's Issues

Supporting SdvDefectViewer based trace viewing

VeriSol currently targets ConcurrencyExplorer tool to view traces generated through Corral. Support option to view traces through SdvDefectViewer distributed as part of Windows Static Driver Verifier.

Support for 0 as an address

Currently, we have to express 0 as 0x0 to distinguish it from the 0 as integer. Perhaps some kind of context based inference (e.g. argument to address(0)) should promote this to an address.

Dynamic type assumption too strong

While translating a method Foo in a contract C, we put an assumption that the dynamic type of this is C. We need to include all subtypes declared in the program.

Dependencies as git submodules

To make installation and maintenance easier, it would be recommendable to include the project dependencies (i.e., Boogie, Corral, etc) as git submodules. It is important that each submodule refers to the the last commit that has been tested for this tool.

Upgrade the solc compiler from 0.4.24

There are various issues:

  1. bugs related to import in directory structure (per @cs0317)
  2. solc.exe does not build on mac properly

Once the regression script is up, we can switch over to newer compiler. All this would mean is to update the instructions.

Unknown form of function call

Unhandled Exception: System.SystemException: Unknown form of function call expr: uint256/address
at SolToBoogie.TransUtils.GetFuncNameFromFuncCallExpr(Expression expr)

Examples:
uint8 public decimals = 18;
...
totalSupply = 200000000 * 10 ** uint256(decimals);

_transfer (msg.sender, address(this), totalSupply);
...
function _transfer(address _from, address _to, uint _value) internal {

Supporting tuples

pragma solidity ^0.4.24;
contract Tuple {
function testTuple() public pure{
(uint a, uint b) = (1, 3);
assert (a == 1);
assert (b == 3);
}
}

Initialize Scalar state variables in constructors

pragma solidity ^0.4.24;

contract A {
     uint x;
     int128 x128;
     string y;
     address z;
     bool w;

     constructor() {
         assert(x == 0);
         assert(x128 == 0);
         assert(z == 0x0);
         assert(!w);

         string memory yval = "";
         bytes32 a = keccak256(bytes(y));
         bytes32 b = keccak256(bytes(yval));
         assert(a == b);

         y = "aa";
         a = keccak256(bytes(y));
         assert(a != b);



     }
}

Support for keccak256

It is fairly common to use keccak256 to compare strings:

return keccak256(string1) == keccak256(string2);

Missing information about Dependencies folder

The script setup_windows.cmd and run_verisol_win.cmd refer to a folder VERISOL_DEPENDENCIES_DIR which seems to be "\verisol_dependencies".
However, there is no such folder in the repository and no information about what files should be included there.

Nested index expressions don't work in calls

NestedArray.sol in regressions.

pragma solidity ^0.4.24;

contract B{
   function foo() returns (uint) {return 33;}
}

contract A {
   B[] a;
   constructor() public {
        B b = new B();
        a.push(b);
        assert (a[0].foo() == 33);       
   }
}

Boogie syntax error on return expression statements

The translated Boogie program has syntax error on return expression statements. One simple example is

contract C {
    function foo() returns (uint a) {
        return 1;
    }
}

The bug is triggered when return parameters are named. Instead of setting a to 1, the translator emits __ret := 1 but variable __ret is not defined.

Also, for return statements with expressions, the translator fails to emit "return" after the assignment, which is problematic if the return statement is not at the end of the function body.

Mappings and implicit constructors

VeriSol would crash for the following example:

Unhandled Exception: System.ArgumentNullException: Value cannot be null. This was masked by the bug for missing constructors. For the case of an implicit constructor, we need to update "currentFunction" inside the implementation, as it is null, when trying to add some initialization code. @rongpan @Yuepeng-Wang

pragma solidity ^0.4.24;

contract Mapping {

    mapping (string => uint) m;

    function test() public {
        m["aa"] = 11;
        m["bb"] = 21;
        assert (m["aa"] == 11);
        assert (m["bb"] == 21);
    }

}

Unsupported elementary types

Unhandled Exception: System.SystemException: Unknown elementary type name: bytes32/bytes/uint64/uint16/uint8
at SolToBoogie.TransUtils.GetBoogieTypeFromSolidityTypeName(TypeName type)

Power binary operator not supported

a**b is not supported

This code:
`pragma solidity ^0.4.24;

contract Power {
function test1() public {
uint a = 2**3-1;
assert (a == 7);
}
}`

yield the following exception: Unhandled Exception: System.SystemException: Unknown binary operator: **
at SolToBoogie.ProcedureTranslator.Visit(BinaryOperation node) in .\verisol\Sources\SolToBoogie\ProcedureTranslator.cs:line 1866

Essentially, the function Convert.ToInt32 cannot handle "2**32-1".

Line number when VeriSol crashes during Boogie translation

Today, VeriSol just prints the error message

Unhandled Exception: System.SystemException: Unknown form of function call expr: address
when it crashes, without providing any hint of which line number or AST element being processed.

pragma solidity ^0.4.24;
contract A {
    address a;   
    constructor() public
    {
        a = address(0);
    }
}

Nested new, cast not handled

pragma solidity ^0.4.24;
contract A{
     uint x;
     constructor() {
          x = 33;
     }
     function getX() view returns (uint) {
          return x;
     }
}
contract B{

      A[] aa;
      constructor() {
          aa.push(new A());
          assert(aa[0].getX() == 33);
      }
}

Need support for integer constant for function argument

In the following code, foo(1) causes an exception in InferFunctionSignature because the type "int_const 1" is not supported.

pragma solidity ^0.4.24;
contract PublicPreviewMembers {
    constructor() public {      
          bool tmp= foo(1);  
    }

    function foo(uint x) internal returns (bool) {
           return true;
   }
}

modifier with invocations

A modifier invoking a helper function fails to to parse.
The error seems to be related to not having the field currentContract instantiated.

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.ContainsKey(TKey key)
at SolToBoogie.TranslatorContext.HasEventNameInContract(ContractDefinition contract, String eventName) in .\verisol\Sources\SolToBoogie\TranslatorContext.cs:line 279
at SolToBoogie.ProcedureTranslator.Visit(FunctionCall node) in C:\Users\diegog\Source\Repos\verisol\Sources\SolToBoogie\ProcedureTranslator.cs:line 1254

pragma solidity ^0.4.24; contract ModifierFunc { function isValid(uint id) public view returns (bool) { return (id > 0); } modifier valid(uint id) { require(isValid(id), "id is not valid"); // this invocation produces an exception _; } }

Support for multiple return values

The tool cannot support returning multiple values. For example,

    function foo() public returns (uint r1, uint r2) {
        return (1, 2);
    }

    function bar() public {
        uint a;
        uint b;
        (a, b) = foo();
        assert (a == 1);
        assert (b == 2);
    }

Getters for public state variables

Verisol crashes:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

since it is unable to find the function x() inside A.

pragma solidity ^0.4.24;

contract A {
    address public x;
}

contract B {
    A a;
    function Foo() public {
        a = new A();
        address y = a.x();
    }
}

Common ArgumentNullException

System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.get_Item(TKey key)

Happens in:
file: ProcedureTranslator.cs
method: CreateDistinctArrayMappingAddress()
line: functionToLocalVarsMap[currentFunction].Add(tmpVar);

Example:
Test/regressions/LoopContinue.sol

Returning values into state variables yields bad boogie program

contract A {
    uint public y;
    function helper() private view returns (uint) {return 1;}
    constructor(A a) {y = helper(); assert (y == 1);}
}

generates ill-formed boogie program since assignment to y is a map assignment, and Boogie only allows assigning to scalars in a call return. This has to be broken up into a temporary.

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.