Skip to content

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

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
14fc35a
add str-iter challenges
thanhnguyen-aws Mar 6, 2025
cdfd027
Merge branch 'main' into strIterchallenges
thanhnguyen-aws Mar 6, 2025
795738f
Merge branch 'main' into strIterchallenges
thanhnguyen-aws Mar 14, 2025
44b9e12
fix date format
thanhnguyen-aws Mar 14, 2025
766009a
fix date format
thanhnguyen-aws Mar 14, 2025
83f112d
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 18, 2025
495e44f
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 18, 2025
34a29ed
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 18, 2025
51f3854
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 18, 2025
00ed97e
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 18, 2025
5aa096c
fix issue link, reward and some typos
thanhnguyen-aws Mar 18, 2025
e2aec46
some typos
thanhnguyen-aws Mar 18, 2025
09c2f99
fix a typo
thanhnguyen-aws Mar 18, 2025
470897c
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 19, 2025
3cceb5c
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 19, 2025
7c2b29e
update summary.md
thanhnguyen-aws Mar 19, 2025
5067720
commit changr from upstream
thanhnguyen-aws Mar 19, 2025
0c02e93
add UB check requirement
thanhnguyen-aws Mar 20, 2025
b490be8
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 24, 2025
f2a6d63
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 24, 2025
6f2f719
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 24, 2025
13eae8c
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws Mar 24, 2025
fe78182
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws Mar 24, 2025
58c29af
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws Mar 24, 2025
8c07a61
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 24, 2025
fc30562
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 24, 2025
4ae8c79
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 24, 2025
cb2e15c
Merge branch 'main' into strIterchallenges
thanhnguyen-aws Mar 24, 2025
542ddc7
change reward for ch 20 21
thanhnguyen-aws Mar 24, 2025
fd6dbfe
complexity of challenge 21
thanhnguyen-aws Mar 24, 2025
d34f1cb
separate safe/unsafe functions in challenge 22
thanhnguyen-aws Mar 24, 2025
2711960
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws Mar 28, 2025
279efe6
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Mar 28, 2025
947538e
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws Mar 28, 2025
f0fbb0c
fixing the template
thanhnguyen-aws Mar 31, 2025
74e044e
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Apr 3, 2025
00d288c
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws Apr 3, 2025
a24cc0f
Update doc/src/challenges/0020-str-pattern-pt1.md
thanhnguyen-aws Apr 3, 2025
8d98b12
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws Apr 3, 2025
f30067b
Update doc/src/challenges/0022-str-iter.md
thanhnguyen-aws Apr 3, 2025
0b13289
Update doc/src/challenges/0021-str-pattern-pt2.md
thanhnguyen-aws Apr 3, 2025
1552426
Merge branch 'main' into strIterchallenges
thanhnguyen-aws Apr 3, 2025
ffbfee3
update reward
thanhnguyen-aws Apr 3, 2025
af9671a
Merge branch 'main' into strIterchallenges
tautschnig Apr 4, 2025
07c0ff4
Update doc/src/challenges/0020-str-pattern-pt1.md
tautschnig Apr 4, 2025
3fd2527
Update doc/src/challenges/0021-str-pattern-pt2.md
tautschnig Apr 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions doc/src/challenges/0020-str-pattern-pt1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,50 @@
- **Tracking Issue:** [#277](https://github.com/model-checking/verify-rust-std/issues/277)
- **Start date:** *2025-03-07*
- **End date:** *2025-10-17*
- **Reward:** *5000 USD*
- **Reward:** *10000 USD*

-------------------


### Context

The following str library functions are generic over the `Pattern` trait (https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html):
contains, starts_with, ends_with, find, rfind, split, split_inclusive, rsplit, split_terminator, rsplit_terminator, splitn, rsplitn, split_once, rsplit_once, rmatches, match_indices, rmatch_indices, trim_matches, trim_start_matches,
strip_prefix, strip_suffix, trim_end_matches.
The functions which take Pattern as input turn the input str into a kind of `Searcher` (https://doc.rust-lang.org/std/str/pattern/trait.Searcher.html) which iterates over positions where the Pattern match, then perform their desired operations (split, find, ...).
- `contains`
- `starts_with`
- `ends_with`
- `find`
- `rfind`
- `split`
- `split_inclusive`
- `rsplit`
- `split_terminator`
- `rsplit_terminator`
- `splitn`
- `rsplitn`
- `split_once`
- `rsplit_once`
- `rmatches`
- `match_indices`
- `rmatch_indices`
- `trim_matches`
- `trim_start_matches`
- `strip_prefix`
- `strip_suffix`
- `trim_end_matches`
These functions accept a pattern as input, then call [into_searcher](https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html#tymethod.into_searcher) to create a [Searcher](https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html#associatedtype.Searcher) for the pattern. They use this `Searcher` to perform their desired operations (split, find, etc.).
Those functions are 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 being a valid utf8 string (str). You can assume any utf8 string property of haystack.
2. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF-8 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 being a valid UTF-8 string (str). You can assume any UTF-8 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. No undefined behavior occurs when calling the functions after the Searcher is created.
1. No undefined behavior occurs after the Searcher is created.
2. The impls of unsafe traits `Searcher` and `ReverseSearcher` satisfy the SAFETY condition stated in the file:
```
/// The trait is marked unsafe because the indices returned by the
Expand All @@ -40,13 +60,25 @@ 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 considered successful if for each `Searcher` above, you can specify a condition (a "type invariant") C and prove that:
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.
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`
for the following `Searcher`s:
- `CharSearcher`
- `MultiCharEqSearcher`
- `CharArraySearcher`
- `CharArrayRefSearcher`
- `CharSliceSearcher`
- `CharPredicateSearcher`

The verification is considered successful if for each `Searcher` above, you can specify a condition (a "type invariant") `C` and prove that:
1. If the `Searcher` is created from any valid UTF-8 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 satisfies `C`.

Furthermore, you must prove the absence of undefined behaviors listed in the next section.

Expand Down
53 changes: 41 additions & 12 deletions doc/src/challenges/0021-str-pattern-pt2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,38 @@
- **Tracking Issue:** [#278](https://github.com/model-checking/verify-rust-std/issues/278)
- **Start date:** *2025-03-07*
- **End date:** *2025-10-17*
- **Reward:** *5000 USD*
- **Reward:** *10000 USD*

-------------------


### Context

The following str library functions are generic over the `Pattern` trait (https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html):
contains, starts_with, ends_with, find, rfind, split, split_inclusive, rsplit, split_terminator, rsplit_terminator, splitn, rsplitn, split_once, rsplit_once, rmatches, match_indices, rmatch_indices, trim_matches, trim_start_matches,
strip_prefix, strip_suffix, trim_end_matches.
The functions which take Pattern as input turn the input str into a kind of `Searcher` (https://doc.rust-lang.org/std/str/pattern/trait.Searcher.html) 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).
- `contains`
- `starts_with`
- `ends_with`
- `find`
- `rfind`
- `split`
- `split_inclusive`
- `rsplit`
- `split_terminator`
- `rsplit_terminator`
- `splitn`
- `rsplitn`
- `split_once`
- `rsplit_once`
- `rmatches`
- `match_indices`
- `rmatch_indices`
- `trim_matches`
- `trim_start_matches`
- `strip_prefix`
- `strip_suffix`
- `trim_end_matches`
These functions accept a pattern as input, then call [into_searcher](https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html#tymethod.into_searcher) to create a [Searcher](https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html#associatedtype.Searcher) for the pattern. They use this `Searcher` to perform their desired operations (split, find, etc.).
Those functions are 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

Expand All @@ -37,16 +57,25 @@ The safety properties we are targeting are:
```
This property should hold for next_back() of `ReverseSearcher` too.

Although this challenge appears similar to Challenge 20 and only requires proving safety for the `StrSearcher` implementation,
it warrants being a separate challenge due to its complexity.
The `StrSearcher` implementation relies on sophisticated algorithms - TwoWay-Search and SIMD-search - making the safety proof significantly more complex.

### 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`.
### Success Criteria

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.
Verify the safety of the following `StrSearcher` functions in (library/core/src/str/pattern.rs):
- `next`
- `next_match`
- `next_back`
- `next_match_back`
- `next_reject`
- `next_back_reject`

The verification is considered successful if you can specify a condition (a "type invariant") `C` and prove that:
1. If the `StrSearcher` is created from any valid UTF-8 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 satisfies `C`.

Furthermore, you must prove the absence of undefined behaviors listed in the next section.

Expand Down
8 changes: 5 additions & 3 deletions doc/src/challenges/0022-str-iter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Verify the safety of [`std::str`] functions that are defined in (library/core/sr
**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).
3. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF-8 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 UTF-8 string (str) (You can assume any property of valid UTF-8 encoded string).


### Success Criteria

Write and prove the contract for the safety of the following functions:
Prove the safety of the following safe functions that contain unsafe code:


| Function | Impl for |
Expand All @@ -43,6 +43,8 @@ Write and prove the contract for the safety of the following functions:
|next_back| MatchesInternal|
|remainder| SplitAsciiWhitespace|

Write and prove the contract for this unsafe function: __iterator_get_unchecked

The verification must be unbounded---it must hold for str of arbitrary length.


Expand Down
Loading