Skip to content

Commit 50faa97

Browse files
jaisnancarolynzech
andauthored
Improve documentation with links and additional steps (model-checking#90)
Minor changes to documentation to clarify some confusion and make it more accessible. Related to :- model-checking#85 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 1300d8a commit 50faa97

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

doc/src/tools/kani.md

+48-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Kani is designed to prove safety properties in your code as well as
55
the absence of some forms of undefined behavior. It uses model checking under the hood to ensure that
66
Rust programs adhere to user specified properties.
77

8-
You can find more information about how to install in [this section of the Kani book](https://model-checking.github.io/kani/install-guide.html).
8+
You can find more information about how to install in [the installation section of the Kani book](https://model-checking.github.io/kani/install-guide.html).
99

1010
## Usage
1111

@@ -27,7 +27,8 @@ fn harness() {
2727
let a = kani::any::<i32>();
2828
let b = kani::any::<i32>();
2929
let result = abs_diff(a, b);
30-
kani::assert(result >= 0, "Result should always be more than 0");}
30+
kani::assert(result >= 0, "Result should always be more than 0");
31+
}
3132
```
3233

3334
Running the command `cargo kani` in your cargo crate will give the result
@@ -46,29 +47,27 @@ Verification failed for - harness
4647
Complete - 0 successfully verified harnesses, 1 failures, 1 total.
4748
```
4849

50+
For a more detailed tutorial, you can refer to the [tutorial section of the Kani book](https://model-checking.github.io/kani/kani-tutorial.html).
4951

5052
## Using Kani to verify the Rust Standard Library
5153

52-
To aid the Rust Standard Library verification effort, Kani provides a sub-command out of the box to help you get started.
54+
Here is a short tutorial of how to use Kani to verify proofs for the standard library.
5355

54-
### Step 1
56+
### Step 1 - Add some proofs to your copy of the model-checking std
5557

56-
Modify your local copy of the Rust Standard Library by writing proofs for the functions/methods that you want to verify.
58+
Create a local copy of the [model-checking fork](https://github.com/model-checking/verify-rust-std) of the Rust Standard Library. The fork comes with Kani configured, so all you'll need to do is to call Kani's building-block APIs (such as
59+
`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.
5760

58-
For example, insert this short blob into your copy of the library. This blob imports the building-block APIs such as
59-
`assert`, `assume`, `proof` and [function-contracts](https://github.com/model-checking/kani/blob/main/rfc/src/rfcs/0009-function-contracts.md) such as `proof_for_contract` and `fake_function`.
61+
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.
6062

6163
``` rust
62-
#[cfg(kani)]
63-
kani_core::kani_lib!(core);
64-
6564
#[cfg(kani)]
6665
#[unstable(feature = "kani", issue = "none")]
6766
pub mod verify {
6867
use crate::kani;
6968

7069
#[kani::proof]
71-
pub fn harness() {
70+
pub fn harness_introduction() {
7271
kani::assert(true, "yay");
7372
}
7473

@@ -84,21 +83,24 @@ pub mod verify {
8483
}
8584
```
8685

87-
### Step 2
86+
### Step 2 - Run the Kani verify-std subcommand
8887

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

91-
`kani verify-std -Z unstable-options "path/to/library" --target-dir "/path/to/target" -Z function-contracts -Z stubbing`.
91+
```
92+
kani verify-std -Z unstable-options "/path/to/library" --target-dir "/path/to/target" -Z function-contracts -Z mem-predicates
93+
```
9294

9395
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.
9496

95-
- `"path/to/library"`: This argument specifies the path to the modified Rust Standard Library that was prepared earlier in the script.
96-
- `--target-dir "path/to/target"`: This optional argument sets the target directory where Kani will store its output and intermediate files.
97+
- `"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`
98+
- `--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`
9799

98100
Apart from these, you can use your regular `kani-args` such as `-Z function-contracts` and `-Z stubbing` depending on your verification needs.
99101
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)
100102

101-
### Step 3
103+
### Step 3 - Check verification result
102104

103105
After running the command, you can expect an output that looks like this:
104106

@@ -112,6 +114,35 @@ Verification Time: 0.017101772s
112114
Complete - 2 successfully verified harnesses, 0 failures, 2 total.
113115
```
114116

117+
### Running on a specific harness
118+
119+
You can specify a specific harness to be verified using the `--harness` flag.
120+
121+
For example, in your local copy of the verify repo, run the following command.
122+
123+
```
124+
kani verify-std --harness harness_introduction -Z unstable-options "./library" --target-dir "/tmp" -Z function-contracts -Z mem-predicates
125+
```
126+
127+
This gives you the verification result for just `harness_introduction` from the aforementioned blob.
128+
129+
```
130+
RESULTS:
131+
Check 1: verify::harness_introduction.assertion.1
132+
- Status: SUCCESS
133+
- Description: "yay"
134+
- Location: library/core/src/lib.rs:479:9 in function verify::harness_introduction
135+
136+
137+
SUMMARY:
138+
** 0 of 1 failed
139+
140+
VERIFICATION:- SUCCESSFUL
141+
Verification Time: 0.01885804s
142+
143+
Complete - 1 successfully verified harnesses, 0 failures, 1 total.
144+
```
145+
115146
## More details
116147

117148
You can find more information about how to install and how you can customize your use of Kani in the

0 commit comments

Comments
 (0)