3 releases (breaking)
0.3.0 | Oct 27, 2024 |
---|---|
0.2.0 | Jul 30, 2024 |
0.1.1 | Jun 25, 2024 |
#464 in Math
1,139 stars & 21 watchers
240KB
6K
SLoC
Le marteau-pilon, forges et aciéries de Saint-Chamond, Joseph-Fortuné LAYRAUD, 1889
About
Creusot is a deductive verifier for Rust code. It verifies your code is safe from panics, overflows, and assertion failures. By adding annotations you can take it further and verify your code does the correct thing.
Creusot works by translating Rust code to WhyML, the verification and specification language of Why3. Users can then leverage the full power of Why3 to (semi)-automatically discharge the verification conditions!
See ARCHITECTURE.md for technical details.
Help and Discussions
If you need help using Creusot or would like to discuss, you can post on the discussions forum or join our Zulip chat!
Citing Creusot
If you would like to cite Creusot in academic contexts, we encourage you to use our ICFEM'22 publication.
Examples of Verification
To get an idea of what verifying a program with Creusot looks like, we encourage you to take a look at some of our test suite:
- Zeroing out a vector
- Binary search on Vectors
- Sorting a vector
- IterMut
- Normalizing If-Then-Else Expressions
More examples are found in creusot/tests/should_succeed.
Projects built with Creusot
- CreuSAT is a verified SAT solver written in Rust and verified with Creusot. It really pushes the tool to its limits and gives an idea of what 'use in anger' looks like.
- Another big project is in the works :)
Installing Creusot as a user
- Install
rustup
, to get the suitable Rust toolchain - Get
opam
, the package manager for OCaml - Clone the creusot repository,
then move into the
creusot
directory for the rest of the setup.$ git clone https://github.com/creusot-rs/creusot $ cd creusot
- Set up Why3 and Why3find. Create a local
opam
switch with why3:
This will build$ opam switch create -y . ocaml.4.14.1 $ eval $(opam env)
why3
,why3find
, and their ocaml dependencies in a local_opam
directory. - Build Creusot:
this will build the$ cargo install --path creusot-rustc $ cargo install --path cargo-creusot
cargo-creusot
andcreusot-rustc
executables and place them in~/.cargo/bin
. - Set up Creusot:
this will download additional solvers (Alt-Ergo, Z3, CVC4, CVC5) and configure Why3 to use them.$ cargo creusot setup install
Upgrading Creusot
- Enter the cloned Creusot git repository used previously to install Creusot
- Update Creusot's sources:
$ git pull
- Upgrade Why3 if needed:
$ eval $(opam env) $ opam update $ opam pin . -y
- Rebuild and reinstall Creusot:
$ cargo install --path creusot-rustc $ cargo install --path cargo-creusot
- Re-run Creusot's setup:
$ cargo creusot setup install
Verifying with Creusot and Why3
- To learn how to write code with creusot: guide
- To see the API of
creusot_contracts
(creusot's "standard library"): creusot_contracts API
Hacking on Creusot
See HACKING.md for information on the developer workflow for hacking on the Creusot codebase.
lib.rs
:
The "standard library" of Creusot.
To start using Creusot, you should always import that crate. The recommended way is to have a glob import:
use creusot_contracts::*;
Writing specifications
To start writing specification, use the requires
and ensures
macros:
use creusot_contracts::*;
#[requires(x < i32::MAX)]
#[ensures(result@ == x@ + 1)]
fn add_one(x: i32) -> i32 {
x + 1
}
For a more detailed explanation, see the guide.
Dependencies
~59KB