Skip to content

Commit 3cab463

Browse files
committed
Merge remote-tracking branch 'origin/main' into layout-harnesses
2 parents e1c598c + 149f6dd commit 3cab463

File tree

265 files changed

+11144
-3532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+11144
-3532
lines changed

.github/TOOL_REQUEST_TEMPLATE.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
_The following form is designed to provide information for your tool that should be included in the effort to verify the Rust standard library. Please note that the tool will need to be **supported** if it is to be included._
2+
3+
## Tool Name
4+
_Please enter your tool name here._
5+
6+
## Description
7+
_Please enter a description for your tool and any information you deem relevant._
8+
9+
## Tool Information
10+
11+
* [ ] Does the tool perform Rust verification?
12+
* [ ] Does the tool deal with *unsafe* Rust code?
13+
* [ ] Does the tool run independently in CI?
14+
* [ ] Is the tool open source?
15+
* [ ] Is the tool under development?
16+
* [ ] Will you or your team be able to provide support for the tool?
17+
18+
## Licenses
19+
_Please list the license(s) that are used by your tool, and if to your knowledge they conflict with the Rust standard library license(s)._
20+
21+
## Steps to Use the Tool
22+
23+
1. [First Step]
24+
2. [Second Step]
25+
3. [and so on...]
26+
27+
## Artifacts
28+
_If there are noteworthy examples of using the tool to perform verificaiton, please include them in this section.Links, papers, etc._
29+
30+
## CI & Versioning
31+
_Please describe how you version the tool and how it will be supported in CI pipelines._

.github/pull_requests.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ members = [
99
"remi-delmas-3000",
1010
"qinheping",
1111
"tautschnig",
12-
"jaisnan"
12+
"jaisnan",
13+
"patricklam",
14+
"ranjitjhala",
15+
"carolynzech"
1316
]

.github/workflows/pr_approval.yml

-62
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@ name: Check PR Approvals
77
on:
88
pull_request_review:
99
types: [submitted]
10-
workflow_dispatch:
11-
12-
# Without these permissions, we get a 403 error from github
13-
# for trying to modify the pull request for newer project.
14-
# Source: https://stackoverflow.com/a/76994510
15-
permissions: write-all
1610

1711
jobs:
1812
check-approvals:
19-
if: github.event.review.state == 'APPROVED' || github.event_name == 'workflow_dispatch'
2013
runs-on: ubuntu-latest
2114
steps:
2215
- name: Checkout repository
@@ -51,22 +44,6 @@ jobs:
5144
pull_number = context.issue.number;
5245
}
5346
54-
// Get PR files
55-
const files = await github.rest.pulls.listFiles({
56-
owner,
57-
repo,
58-
pull_number
59-
});
60-
61-
const relevantPaths = ['library/', 'doc/src/challenges/'];
62-
const isRelevantPR = files.data.some(file =>
63-
relevantPaths.some(path => file.filename.startsWith(path))
64-
);
65-
66-
if (!isRelevantPR) {
67-
console.log('PR does not touch relevant paths. Exiting workflow.');
68-
return;
69-
}
7047
7148
// Get parsed data
7249
try {
@@ -117,45 +94,6 @@ jobs:
11794
text: `Approvers: ${Array.from(approvers).join(', ')}\nRequired Approvers: ${requiredApprovers.join(', ')}`
11895
};
11996
120-
// Get PR details
121-
const pr = await github.rest.pulls.get({
122-
owner,
123-
repo,
124-
pull_number
125-
});
126-
127-
// Create or update check run
128-
const checkRuns = await github.rest.checks.listForRef({
129-
owner,
130-
repo,
131-
ref: pr.data.head.sha,
132-
check_name: checkName
133-
});
134-
135-
// Reuse the same workflow everytime there's a new review submitted
136-
// instead of creating new workflows. Better efficiency and readability
137-
// as the number of workflows is kept to a minimal number
138-
if (checkRuns.data.total_count > 0) {
139-
await github.rest.checks.update({
140-
owner,
141-
repo,
142-
check_run_id: checkRuns.data.check_runs[0].id,
143-
status: 'completed',
144-
conclusion,
145-
output
146-
});
147-
} else {
148-
await github.rest.checks.create({
149-
owner,
150-
repo,
151-
name: checkName,
152-
head_sha: pr.data.head.sha,
153-
status: 'completed',
154-
conclusion,
155-
output
156-
});
157-
}
158-
15997
if (conclusion === 'failure') {
16098
core.setFailed(`PR needs at least ${requiredApprovals} total approvals and 2 required approvals. Current approvals: ${approvers.size}, Required approvals: ${requiredApprovals}`);
16199
}

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
This repository is a fork of the official Rust programming
88
language repository, created solely to verify the Rust standard
99
library. It should not be used as an alternative to the official
10-
Rust releases.
10+
Rust releases. The repository is tool agnostic and welcomes the addition of
11+
new tools.
1112

