Giter Site home page Giter Site logo

pointerbender / prusti-dev Goto Github PK

View Code? Open in Web Editor NEW

This project forked from viperproject/prusti-dev

0.0 0.0 0.0 550.71 MB

A static verifier for Rust, based on the Viper verification infrastructure.

Home Page: http://prusti.ethz.ch

License: Other

Shell 3.13% Rust 96.12% Python 0.62% Dockerfile 0.05% Nix 0.08%

prusti-dev's Introduction

Prusti

Test Deploy Test coverage Project chat

Prusti is a prototype verifier for Rust, built upon the Viper verification infrastructure.

By default Prusti verifies absence of integer overflows and panics by proving that statements such as unreachable!() and panic!() are unreachable. Overflow checking can be disabled with a configuration flag, treating all integers as unbounded. In Prusti, the functional behaviour of a function can be specified by using annotations, among which are preconditions, postconditions, and loop invariants. The tool checks them, reporting error messages when the code does not adhere to the provided specification.

Documentation

  • The user guide contains installation instructions, a guided tutorial and a description of various verification features.
  • The developer guide contains Prusti details intended to make the project more approachable for new contributors.

Do you still have questions? Open an issue or contact us on the Zulip chat.

Getting Prusti

The easiest way to try out Prusti is by using the "Prusti Assistant" extension for VS Code. See the requirements and the troubleshooting section in its readme.

Alternatively, if you wish to use Prusti from the command line there are three options:

  • Download the precompiled binaries for Ubuntu, Windows, or macOS x64 from a GitHub release.
  • Compile from the source code, by installing rustup, running ./x.py setup and then ./x.py build --release.
  • (unmaintained) Build a Docker image from this Dockerfile.

All three options provide the prusti-rustc and cargo-prusti programs that can be used analogously to, respectively, rustc and cargo build. For more detailed instructions, refer to the guides linked above.

Quick example

  1. Take the following program:
    /// A monotonically increasing discrete function, with domain [0, domain_size)
    trait Function {
      fn domain_size(&self) -> usize;
      fn eval(&self, x: usize) -> i32;
    }
    
    /// Find the `x` s.t. `f(x) == target`
    fn bisect<T: Function>(f: &T, target: i32) -> Option<usize> {
      let mut low = 0;
      let mut high = f.domain_size();
      while low < high {
        let mid = (low + high) / 2;
        let mid_val = f.eval(mid);
        if mid_val < target {
          low = mid + 1;
        } else if mid_val > target {
          high = mid;
        } else {
          return Some(mid)
        }
      }
      None
    }
  2. Run Prusti. You get the following error:
    error: [Prusti: verification error] assertion might fail with "attempt to add with overflow"
      --> example.rs:12:15
       |
    12 |     let mid = (low + high) / 2;
       |               ^^^^^^^^^^^^
    
    Verification failed
    
  3. Fix the buggy line with let mid = low + ((high - low) / 2);
  4. Run Prusti. Now the bisect function verifies.

Congratulations! You just proved absence of panics and integer overflows in the bisect function. To additionally prove that the result is correct (i.e. such that f(x) == target), see this example.

prusti-dev's People

Contributors

fpoli avatar vakaras avatar aurel300 avatar jonasalaif avatar dario23 avatar vl0w avatar bors[bot] avatar cmatheja avatar juliand665 avatar zgrannan avatar pointerbender avatar tillarnold avatar ani003 avatar gavinleroy avatar maxwell-yang-2001 avatar mlimbeck avatar kammola avatar fabianwolff avatar karlosss avatar pascal-huber avatar cedihegi avatar karenhong avatar frececroka avatar dependabot-preview[bot] avatar justinhuprime avatar jjurm avatar jm4ier avatar mohammadhossam avatar dependabot[bot] avatar patrick-6 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.