Verify safety of StrSearcher (Challenge 21) #538
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.
Summary
Verify the 6 Searcher/ReverseSearcher methods on StrSearcher (substring search) for Challenge 21.
This PR adds 14 Kani proof harnesses covering both EmptyNeedle and TwoWay variants, proving that returned indices lie on valid UTF-8 char boundaries with no undefined behavior.
Implementation
Single file modified:
library/core/src/str/pattern.rs(+725 lines)Abstractions under
#[cfg(kani)]Since the entire StrSearcher implementation contains zero
unsafeblocks, UB-freedom is structurally guaranteed by Rust. The primary proof obligation is UTF-8 char boundary safety.The TwoWaySearcher algorithm has deeply nested loops intractable for CBMC. We abstract:
#[cfg]on EmptyNeedle loop arms14 Harnesses
verify_str_searcher_empty_creationverify_str_searcher_empty_nextverify_str_searcher_empty_next_backverify_str_searcher_empty_next_matchverify_str_searcher_empty_next_match_backverify_str_searcher_empty_next_rejectverify_str_searcher_empty_next_reject_backverify_str_searcher_twoway_creationverify_str_searcher_twoway_nextverify_str_searcher_twoway_next_matchverify_str_searcher_twoway_next_backverify_str_searcher_twoway_next_match_backverify_str_searcher_twoway_next_rejectverify_str_searcher_twoway_next_reject_backChallenge 21 Requirements Met
type_invariant_str_searchercovering EmptyNeedle and TwoWaySearcheris_char_boundaryon returned indices#[cfg(kani)]abstractionsLocal Testing
All 14 harnesses pass locally (~24s each):
Full CI simulation (556 harnesses total): 0 failures
Dependencies
This PR is based on #537 (Challenge 20) which adds char-related Searcher verification. The branch includes both Challenge 20 and Challenge 21 changes.
If Challenge 20 needs revisions, this PR can be rebased accordingly.
Notes
#[loop_invariant]annotations used (learned from Ch20 CI fix)