Skip to content

Commit 72baf24

Browse files
add slice challenges
1 parent b764eeb commit 72baf24

3 files changed

Lines changed: 247 additions & 0 deletions

File tree

doc/src/challenges/0017-slice.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Challenge 17: Verify the safety of `slice` functions
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29)
5+
- **Start date:** *2025/03/07*
6+
- **End date:** *2025/10/17*
7+
- **Reward:** *?*
8+
9+
-------------------
10+
11+
12+
## Goal
13+
14+
Verify the safety of [`std::slice`] functions in (library/core/src/slice/mod.rs).
15+
16+
17+
### Success Criteria
18+
19+
The memory safety of the following public functions that iterating over the internal inductive data type must be verified:
20+
21+
| Function |
22+
|---------|
23+
|first_chunk|
24+
|first_chunk_mut|
25+
|split_first_chunk|
26+
|split_first_chunk_mut|
27+
|split_last_chunk|
28+
|split_last_chunk_mut|
29+
|last_chunk|
30+
|last_chunk_mut|
31+
|get_unchecked|
32+
|get_unchecked_mut|
33+
|as_ptr_range|
34+
|as_mut_ptr_range|
35+
|as_array|
36+
|as_mut_array|
37+
|swap|
38+
|swap_unchecked|
39+
|reverse|
40+
|as_chunks_unchecked|
41+
|as_chunks|
42+
|as_rchunks|
43+
|as_chunks_unchecked_mut|
44+
|split_at_unchecked|
45+
|split_at_mut_unchecked|
46+
|split_at_checked|
47+
|split_at_mut_checked|
48+
|binary_search_by|
49+
|partition_dedup_by|
50+
|rotate_left|
51+
|rotate_right|
52+
|copy_from_slice|
53+
|copy_within|
54+
|swap_with_slice|
55+
|align_to|
56+
|align_to_mut|
57+
|as_simd|
58+
|as_simd_mut|
59+
|get_many_unchecked_mut|
60+
|get_many_mut|
61+
|as_flattened|
62+
|as_flattened_mut|
63+
64+
The verification must be unbounded---it must hold for slices of arbitrary length.
65+
66+
The verification must be hold for generic type `T` (no monomorphization).
67+
68+
### List of UBs
69+
70+
All proofs must automatically ensure the absence of the following undefined behaviors [ref](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
71+
72+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
73+
* Reading from uninitialized memory except for padding or unions.
74+
* Mutating immutable bytes.
75+
* Producing an invalid value
76+
77+
78+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
79+
in addition to the ones listed above.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Challenge 18: Verify the safety of `slice` iter functions - part 1
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29)
5+
- **Start date:** *2025/03/07*
6+
- **End date:** *2025/10/17*
7+
- **Reward:** *?*
8+
9+
-------------------
10+
11+
12+
## Goal
13+
14+
Verify the safety of Iterator functions of [`std::slice`] generated by `iterator!` and `forward_iterator!` macros that are defined in (library/core/src/slice/iter/macros.rs):
15+
to generate impl for `Iter`, `IterMut`, `SplitN`, `SplitNMut`, `RSplitN`, `RSplitNMut` in (library/core/src/slice/iter.rs):
16+
17+
```
18+
iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, as_ref, {
19+
fn is_sorted_by<F>(self, mut compare: F) -> bool
20+
where
21+
Self: Sized,
22+
F: FnMut(&Self::Item, &Self::Item) -> bool,
23+
{
24+
self.as_slice().is_sorted_by(|a, b| compare(&a, &b))
25+
}
26+
}}
27+
28+
iterator! {struct IterMut -> *mut T, &'a mut T, mut, {mut}, as_mut, {}}
29+
30+
forward_iterator! { SplitN: T, &'a [T] }
31+
forward_iterator! { RSplitN: T, &'a [T] }
32+
forward_iterator! { SplitNMut: T, &'a mut [T] }
33+
forward_iterator! { RSplitNMut: T, &'a mut [T] }
34+
```
35+
36+
### Success Criteria
37+
38+
Write and prove the contract for the safety of the following functions:
39+
40+
| Function |
41+
|---------|
42+
|next_back_unchecked|
43+
|make_slice|
44+
|pre_dec_end|
45+
|post_inc_start|
46+
|len|
47+
|is_empty|
48+
|next|
49+
|size_hint|
50+
|count|
51+
|nth|
52+
|advance_by|
53+
|last|
54+
|fold|
55+
|for_each|
56+
|all|
57+
|any|
58+
|find|
59+
|find_map|
60+
|position|
61+
|rposition|
62+
|next_back|
63+
|nth_back|
64+
|advance_back_by|
65+
|next_unchecked|
66+
67+
68+
The verification must be unbounded---it must hold for slices of arbitrary length.
69+
70+
The verification must be hold for generic type `T` (no monomorphization).
71+
72+
### List of UBs
73+
74+
All proofs must automatically ensure the absence of the following undefined behaviors [ref](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
75+
76+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
77+
* Reading from uninitialized memory except for padding or unions.
78+
* Mutating immutable bytes.
79+
* Producing an invalid value
80+
81+
82+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
83+
in addition to the ones listed above.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Challenge 19: Verify the safety of `slice` iter functions - part 2
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29)
5+
- **Start date:** *2025/03/07*
6+
- **End date:** *2025/10/17*
7+
- **Reward:** *?*
8+
9+
-------------------
10+
11+
12+
## Goal
13+
14+
Verify the safety of Iterator functions of [`std::slice`] that are defined in (library/core/src/slice/iter.rs):
15+
16+
17+
18+
### Success Criteria
19+
20+
Write and prove the contract for the safety of the following functions:
21+
22+
| Function | Impl for |
23+
|---------| ---------|
24+
|new| Iter|
25+
|new| IterMut|
26+
|into_slice| IterMut|
27+
|as_mut_slice| IterMut|
28+
|next| Split|
29+
|next_back| Split|
30+
|__iterator_get_unchecked| Windows|
31+
|__iterator_get_unchecked| Chunks|
32+
|next_back| Chunks|
33+
|next| ChunksMut|
34+
|nth| ChunksMut|
35+
|__iterator_get_unchecked| ChunksMut|
36+
|next_back| ChunksMut|
37+
|nth_back| ChunksMut|
38+
|new| ChunksExact|
39+
|__iterator_get_unchecked| ChunksExact|
40+
|new| ChunksExactMut|
41+
|next| ChunksExactMut|
42+
|nth| ChunksExactMut|
43+
|__iterator_get_unchecked| ChunksExact|
44+
|next_back| ChunksExactMut|
45+
|nth_back| ChunksExactMut|
46+
|next| ArrayWindows|
47+
|nth| ArrayWindows|
48+
|next_back| ArrayWindows|
49+
|nth_back| ArrayWindows|
50+
|__iterator_get_unchecked| ArrayChunks|
51+
|__iterator_get_unchecked| ArrayChunksMut|
52+
|next| RChunks|
53+
|__iterator_get_unchecked| RChunks|
54+
|next_back| RChunks|
55+
|next| RChunksMut|
56+
|nth| RChunksMut|
57+
|last| RChunksMut|
58+
|__iterator_get_unchecked| RChunksMut|
59+
|next_back| RChunksMut|
60+
|nth_back| RChunksMut|
61+
|new| RChunksExact|
62+
|__iterator_get_unchecked| RChunksExact|
63+
|new| RChunksExactMut|
64+
|next| RChunksExactMut|
65+
|nth| RChunksExactMut|
66+
|__iterator_get_unchecked| RChunksExactMut|
67+
|next_back| RChunksExactMut|
68+
|nth_back| RChunksExactMut|
69+
70+
The verification must be unbounded---it must hold for slices of arbitrary length.
71+
72+
The verification must be hold for generic type `T` (no monomorphization).
73+
74+
### List of UBs
75+
76+
All proofs must automatically ensure the absence of the following undefined behaviors [ref](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 except for padding or unions.
80+
* Mutating immutable bytes.
81+
* Producing an invalid value
82+
83+
84+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
85+
in addition to the ones listed above.

0 commit comments

Comments
 (0)