forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 66
Add Challenges 17 18 for slices #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
carolynzech
merged 19 commits into
model-checking:main
from
thanhnguyen-aws:slicechallenges
Apr 3, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
72baf24
add slice challenges
thanhnguyen-aws 87a1663
Merge branch 'main' into slicechallenges
thanhnguyen-aws 290cd3e
fix typo
thanhnguyen-aws 4f0580c
Merge branch 'main' into slicechallenges
thanhnguyen-aws eb18abc
fix date format
thanhnguyen-aws d12ddd7
fix typos
thanhnguyen-aws a9cfdf4
fix issue link, reward
thanhnguyen-aws bb4e37e
Update doc/src/challenges/0018-slice-iter-pt1.md
thanhnguyen-aws d9095e5
combine 2 challenges
thanhnguyen-aws 6a4ac1e
update summary.md
thanhnguyen-aws 706db8a
Merge branch 'slicechallenges' of https://github.com/thanhnguyen-aws/…
thanhnguyen-aws 82953be
Update doc/src/SUMMARY.md
thanhnguyen-aws d72e6cd
Merge branch 'main' into slicechallenges
thanhnguyen-aws 056d459
separate safe/unsafe for challenge 17
thanhnguyen-aws dbfbd9c
Update doc/src/challenges/0017-slice.md
thanhnguyen-aws dfde3e1
Update doc/src/challenges/0017-slice.md
thanhnguyen-aws 6abf6b4
Update doc/src/challenges/0017-slice.md
thanhnguyen-aws 8c17efd
Merge branch 'main' into slicechallenges
thanhnguyen-aws e450646
update reward
thanhnguyen-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Challenge 17: Verify the safety of `slice` functions | ||
|
|
||
| - **Status:** Open | ||
| - **Tracking Issue:** [#281](https://github.com/model-checking/verify-rust-std/issues/281) | ||
| - **Start date:** *2025-03-07* | ||
| - **End date:** *2025-10-17* | ||
| - **Reward:** *10000 USD* | ||
|
|
||
| ------------------- | ||
|
|
||
|
|
||
| ## Goal | ||
|
|
||
| Verify the safety of `std::slice` functions in (library/core/src/slice/mod.rs). | ||
|
|
||
|
|
||
| ### Success Criteria | ||
|
|
||
| For the following unsafe functions (in library/core/src/slice/mod.rs): | ||
| - Write contracts specifying the safety precondition(s) that the caller must uphold, then | ||
| - Verify that if the caller respects those preconditions, the function does not cause undefined behavior. | ||
|
|
||
| | Function | | ||
| |---------| | ||
| |get_unchecked| | ||
| |get_unchecked_mut| | ||
| |swap_unchecked| | ||
| |as_chunks_unchecked| | ||
| |as_chunks_unchecked_mut| | ||
| |split_at_unchecked| | ||
| |split_at_mut_unchecked| | ||
| |align_to| | ||
| |align_to_mut| | ||
| |get_disjoint_unchecked_mut| | ||
|
|
||
| Prove that the following safe abstractions (in library/core/src/slice/mod.rs) do not cause undefined behavior: | ||
|
|
||
| | Function | | ||
| |---------| | ||
| |first_chunk| | ||
| |first_chunk_mut| | ||
| |split_first_chunk| | ||
| |split_first_chunk_mut| | ||
| |split_last_chunk| | ||
| |split_last_chunk_mut| | ||
| |last_chunk| | ||
| |last_chunk_mut| | ||
| |reverse| | ||
| |as_chunks| | ||
| |as_chunks_mut| | ||
| |as_rchunks| | ||
| |split_at_checked| | ||
| |split_at_mut_checked| | ||
| |binary_search_by| | ||
| |partition_dedup_by| | ||
| |rotate_left| | ||
| |rotate_right| | ||
| |copy_from_slice| | ||
| |copy_within| | ||
| |swap_with_slice| | ||
| |as_simd| | ||
| |as_simd_mut| | ||
| |get_disjoint_mut| | ||
| |get_disjoint_check_valid| | ||
| |as_flattened| | ||
| |as_flattened_mut| | ||
|
|
||
| The verification must be unbounded---it must hold for slices of arbitrary length. | ||
|
|
||
| The verification must hold for generic type `T` (no monomorphization). | ||
|
thanhnguyen-aws marked this conversation as resolved.
|
||
|
|
||
| ### List of UBs | ||
|
|
||
| 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): | ||
|
|
||
| * Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer. | ||
| * Reading from uninitialized memory except for padding or unions. | ||
| * Mutating immutable bytes. | ||
| * Producing an invalid value | ||
|
|
||
|
|
||
| Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md) | ||
| in addition to the ones listed above. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # Challenge 18: Verify the safety of `slice` iter functions | ||
|
|
||
| - **Status:** Open | ||
| - **Tracking Issue:** [#282](https://github.com/model-checking/verify-rust-std/issues/282) | ||
| - **Start date:** *2025-03-07* | ||
| - **End date:** *2025-10-17* | ||
| - **Reward:** *10000 USD* | ||
|
|
||
| ------------------- | ||
|
|
||
|
|
||
| ## Goal | ||
| **Part 1:** | ||
| 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): | ||
| to generate impl for Iter, IterMut, SplitN, SplitNMut, RSplitN, RSplitNMut in (library/core/src/slice/iter.rs): | ||
|
|
||
| ``` | ||
| iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, as_ref, { | ||
| fn is_sorted_by<F>(self, mut compare: F) -> bool | ||
| where | ||
| Self: Sized, | ||
| F: FnMut(&Self::Item, &Self::Item) -> bool, | ||
| { | ||
| self.as_slice().is_sorted_by(|a, b| compare(&a, &b)) | ||
| } | ||
| }} | ||
|
|
||
| iterator! {struct IterMut -> *mut T, &'a mut T, mut, {mut}, as_mut, {}} | ||
|
|
||
| forward_iterator! { SplitN: T, &'a [T] } | ||
| forward_iterator! { RSplitN: T, &'a [T] } | ||
| forward_iterator! { SplitNMut: T, &'a mut [T] } | ||
| forward_iterator! { RSplitNMut: T, &'a mut [T] } | ||
| ``` | ||
|
|
||
| **Part 2:** | ||
| Verify the safety of Iterator functions of `std::slice` that are defined in (library/core/src/slice/iter.rs). | ||
|
|
||
| ### Success Criteria | ||
|
|
||
| **Part 1:** In (library/core/src/slice/iter/macros.rs) | ||
|
|
||
| Prove absence of undefined behaviors of following safe functions that contain unsafe code: | ||
|
|
||
| | Function | | ||
| |---------| | ||
| |make_slice| | ||
| |len| | ||
| |is_empty| | ||
| |next| | ||
| |size_hint| | ||
| |count| | ||
| |nth| | ||
| |advance_by| | ||
| |last| | ||
| |fold| | ||
| |for_each| | ||
| |position| | ||
| |rposition| | ||
| |next_back| | ||
| |nth_back| | ||
| |advance_back_by| | ||
|
|
||
|
|
||
| **Part 2:** In (library/core/src/slice/iter.rs) | ||
|
|
||
| Write and prove the contract for the safety of the following unsafe functions: | ||
|
|
||
| | Function | Impl for | | ||
| |---------| ---------| | ||
| |__iterator_get_unchecked| Windows| | ||
| |__iterator_get_unchecked| Chunks| | ||
| |__iterator_get_unchecked| ChunksMut| | ||
| |__iterator_get_unchecked| ChunksExact| | ||
| |__iterator_get_unchecked| ChunksExact| | ||
| |__iterator_get_unchecked| ArrayChunks| | ||
| |__iterator_get_unchecked| ArrayChunksMut| | ||
| |__iterator_get_unchecked| RChunks| | ||
| |__iterator_get_unchecked| RChunksMut| | ||
| |__iterator_get_unchecked| RChunksExact| | ||
| |__iterator_get_unchecked| RChunksExactMut| | ||
|
|
||
| Prove absence of undefined behaviors of following safe functions that contain unsafe code: | ||
|
|
||
| | Function | Impl for | | ||
| |---------| ---------| | ||
| |new| Iter| | ||
| |new| IterMut| | ||
| |into_slice| IterMut| | ||
| |as_mut_slice| IterMut| | ||
| |next| Split| | ||
| |next_back| Split| | ||
| |next_back| Chunks| | ||
| |next| ChunksMut| | ||
| |nth| ChunksMut| | ||
| |next_back| ChunksMut| | ||
| |nth_back| ChunksMut| | ||
| |new| ChunksExact| | ||
| |new| ChunksExactMut| | ||
| |next| ChunksExactMut| | ||
| |nth| ChunksExactMut| | ||
| |next_back| ChunksExactMut| | ||
| |nth_back| ChunksExactMut| | ||
| |next| ArrayWindows| | ||
| |nth| ArrayWindows| | ||
| |next_back| ArrayWindows| | ||
| |nth_back| ArrayWindows| | ||
| |next| RChunks| | ||
| |next_back| RChunks| | ||
| |next| RChunksMut| | ||
| |nth| RChunksMut| | ||
| |last| RChunksMut| | ||
| |next_back| RChunksMut| | ||
| |nth_back| RChunksMut| | ||
| |new| RChunksExact| | ||
| |new| RChunksExactMut| | ||
| |next| RChunksExactMut| | ||
| |nth| RChunksExactMut| | ||
| |next_back| RChunksExactMut| | ||
| |nth_back| RChunksExactMut| | ||
|
|
||
|
|
||
| The verification must be unbounded---it must hold for slices of arbitrary length. | ||
|
|
||
| The verification must hold for generic type `T` (no monomorphization). | ||
|
|
||
| ### List of UBs | ||
|
|
||
| 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): | ||
|
|
||
| * Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer. | ||
| * Reading from uninitialized memory except for padding or unions. | ||
| * Mutating immutable bytes. | ||
| * Producing an invalid value | ||
|
|
||
|
|
||
| Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md) | ||
| in addition to the ones listed above. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.