Skip to content

Commit bd56a76

Browse files
jaisnancarolynzech
andauthored
Add kani script instructions to book (#135)
Simplify Kani instructions with the new kani script for users. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Carolyn Zech <[email protected]>
1 parent 977cf8b commit bd56a76

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

doc/src/general-rules.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
**Verification Target:** [Our repository](https://github.com/model-checking/verify-rust-std) is a fork of the original Rust repository,
66
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.
77
We will periodically update the `library/` folder to track newer versions of the [official Rust standard library](https://github.com/rust-lang/rust/).
8-
NOTE: This work is not officially affiliated, or endorsed by the Rust project or Rust Foundation.
8+
9+
**NOTE:** This work is not officially affiliated, or endorsed by the Rust project or Rust Foundation.
10+
911
**Challenges:** Each individual verification effort will have a
1012
tracking issue where contributors can add comments and ask clarification questions.
1113
You can find the list of [open challenges here](https://github.com/model-checking/verify-rust-std/labels/Challenge).

doc/src/tools/kani.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Create a local copy of the [model-checking fork](https://github.com/model-checki
5959
`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.
6060

6161

62-
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.
62+
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.
63+
This is just for the purpose of getting started, so you can insert it in a different (existing) file in the core library instead.
6364

6465
``` rust
6566
#[cfg(kani)]
@@ -84,22 +85,24 @@ pub mod verify {
8485
}
8586
```
8687

87-
### Step 2 - Run the Kani verify-std subcommand
88+
### Step 2 - Run the Kani script on the std library
8889

89-
To aid the Rust Standard Library verification effort, Kani provides a sub-command out of the box to help you get started.
90-
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:
90+
To aid the Rust Standard Library verification effort, Kani provides a script out of the box to help you get started.
91+
Run the following command in your local terminal from the verify repository root:
9192

9293
```
93-
kani verify-std -Z unstable-options "/path/to/library" --target-dir "/path/to/target" -Z function-contracts -Z mem-predicates
94+
./scripts/run-kani.sh --path .
9495
```
9596

96-
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.
97+
To pass kani arguments such as `--harness`, you can run the script with `--kani-args` and continue passing in all the necessary arguments:
9798

98-
- `"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`
99-
- `--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`
99+
```
100+
./scripts/run-kani.sh --path . --kani-args --harness alloc::layout::verify::check_array_i32 --output-format=terse
101+
```
102+
103+
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.
100104

101-
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.
102-
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)
105+
**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.
103106

104107
### Step 3 - Check verification result
105108

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

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

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

147-
Now you can write proof harnesses to verify specific functions in the library.
148-
The current convention is to keep proofs in the same module file of the verification target.
149-
To run Kani for an individual proof, use `--harness [harness_function_name]`.
150-
Note that Kani will batch run all proofs in the library folder if you do not supply the `--harness` flag.
151-
If Kani returns the error `no harnesses matched the harness filter`, you can give the full name of the harness.
152-
For example, to run the proof harness named `check_new` in `library/core/src/ptr/unique.rs`, use
153-
`--harness ptr::unique::verify::check_new`. To run all proofs in `unique.rs`, use `--harness ptr::unique::verify`.
150+
Now you can write proof harnesses to verify specific functions in the library.
151+
The current convention is to keep proofs in the same module file of the verification target.
152+
153+
To run Kani for an individual proof, use `--harness [harness_function_name]`.
154+
Note that Kani will batch run all proofs in the library folder if you do not supply the `--harness` flag.
155+
156+
If Kani returns the error `no harnesses matched the harness filter`, you can give the full name of the harness.
157+
For example, to run the proof harness named `check_new` in `library/core/src/ptr/unique.rs`, use
158+
`--harness ptr::unique::verify::check_new`. To run all proofs in `unique.rs`, use `--harness ptr::unique::verify`.
159+
154160
To find the full name of a harness, check the Kani output and find the line starting with `Checking harness [harness full name]`.
155161

156162
## More details

0 commit comments

Comments
 (0)