1213
The goal is to have a verified [Rust standard library](https://doc.rust-lang.org/std/) and prove that it is safe.
1314
1. Contributing to the core mechanism of verifying the rust standard library
@@ -36,12 +37,14 @@ See [SECURITY](https://github.com/model-checking/kani/security/policy) for more
3637
## License
3738

3839
### Kani
39-
4040
Kani is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
4141
See [LICENSE-APACHE](https://github.com/model-checking/kani/blob/main/LICENSE-APACHE) and [LICENSE-MIT](https://github.com/model-checking/kani/blob/main/LICENSE-MIT) for details.
4242

4343
## Rust
44-
4544
Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
4645

4746
See [the Rust repository](https://github.com/rust-lang/rust) for details.
47+
48+
## Introducing a New Tool
49+
50+
Please use the [template available in this repository](.github/TOOL_REQUEST_TEMPLATE.md) to introduce a new verification tool.

doc/book.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ build-dir = "../book"
1212
site-url = "/verify-rust-std/"
1313
git-repository-url = "https://github.com/model-checking/verify-rust-std"
1414
edit-url-template = "https://github.com/model-checking/verify-rust-std/edit/main/doc/{path}"
15+
no-section-label = true
1516

1617
[output.html.playground]
1718
runnable = false

doc/src/SUMMARY.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
---
1414

1515
- [Challenges](./challenges.md)
16-
- [Core Transmutation](./challenges/0001-core-transmutation.md)
17-
- [Memory safety of core intrinsics](./challenges/0002-intrinsics-memory.md)
18-
- [Pointer Arithmetic](./challenges/0003-pointer-arithmentic.md)
19-
- [Memory safety of BTreeMap's `btree::node` module](./challenges/0004-btree-node.md)
20-
- [Inductive data type](./challenges/0005-linked-list.md)
21-
- [Contracts for SmallSort](./challenges/0008-smallsort.md)
22-
- [Memory safety of String](./challenges/0010-string.md)
16+
- [1: Verify core transmuting methods](./challenges/0001-core-transmutation.md)
17+
- [2: Verify the memory safery of core intrinsics using raw pointers](./challenges/0002-intrinsics-memory.md)
18+
- [3: Verifying Raw Pointer Arithmetic Operations](./challenges/0003-pointer-arithmentic.md)
19+
- [4: Memory safety of BTreeMap's `btree::node` module](./challenges/0004-btree-node.md)
20+
- [5: Verify functions iterating over inductive data type: `linked_list`](./challenges/0005-linked-list.md)
21+
- [6: Safety of `NonNull`](./challenges/0006-nonnull.md)
22+
- [8: Contracts for SmallSort](./challenges/0008-smallsort.md)
23+
- [9: Safe abstractions for `core::time::Duration`](./challenges/0009-duration.md)
24+
- [10: Memory safety of String](./challenges/0010-string.md)
25+
- [11: Safety of Methods for Numeric Primitive Types](./challenges/0011-floats-ints.md)
26+
- [12: Safety of `NonZero`](./challenges/0012-nonzero.md)
27+
28+

doc/src/challenges/0001-core-transmutation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Challenge 1: Verify `core` transmuting methods
22

33
- **Status:** Open
4-
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/19)
4+
- **Tracking Issue:** [#19](https://github.com/model-checking/verify-rust-std/issues/19)
55
- **Start date:** 2024-06-12
66
- **End date:** 2024-12-10
77

doc/src/challenges/0002-intrinsics-memory.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Challenge 2: Verify the memory safery of core intrinsics using raw pointers
22

33
- **Status:** Open
4-
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/16)
4+
- **Tracking Issue:** [#16](https://github.com/model-checking/verify-rust-std/issues/16)
55
- **Start date:** *24/06/12*
66
- **End date:** *24/12/10*
77

doc/src/challenges/0003-pointer-arithmentic.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- **Status:** Open
44
- **Solution:**
5-
- **Tracking Issue:** <https://github.com/model-checking/verify-rust-std/issues/21>
5+
- **Tracking Issue:** [#76](https://github.com/model-checking/verify-rust-std/issues/76)
66
- **Start date:** 24/06/24
77
- **End date:** 24/12/10
88

doc/src/challenges/0004-btree-node.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Challenge 4: Memory safety of BTreeMap's `btree::node` module
22

33
- **Status:** Open
4-
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/25)
4+
- **Tracking Issue:** [#77](https://github.com/model-checking/verify-rust-std/issues/77)
55
- **Start date:** *2024-07-01*
66
- **End date:** *2024-12-10*
77

doc/src/challenges/0005-linked-list.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Challenge 5: Verify functions iterating over inductive data type: `linked_list`
22

33
- **Status:** Open
4-
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/29)
4+
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29)
55
- **Start date:** *24/07/01*
66
- **End date:** *24/12/10*
77

doc/src/challenges/0006-nonnull.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Challenge 6: Safety of NonNull
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [#53](https://github.com/model-checking/verify-rust-std/issues/53)
5+
- **Start date:** *2024-08-16*
6+
- **End date:** *2024-12-10*
7+
8+
-------------------
9+
10+
11+
## Goal
12+
13+
Verify absence of undefined behavior of the [`ptr::NonNull` module](https://github.com/rust-lang/rust/blob/master/library/core/src/ptr/non_null.rs).
14+
Most of its functions are marked `unsafe`, yet they are used in 62 other modules
15+
of the standard library.
16+
17+
### Success Criteria
18+
19+
Prove absence of undefined behavior of the following 48 public functions. You
20+
may wish to do so by attaching pre- and postconditions to these, and then (if
21+
needed by the tooling that you choose to use) adding verification harnesses.
22+
23+
1. `NonNull<T>::add`
24+
2. `NonNull<T>::addr`
25+
3. `NonNull<T>::align_offset`
26+
4. `NonNull<T>::as_mut<'a>`
27+
5. `NonNull<T>::as_mut_ptr`
28+
6. `NonNull<T>::as_non_null_ptr`
29+
7. `NonNull<T>::as_ptr`
30+
8. `NonNull<T>::as_ref<'a>`
31+
9. `NonNull<T>::as_uninit_mut<'a>`
32+
10. `NonNull<T>::as_uninit_ref<'a>`
33+
11. `NonNull<T>::as_uninit_slice<'a>`
34+
12. `NonNull<T>::as_uninit_slice_mut<'a>`
35+
13. `NonNull<T>::byte_add`
36+
14. `NonNull<T>::byte_offset_from<U: ?Sized>`
37+
15. `NonNull<T>::byte_offset`
38+
16. `NonNull<T>::byte_sub`
39+
17. `NonNull<T>::cast<U>`
40+
18. `NonNull<T>::copy_from_nonoverlapping`
41+
19. `NonNull<T>::copy_from`
42+
20. `NonNull<T>::copy_to_nonoverlapping`
43+
21. `NonNull<T>::copy_to`
44+
22. `NonNull<T>::dangling`
45+
23. `NonNull<T>::drop_in_place`
46+
24. `NonNull<T>::from_raw_parts`
47+
25. `NonNull<T>::get_unchecked_mut<I>`
48+
26. `NonNull<T>::is_aligned_to`
49+
27. `NonNull<T>::is_aligned`
50+
28. `NonNull<T>::is_empty`
51+
29. `NonNull<T>::len`
52+
30. `NonNull<T>::map_addr`
53+
31. `NonNull<T>::new_unchecked`
54+
32. `NonNull<T>::new`
55+
33. `NonNull<T>::offset_from`
56+
34. `NonNull<T>::offset`
57+
35. `NonNull<T>::read_unaligned`
58+
36. `NonNull<T>::read_volatile`
59+
37. `NonNull<T>::read`
60+
38. `NonNull<T>::replace`
61+
39. `NonNull<T>::slice_from_raw_parts`
62+
40. `NonNull<T>::sub_ptr`
63+
41. `NonNull<T>::sub`
64+
42. `NonNull<T>::swap`
65+
43. `NonNull<T>::to_raw_parts`
66+
44. `NonNull<T>::with_addr`
67+
45. `NonNull<T>::write_bytes`
68+
46. `NonNull<T>::write_unaligned`
69+
47. `NonNull<T>::write_volatile`
70+
48. `NonNull<T>::write`
71+
72+
### List of UBs
73+
74+
In addition to any properties called out as `SAFETY` comments in the source
75+
code,
76+
all proofs must automatically ensure the absence of the following [undefined behaviors](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
77+
78+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
79+
* Reading from uninitialized memory.
80+
* Mutating immutable bytes.
81+
* Producing an invalid value
82+
83+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
84+
in addition to the ones listed above.

doc/src/challenges/0008-smallsort.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Challenge 8: Contracts for SmallSort
22

33
- **Status:** Open
4-
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/56)
4+
- **Tracking Issue:** [#56](https://github.com/model-checking/verify-rust-std/issues/56)
55
- **Start date:** *2024-08-17*
66
- **End date:** *2024-12-10*
77

doc/src/challenges/0009-duration.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Challenge 9: Safe abstractions for `core::time::Duration`
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [#72](https://github.com/model-checking/verify-rust-std/issues/72)
5+
- **Start date:** *2024-08-20*
6+
- **End date:** *2024-12-20*
7+
8+
-------------------
9+
10+
11+
## Goal
12+
13+
Write function contracts for `core::time::Duration` that can be used as safe abstractions.
14+
Even though the majority of `Duration` methods are safe, many of them are safe abstractions over unsafe code.
15+
16+
For instance, the `new` method is implemented as follows in v1.3.0:
17+
```rust
18+
pub const fn new(secs: u64, nanos: u32) -> Duration {
19+
if nanos < NANOS_PER_SEC {
20+
// SAFETY: nanos < NANOS_PER_SEC, therefore nanos is within the valid range
21+
Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
22+
} else {
23+
let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
24+
Some(secs) => secs,
25+
None => panic!("overflow in Duration::new"),
26+
};
27+
let nanos = nanos % NANOS_PER_SEC;
28+
// SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
29+
Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
30+
}
31+
}
32+
```
33+
34+
### Success Criteria
35+
36+
Write a [type invariant](https://model-checking.github.io/kani/crates/doc/kani/derive.Invariant.html) for the struct `Duration`. Write function contracts for the following public functions.
37+
38+
1. `Duration::new(secs: u64, nanos: u32) -> Duration`
39+
2. `Duration::from_secs(secs: u64) -> Duration`
40+
3. `Duration::from_millis(millis: u64) -> Duration`
41+
4. `Duration::from_micros(micros: u64) -> Duration`
42+
5. `Duration::from_nanos(nanos: u64) -> Duration`
43+
44+
6. `Duration::as_secs(&self) -> u64`
45+
7. `Duration::as_millis(&self) -> u128`
46+
8. `Duration::as_micros(&self) -> u128`
47+
9. `Duration::as_nanos(&self) -> u128`
48+
10. `Duration::subsec_millis(&self) -> u32`
49+
11. `Duration::subsec_micros(&self) -> u32`
50+
12. `Duration::subsec_nanos(&self) -> u32`
51+
52+
13. `Duration::checked_add(&self, rhs: Duration) -> Option<Duration>`
53+
14. `Duration::checked_sub(&self, rhs: Duration) -> Option<Duration>`
54+
15. `Duration::checked_mul(&self, rhs: u32) -> Option<Duration>`
55+
16. `Duration::checked_div(&self, rhs: u32) -> Option<Duration>`
56+
57+
The memory safety and the contracts of the above listed functions must be verified
58+
for all possible input values.
59+
60+
### List of UBs
61+
62+
In addition to any properties called out as `SAFETY` comments in the source
63+
code,
64+
all proofs must automatically ensure the absence of the following [undefined behaviors](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
65+
66+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
67+
* Reading from uninitialized memory.
68+
* Mutating immutable bytes.
69+
* Producing an invalid value
70+
71+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
72+
in addition to the ones listed above.

0 commit comments

Comments
 (0)