Skip to content

Commit

Permalink
merge with upstream/main
Browse files Browse the repository at this point in the history
  • Loading branch information
QinyuanWu committed Nov 7, 2024
2 parents 293a297 + 25ad12b commit 028ab6a
Show file tree
Hide file tree
Showing 552 changed files with 17,591 additions and 8,165 deletions.
4 changes: 3 additions & 1 deletion doc/src/general-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
**Verification Target:** [Our repository](https://github.com/model-checking/verify-rust-std) is a fork of the original Rust repository,
and we kept a copy of the Rust standard library inside the `library/` folder that shall be used as the verification target for all our challenges.
We will periodically update the `library/` folder to track newer versions of the [official Rust standard library](https://github.com/rust-lang/rust/).
NOTE: This work is not officially affiliated, or endorsed by the Rust project or Rust Foundation.

**NOTE:** This work is not officially affiliated, or endorsed by the Rust project or Rust Foundation.

**Challenges:** Each individual verification effort will have a
tracking issue where contributors can add comments and ask clarification questions.
You can find the list of [open challenges here](https://github.com/model-checking/verify-rust-std/labels/Challenge).
Expand Down
42 changes: 24 additions & 18 deletions doc/src/tools/kani.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Create a local copy of the [model-checking fork](https://github.com/model-checki
`assert`, `assume`, `proof` and [function-contracts](https://github.com/model-checking/kani/blob/main/rfc/src/rfcs/0009-function-contracts.md) such as `modifies`, `requires` and `ensures`) directly.


For example, insert this module into an existing file in the core library, like `library/core/src/hint.rs` or `library/core/src/error.rs` in your copy of the library. This is just for the purpose of getting started, so you can insert in any existing file in the core library if you have other preferences.
For example, insert this module into an existing file in the core library, like `library/core/src/hint.rs` or `library/core/src/error.rs` in your copy of the library.
This is just for the purpose of getting started, so you can insert it in a different (existing) file in the core library instead.

``` rust
#[cfg(kani)]
Expand All @@ -84,22 +85,24 @@ pub mod verify {
}
```

### Step 2 - Run the Kani verify-std subcommand
### Step 2 - Run the Kani script on the std library

To aid the Rust Standard Library verification effort, Kani provides a sub-command out of the box to help you get started.
Run the following command in your local terminal (Replace "/path/to/library" and "/path/to/target" with your local paths) from the verify repository root:
To aid the Rust Standard Library verification effort, Kani provides a script out of the box to help you get started.
Run the following command in your local terminal from the verify repository root:

```
kani verify-std -Z unstable-options "/path/to/library" --target-dir "/path/to/target" -Z function-contracts -Z mem-predicates
./scripts/run-kani.sh --path .
```

The command `kani verify-std` is a sub-command of the `kani`. This specific sub-command is used to verify the Rust Standard Library with the following arguments.
To pass kani arguments such as `--harness`, you can run the script with `--kani-args` and continue passing in all the necessary arguments:

- `"path/to/library"`: This argument specifies the path to the modified Rust Standard Library that was prepared earlier in the script. For example, `./library` or `/home/ubuntu/verify-rust-std/library`
- `--target-dir "path/to/target"`: This optional argument sets the target directory where Kani will store its output and intermediate files. For example, `/tmp` or `/tmp/verify-std`
```
./scripts/run-kani.sh --path . --kani-args --harness alloc::layout::verify::check_array_i32 --output-format=terse
```

The script `run-kani` installs the right version of Kani for you, builds it and then finally runs the verify-std sub-command of the `kani` with some default flags.

Apart from these, you can use your regular `kani-args` such as `-Z function-contracts`, `-Z stubbing` and `-Z mem-predicates` depending on your verification needs. If you run into a Kani error that says `Use of unstable feature`, add the corresponding feature with `-Z` to the command line.
For more details on Kani's features, refer to [the features section in the Kani Book](https://model-checking.github.io/kani/reference/attributes.html)
**NOTE:** This script may crash due to linking issues. If the script fails with an error message related to linking, link the new CBMC version, delete the `./kani_build` directory and re-run.

### Step 3 - Check verification result

Expand All @@ -122,7 +125,7 @@ You can specify a specific harness to be verified using the `--harness` flag.
For example, in your local copy of the verify repo, run the following command.

```
kani verify-std --harness harness_introduction -Z unstable-options "./library" --target-dir "/tmp" -Z function-contracts -Z mem-predicates
./scripts/run-kani.sh --kani-args --harness harness_introduction
```

This gives you the verification result for just `harness_introduction` from the aforementioned blob.
Expand All @@ -144,13 +147,16 @@ Verification Time: 0.01885804s
Complete - 1 successfully verified harnesses, 0 failures, 1 total.
```

Now you can write proof harnesses to verify specific functions in the library.
The current convention is to keep proofs in the same module file of the verification target.
To run Kani for an individual proof, use `--harness [harness_function_name]`.
Note that Kani will batch run all proofs in the library folder if you do not supply the `--harness` flag.
If Kani returns the error `no harnesses matched the harness filter`, you can give the full name of the harness.
For example, to run the proof harness named `check_new` in `library/core/src/ptr/unique.rs`, use
`--harness ptr::unique::verify::check_new`. To run all proofs in `unique.rs`, use `--harness ptr::unique::verify`.
Now you can write proof harnesses to verify specific functions in the library.
The current convention is to keep proofs in the same module file of the verification target.

To run Kani for an individual proof, use `--harness [harness_function_name]`.
Note that Kani will batch run all proofs in the library folder if you do not supply the `--harness` flag.

If Kani returns the error `no harnesses matched the harness filter`, you can give the full name of the harness.
For example, to run the proof harness named `check_new` in `library/core/src/ptr/unique.rs`, use
`--harness ptr::unique::verify::check_new`. To run all proofs in `unique.rs`, use `--harness ptr::unique::verify`.

To find the full name of a harness, check the Kani output and find the line starting with `Checking harness [harness full name]`.

## More details
Expand Down
90 changes: 50 additions & 40 deletions library/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion library/alloc/benches/binary_heap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BinaryHeap;

use rand::seq::SliceRandom;
use test::{black_box, Bencher};
use test::{Bencher, black_box};

#[bench]
fn bench_find_smallest_1000(b: &mut Bencher) {
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/benches/btree/map.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::BTreeMap;
use std::ops::RangeBounds;

use rand::seq::SliceRandom;
use rand::Rng;
use test::{black_box, Bencher};
use rand::seq::SliceRandom;
use test::{Bencher, black_box};

macro_rules! map_insert_rand_bench {
($name: ident, $n: expr, $map: ident) => {
Expand Down
3 changes: 2 additions & 1 deletion library/alloc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#![feature(iter_next_chunk)]
#![feature(repr_simd)]
#![feature(slice_partition_dedup)]
#![feature(strict_provenance)]
#![cfg_attr(bootstrap, feature(strict_provenance))]
#![cfg_attr(not(bootstrap), feature(strict_provenance_lints))]
#![feature(test)]
#![deny(fuzzy_provenance_casts)]

Expand Down
8 changes: 4 additions & 4 deletions library/alloc/benches/slice.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{mem, ptr};

use rand::distributions::{Alphanumeric, DistString, Standard};
use rand::Rng;
use test::{black_box, Bencher};
use rand::distributions::{Alphanumeric, DistString, Standard};
use test::{Bencher, black_box};

#[bench]
fn iterator(b: &mut Bencher) {
Expand Down Expand Up @@ -336,10 +336,10 @@ reverse!(reverse_u32, u32, |x| x as u32);
reverse!(reverse_u64, u64, |x| x as u64);
reverse!(reverse_u128, u128, |x| x as u128);
#[repr(simd)]
struct F64x4(f64, f64, f64, f64);
struct F64x4([f64; 4]);
reverse!(reverse_simd_f64x4, F64x4, |x| {
let x = x as f64;
F64x4(x, x, x, x)
F64x4([x, x, x, x])
});

macro_rules! rotate {
Expand Down
4 changes: 3 additions & 1 deletion library/alloc/benches/str.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test::{black_box, Bencher};
use test::{Bencher, black_box};

#[bench]
fn char_iterator(b: &mut Bencher) {
Expand Down Expand Up @@ -347,3 +347,5 @@ make_test!(rsplitn_space_char, s, s.rsplitn(10, ' ').count());

make_test!(split_space_str, s, s.split(" ").count());
make_test!(split_ad_str, s, s.split("ad").count());

make_test!(to_lowercase, s, s.to_lowercase());
Loading

0 comments on commit 028ab6a

Please sign in to comment.