forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 50
Add Challenges 20 21 22 for str Pattern and iter #266
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
tautschnig
merged 47 commits into
model-checking:main
from
thanhnguyen-aws:strIterchallenges
May 20, 2025
Merged
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
14fc35a
add str-iter challenges
thanhnguyen-aws cdfd027
Merge branch 'main' into strIterchallenges
thanhnguyen-aws 795738f
Merge branch 'main' into strIterchallenges
thanhnguyen-aws 44b9e12
fix date format
thanhnguyen-aws 766009a
fix date format
thanhnguyen-aws 83f112d
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 495e44f
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 34a29ed
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 51f3854
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 00ed97e
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 5aa096c
fix issue link, reward and some typos
thanhnguyen-aws e2aec46
some typos
thanhnguyen-aws 09c2f99
fix a typo
thanhnguyen-aws 470897c
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 3cceb5c
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 7c2b29e
update summary.md
thanhnguyen-aws 5067720
commit changr from upstream
thanhnguyen-aws 0c02e93
add UB check requirement
thanhnguyen-aws b490be8
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws f2a6d63
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 6f2f719
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 13eae8c
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws fe78182
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws 58c29af
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws 8c07a61
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws fc30562
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 4ae8c79
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws cb2e15c
Merge branch 'main' into strIterchallenges
thanhnguyen-aws 542ddc7
change reward for ch 20 21
thanhnguyen-aws fd6dbfe
complexity of challenge 21
thanhnguyen-aws d34f1cb
separate safe/unsafe functions in challenge 22
thanhnguyen-aws 2711960
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws 279efe6
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 947538e
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws f0fbb0c
fixing the template
thanhnguyen-aws 74e044e
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 00d288c
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws a24cc0f
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws 8d98b12
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws f30067b
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws 0b13289
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws 1552426
Merge branch 'main' into strIterchallenges
thanhnguyen-aws ffbfee3
update reward
thanhnguyen-aws af9671a
Merge branch 'main' into strIterchallenges
tautschnig 07c0ff4
Update doc/src/challenges/0020-str-pattern-pt1.md
tautschnig 3fd2527
Update doc/src/challenges/0021-str-pattern-pt2.md
tautschnig cc4d48a
Merge branch 'main' into strIterchallenges
tautschnig 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Challenge 20: Verify the safety of char-related functions in str::pattern | ||
|
||
- **Status:** Open | ||
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29) | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **Start date:** *2025-03-07* | ||
- **End date:** *2025-10-17* | ||
- **Reward:** *? USD* | ||
|
||
------------------- | ||
|
||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Context | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
A majority portion in str library functions take a Pattern (https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html) as input. | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The functions which take Pattern as input turn the input str into a kind of Searcher which iterates over positions where the Pattern match, then perform their desired operations (split, find, ...). | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Those functions is implemented in (library/core/src/str/mod.rs), but the core of them is the searching algorithms which are implemented in (library/core/src/str/pattern.rs). | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Details | ||
|
||
IMPORTANT NOTE: for this challenge, you can assume: | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. The safety and functional correctness of all functions in `slice` module | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF8 encoding description in https://en.wikipedia.org/wiki/UTF-8) . | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
3. That all the Searchers in (library/core/src/str/iter.rs) are created by the into_searcher(_, haystack) with haystack is a valid utf8 string (str). You can assume any utf8 string property of haystack. | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Verify the safety of the functions in (library/core/src/str/pattern.rs) listed in the next section. | ||
|
||
The safety properties we are targeting are: | ||
1. There is no UB happens when calling the functions after the Searcher is created. | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. The impls of unsafe traits `Searcher` and `ReverseSearcher` satisfies the SAFETY condition stated in the file: | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
/// The trait is marked unsafe because the indices returned by the | ||
/// [`next()`][Searcher::next] methods are required to lie on valid utf8 | ||
/// boundaries in the haystack. This enables consumers of this trait to | ||
/// slice the haystack without additional runtime checks. | ||
``` | ||
This property should hold for next_back() of `ReverseSearcher` too. | ||
|
||
|
||
### Success Criteria | ||
|
||
Verify the safety of the following functions in (library/core/src/str/pattern.rs) : `next`, `next_match`, `next_back`, `next_match_back`, `next_reject`, `next_back_reject` | ||
which are implemented for the following `Searcher`s: `CharSearcher`, `MultiCharEqSearcher`, `CharArraySearcher` , `CharArrayRefSearcher`, `CharSliceSearcher`, `CharPredicateSearcher`. | ||
|
||
The verification is consider successful if for each `Searcher` above, you can specify a condition (a "type invariant") C and prove that: | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. If the `Searcher` is created from any valid utf8 haystack, it satisfies C. | ||
2. If the `Searcher` satisfies C, it ensures the two safety properties mentioned in the previous section. | ||
3. If the `Searcher` satisfies C, after it calls any function above and gets modified, it still statisfies C. | ||
|
||
|
||
The verification must be unbounded---it must hold for inputs of arbitrary size. | ||
|
||
### 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 | ||
carolynzech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
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,63 @@ | ||
# Challenge 21: Verify the correctness of char-related functions in str::pattern | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- **Status:** Open | ||
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29) | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **Start date:** *2025-03-07* | ||
- **End date:** *2025-10-17* | ||
- **Reward:** *? USD* | ||
|
||
------------------- | ||
|
||
|
||
### Context | ||
carolynzech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
A majority portion in str library functions take a Pattern (https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html) as input. | ||
The functions which take Pattern as input turn the input str into a kind of `Searcher` which iterates over positions where the Pattern matches, then perform their desired operations (split, find, ...). | ||
Those functions is implemented in (library/core/src/str/mod.rs), but the core of them is the searching algorithms which are implemented in (library/core/src/str/pattern.rs). | ||
|
||
# Details | ||
|
||
IMPORTANT NOTE: for this challenge, you can assume: | ||
1. The safety and functional correctness of all functions in `slice` module | ||
2. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF8 encoding description in https://en.wikipedia.org/wiki/UTF-8) . | ||
3. That all the Searchers in (library/core/src/str/iter.rs) are created by the into_searcher(_, haystack) with haystack is a valid utf8 string (str). You can assume any utf8 string property of haystack. | ||
|
||
Verify the safety of the functions in (library/core/src/str/pattern.rs) listed in the next section. | ||
|
||
The safety properties we are targeting are: | ||
1. There is no UB happens when calling the functions after the Searcher is created. | ||
2. The impls of unsafe traits `Searcher` and `ReverseSearcher` satisfies the SAFETY condition stated in the file: | ||
``` | ||
/// The trait is marked unsafe because the indices returned by the | ||
/// [`next()`][Searcher::next] methods are required to lie on valid utf8 | ||
/// boundaries in the haystack. This enables consumers of this trait to | ||
/// slice the haystack without additional runtime checks. | ||
``` | ||
This property should hold for next_back() of `ReverseSearcher` too. | ||
|
||
|
||
### Success Criteria | ||
|
||
Verify the safety of the following functions in (library/core/src/str/pattern.rs) : `next`, `next_match`, `next_back`, `next_match_back`, `next_reject`, `next_back_reject` | ||
which are implemented for `StrSearcher`. | ||
|
||
The verification is consider successful if you can specify a condition (a "type invariant") C and prove that: | ||
1. If the `StrSearcher` is created from any valid utf8 haystack, it satisfies C. | ||
2. If the `StrSearcher` satisfies C, it ensures the two safety properties mentioned in the previous section. | ||
3. If the `StrSearcher` satisfies C, after it calls any function above and gets modified, it still statisfies C. | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
The verification must be unbounded---it must hold for inputs of arbitrary size. | ||
|
||
### 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,60 @@ | ||
# Challenge 22: Verify the safety of `str` iter functions - part 2 | ||
|
||
- **Status:** Open | ||
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29) | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **Start date:** *2025-03-07* | ||
- **End date:** *2025-10-17* | ||
- **Reward:** *?* | ||
|
||
------------------- | ||
|
||
|
||
## Goal | ||
|
||
Verify the safety of [`std::str`] functions that are defined in (library/core/src/str/iter.rs): | ||
|
||
IMPORTANT NOTE: for this challenge, you can assume: | ||
1. The safety and functional correctness of all functions in `slice` module | ||
2. The safety and functional correctness of all functions in (library/core/src/str/pattern.rs) | ||
3. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF8 encoding description in https://en.wikipedia.org/wiki/UTF-8). | ||
4. That all the Iterators in (library/core/src/str/iter.rs) are derived from a valid utf8 string (str) (You can assume any property of valid utf8 encoded string) | ||
|
||
|
||
### Success Criteria | ||
|
||
Write and prove the contract for the safety of the following functions: | ||
thanhnguyen-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
| Function | Impl for | | ||
|---------| ---------| | ||
|next| Chars| | ||
|advance_by| Chars| | ||
carolynzech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|next_back| Chars| | ||
|as_str| Chars| | ||
|get_end| SplitInternal| | ||
|next| SplitInternal| | ||
|next_inclusive| SplitInternal| | ||
|next_match_back| SplitInternal| | ||
|next_back_inclusive| SplitInternal| | ||
|remainder| SplitInternal| | ||
|next| MatchIndicesInternal| | ||
|next_back| MatchIndicesInternal| | ||
|next| MatchesInternal| | ||
|next_back| MatchesInternal| | ||
|remainder| SplitAsciiWhitespace| | ||
|
||
The verification must be unbounded---it must hold for str of arbitrary length. | ||
|
||
|
||
### 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. |
Oops, something went wrong.
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.