Skip to content

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

License

Notifications You must be signed in to change notification settings

viperproject/prusti-dev

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

08c1e9e · Oct 22, 2023
Mar 21, 2023
Oct 18, 2022
Oct 19, 2023
Aug 29, 2022
Sep 19, 2023
Oct 22, 2023
Jun 26, 2023
Sep 27, 2023
Oct 22, 2023
Oct 22, 2023
Mar 31, 2023
Sep 4, 2023
Sep 19, 2023
Aug 22, 2023
May 23, 2023
Oct 22, 2023
Aug 2, 2023
Oct 22, 2023
Oct 22, 2023
Oct 22, 2023
Sep 19, 2023
Dec 21, 2022
Aug 22, 2023
Oct 5, 2023
Sep 15, 2023
Aug 22, 2023
Oct 22, 2023
Feb 6, 2023
Oct 22, 2023
Jun 4, 2021
Feb 16, 2022
Oct 22, 2023
Nov 13, 2022
Feb 10, 2021
Oct 22, 2023
Aug 11, 2023
Jun 4, 2021
Jul 19, 2019
Aug 10, 2023
Feb 17, 2021
Oct 22, 2022
Apr 27, 2021
Apr 27, 2021
Sep 19, 2023
Sep 6, 2023
Sep 27, 2023

Repository files navigation

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, 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 functions and external libraries 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.

Useful links

  • 💻 VS Code extension to use Prusti from your IDE.
  • 📖 User guide, containing installation instructions, a guided tutorial and a description of various verification features.
  • 🧰 Developer guide, meant for new contributors.
  • 📚 List of publications. To cite the Prusti verifier, please use this BibTeX entry.
  • ⚖️ License of the source code (Mozilla Public License Version 2.0, with exceptions).
  • 💬 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.