Skip to content

Challenge 22: Unbounded verification for str iter with Kani - #741

Open
v3risec wants to merge 19 commits into
model-checking:mainfrom
v3risec:challenge-22-str-iter
Open

v3risec wants to merge 19 commits into
model-checking:mainfrom
v3risec:challenge-22-str-iter

Conversation

@v3risec

@v3risec v3risec commented Oct 27, 2026 •

Copy link
Copy Markdown

Summary

This PR provides Kani proofs for all 15 safe methods required by Challenge 22 and verifies the existing safety contract of Bytes::__iterator_get_unchecked.

All 16 required harnesses execute the production target method bodies over symbolic-length inputs, covering the full range representable by the configured CBMC object model. No required harness relies on a fixed input-size bound or an unwind bound.

The changes preserve non-Kani runtime behavior. No required target method implementation is replaced with a verification-specific implementation.

Unbounded verification

Every required proof admits symbolic string lengths from zero through the maximum representable allocation size under the repository's x86-64 CBMC configuration (--object-bits 12):

const MAX_ALLOCATION_BYTES: usize = (1usize << 51) - 1;

Key properties:

  • All 16 required harnesses use symbolic-length inputs, with no fixed-size backing buffer.
  • Chars::advance_by accepts an arbitrary usize request.
  • All four loops in Chars::advance_by are verified inductively:
    1. The 32-byte chunk loop.
    2. The 32-element chunk-flag fill loop.
    3. The continuation-byte skipping loop.
    4. The remaining scalar-by-scalar loop.
  • No required harness introduces an unwind bound or a smaller input-length restriction.
  • The proof invariants check cursor bounds, pointer relationships, valid flag representations, and UTF-8 boundary conditions.

No new #[kani::unwind] annotations are introduced. The two #[kani::unwind(4)] annotations remaining in the affected files are pre-existing upstream annotations for supplementary small_slice_eq dependency checks; they do not bound any required target proof.

Proof architecture and key contributions

1. Chars::advance_by: inductive verification of the chunked implementation

The proof executes the real production Chars::advance_by implementation and the real slice::Iter operations, including as_slice, len, next, and advance_by.

The four loops are verified using inductive loop contracts rather than finite unrolling.

The proof establishes:

  • The chunk iterator remains within the original input allocation.
  • The chunk cursor and endpoint maintain the expected pointer relationship.
  • The chunk-flag array contains valid Boolean representations.
  • An arbitrary flag slot is related to the corresponding byte in the original input.
  • Each chunk's decrement is equal to the independently computed sum of its flags.
  • The scalar loop reads the corresponding byte from the original input.
  • The iterator cursor remains within the allocation and at a valid UTF-8 boundary.
  • The returned suffix has the expected pointer, length, and boundary properties.
  • Success and failure satisfy the corresponding advance_by safety postconditions, including the bounds on the remaining request.

The loop invariant predicates are side-effect-free: they do not contain kani::assume calls. UTF-8 assumptions are instantiated separately on the immutable original input.

2. Consuming Fold model and semantic refinement

The chunk implementation uses PolymorphicIter::fold to count the Boolean flags.

The Kani-only kani_fold_at_most_32 model preserves the actual consuming Fold semantics:

  • It consumes each live element in order.
  • It updates the live range before invoking the callback.
  • It invokes the actual supplied callback.
  • It returns the resulting accumulator.
  • Its element type is restricted to the verified Boolean instantiation through a fail-closed type guard.

The independent check_consuming_fold_model harness compares the model against the real PolymorphicIter::fold for symbolic Boolean arrays and every valid live subrange:

0 <= start <= end <= 32

It checks:

  • The final result.
  • Callback order.
  • Callback count.
  • Exact final live range.
  • Correct handling of empty and interior subranges.

This is a semantic refinement of the consuming Fold operation, rather than merely a replacement that computes the same Boolean sum.

3. Exact Split state-transition verification

The Split harnesses preselect legal search results before invoking the production methods.

They verify the exact relationship between the selected search result and the production method's behavior, including:

  • Exact returned slice boundaries.
  • Updated start and end.
  • Forward and reverse search cursors.
  • finished and allow_trailing_empty state.
  • Correct handling of inclusive and exclusive splitting.
  • Correct handling of empty trailing pieces.

The reverse Split proofs explicitly cover both outcomes of the second search after discarding an initial trailing empty piece.

4. Exact Matches and MatchIndices verification

All four directional methods are checked:

  • MatchesInternal::next
  • MatchesInternal::next_back
  • MatchIndicesInternal::next
  • MatchIndicesInternal::next_back

Each harness selects an expected match range before calling the production method.

The proof then checks:

  • The returned slice is exactly the selected [start, end) range.
  • The MatchIndices byte index equals the selected start offset.
  • The returned slice has the correct pointer and length.
  • The searcher cursor moves in the correct direction.
  • The expected search-plan entry is consumed.
  • No unexpected additional search call occurs.

These checks verify exact results and state transitions, not merely that the returned slices are memory-safe.

5. Searcher protocol verification

harness_searcher_protocol checks all four directional operations:

  • Searcher::next
  • ReverseSearcher::next_back
  • Searcher::next_match
  • ReverseSearcher::next_match_back

The symbolic ModelSearcher verifies:

  • Search ranges remain within the unsearched interval.
  • Returned endpoints are UTF-8 character boundaries.
  • Forward and reverse cursors move inward.
  • The original haystack identity is preserved.
  • Match, Reject, zero-width results, and exhaustion are covered.

The model implements Searcher and ReverseSearcher, but intentionally does not implement DoubleEndedSearcher: its independent nondeterministic forward and reverse choices do not claim the same-stream guarantee required by that trait.

6. Additional iterator and dependency verification

Additional harnesses cover:

  • CharIndices::next and CharIndices::next_back, including exact byte offsets and Unicode scalar validity.
  • Initial invariants for all 13 public &str iterator constructors.
  • Chars::next, Chars::next_back, and Chars::as_str over symbolic interior UTF-8 windows.
  • SplitAsciiWhitespace::remainder.
  • The existing Bytes::__iterator_get_unchecked safety contract through proof_for_contract.

The Bytes contract proof operates on arbitrary byte subslices, including cursors inside multibyte UTF-8 characters. It also passes a separate -Z uninit-checks run.

Dependency models and refinement checks

The required target method bodies are not replaced. The Kani harnesses use narrowly scoped dependency models for operations whose behavior is covered by the challenge's permitted assumptions or independently checked.

  • slice::Iter: Real production methods are executed without method stubs. A Kani-only pointer accessor exposes the iterator representation needed by loop invariants.
  • PolymorphicIter::fold: The Kani-only consuming model is checked against the real implementation over every valid subrange of the 32-element Boolean array.
  • utf8_char_width: The branch-based model is checked against the real function for all 256 possible byte values.
  • UTF-8 sequence model: A separate refinement harness checks the local sequence predicate against Unicode scalar encoding and the following character boundary. It covers all four UTF-8 widths, truncated sequences, and stray continuation bytes.
  • Pattern / Searcher: The symbolic ModelPattern and ModelSearcher over-approximate legal search transitions and are checked against the documented range and safety guarantees. Supplementary bounded regressions exercise concrete CharSearcher and StrSearcher behavior.

The fixed 32-element Fold domain corresponds to the production chunk size. The bounded concrete searcher regressions and other dependency checks are supplementary; they do not impose a bound on the symbolic input lengths of required target harnesses.

Verification results

Latest revision:

238a686bdb61f9465a1011ce9a12d337c85c3c0a

Local Kani verification:

Metric Result
Total harnesses 30/30 passed
Required targets 16/16 passed
Explicit cover goals 218/218 satisfied
New unwind annotations 0

The symbolic Chars::advance_by proof completed in 430.16 seconds, with a sampled peak process-group RSS of 4.95 GB.

Additional memory-safety check:

Bytes::__iterator_get_unchecked also passed a separate -Z uninit-checks run:

0 / 323 checks failed
3 / 3 covers satisfied

Fault injection

Mutation testing across earlier revisions of this PR demonstrates that the harnesses detect both memory-safety violations and incorrect iterator behavior.

Nine injected faults were caught on revision 0e79f5bd, including:

  • Incorrect Unicode scalar decoding.
  • Incorrect chunk advancement.
  • Invalid Split slice boundaries.
  • Incorrect MatchIndices offsets.
  • Incorrect reverse Matches results.
  • Incorrect finished-state handling.
  • An invalid one-past-the-end Bytes contract.
  • Incorrect Fold live-range handling.

Five additional faults were caught in the Split and chunk follow-up:

  • Omitting a delimiter from next_inclusive.
  • Breaking reverse trailing-empty handling.
  • Misclassifying a chunk flag.
  • Incorrect per-chunk counting.
  • Changing Fold callback order.

The strengthened Split checks caught a delimiter omission that the earlier proof had accepted because the resulting slice was still memory-safe.

Assumptions and limitations

The proofs use the assumptions explicitly permitted by Challenge 22:

  1. The slice module is safe and functionally correct.
  2. The str::pattern module satisfies its documented safety and range guarantees.
  3. The str::validations module satisfies its documented correctness assumptions.
  4. Input strings originate from valid UTF-8 &str values.

The following proof boundaries are documented explicitly:

  • CBMC allocation limit: The maximum symbolic input length is 2^51 - 1 bytes under the configured x86-64 object model. This is a tool representation limit, not a manually selected small input bound.
  • UTF-8 assumptions: The harnesses instantiate the valid UTF-8 premise locally at inspected offsets. They do not independently prove whole-string UTF-8 validity.
  • Chunk abstraction: The inner fill-loop contract verifies the flag update at an arbitrary slot and the subsequent proof checks the exact sum of the resulting flags. The PR does not claim a complete functional proof of the total Unicode scalar count across an unbounded number of chunks.
  • Pattern abstraction: The symbolic searcher proves safety and state-transition properties for legal search responses. It does not claim to prove the matching semantics of every concrete pattern implementation.
  • Supplementary bounded checks: Concrete CharSearcher regressions, fixed-size Fold refinement checks, and the Chars::nth caller harness use bounded auxiliary domains. They do not bound any required Challenge 22 proof.
  • Termination: The proofs establish the stated safety properties and postconditions, not termination for every possible input.
  • Additional UB tooling: The repository's default CI configuration does not enable all valid-value, initialization, and aliasing checks. The Bytes contract has a separate successful uninitialized-memory check. Some additional advance_by checks remain limited by unsupported Kani/CBMC instrumentation, as documented in the related tooling issue.

Resolves #279

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@v3risec
v3risec requested a review from a team as a code owner October 27, 2026 09:07
@v3risec v3risec changed the title challenge 22 proof Challenge 22: Verify safety of str iter with Kani Oct 27, 2026
@feliperodri feliperodri added Maintenance Maintenance related issues for the challange Challenge Used to tag a challenge and removed Maintenance Maintenance related issues for the challange labels Oct 31, 2026
@feliperodri

Copy link
Copy Markdown
Member

@v3risec, running the str::iter::verify harnesses locally with the pinned Kani (9461e07, 6 jobs on a 16-core, 30 GB machine): 40 pass and 4 don't finish:

Harness Result
harness_chars_advance_by_all_counts CBMC out of memory
harness_chars_advance_by_extended_counts CBMC out of memory
harness_chars_advance_by_window_rank CBMC out of memory
harness_chars_advance_by_chunked timed out after 15 minutes

CI hits the same wall: "Verify std library (partition 2)" was killed with "The runner has received a shutdown signal" while running the str::iter harnesses, which is what happens when a job exhausts the 16 GB runner. Since the proofs have to run in CI, these four need to get smaller, for example by splitting the count ranges across several harnesses or lowering the bounds they use.

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is careful work: all 15 target functions and the __iterator_get_unchecked contract have harnesses, every assumption is followed by a reachability cover, the searcher stubs are checked against the real searchers in refinement harnesses, and nothing outside the verify modules changes. The static checks we run on every challenge PR (cfg body swaps, trivial invariants, contracts without a contract harness) are clean.

It doesn't meet the challenge yet, because Challenge 22 requires that "the verification must be unbounded---it must hold for str of arbitrary length", and the description says string lengths and windows remain bounded. The harnesses use backing buffers of at most 256 bytes and no loop invariants. #557 and #706 both claim unbounded string length for most targets, so this PR is currently behind them on the criterion that decides the challenge.

What would flip it: unbounded string length for all targets, including Chars::advance_by's chunk loop (loop invariants or a symbolic-length input that no loop is unwound over), and harnesses that complete within CI's resources.

Locally with the pinned Kani (9461e07): 40 of 44 harnesses pass; the 4 heaviest advance_by harnesses run out of memory or time out, and CI's partition 2 dies the same way (details in my comment above). Mutation testing: an off-by-one in SplitInternal::get_end fails 7 harnesses, one in next fails 6, and skipping one extra byte in Chars::advance_by fails 6, so the proofs do constrain the code within their bounds.

Comment thread library/core/src/str/iter.rs Outdated
// The backing array bounds CBMC's object model, not the number of
// iteration steps. Claims of arbitrary mathematical length require an
// additional argument beyond this finite allocation model.
const MAX_BYTES: usize = 256;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Challenge 22 requires the verification to hold "for str of arbitrary length". With a fixed 256-byte backing buffer, every harness here covers strings up to 256 bytes only, and the comment above this line says arbitrary length "requires an additional argument beyond this finite allocation model". Could the harnesses use a symbolic-length allocation that no loop is unwound over (as #557 and #706 do), with loop invariants where a loop does depend on the length?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the fixed backing buffers with symbolic-length allocations for all required proofs. Input-dependent loops use inductive invariants, and no required harness has an unwind bound. Lengths are limited only by CBMC’s object model (2^51 - 1 bytes with the current flags). Remaining bounded checks are supplementary dependency checks or exhaustive checks of fixed-size components.

Comment thread library/core/src/str/iter.rs Outdated
kani::cover(true, "C22-END: harness_chars_as_str completed");
}

const ADVANCE_MAX: usize = 8;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: advance_by is the hardest target to make unbounded, because of the chunk-skip loop. #706 reports that a loop invariant there hits kani#4893 and kani#4943 (the latter is fixed in kani#4948). Have you tried #[kani::loop_invariant] on that loop with the current pin (9461e07)?

@v3risec v3risec Nov 16, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. All four loops in the unchanged Chars::advance_by body now have inductive loop contracts, and the harness accepts an arbitrary usize count without an unwind bound. This passes now.

Comment thread library/core/src/str/iter.rs Outdated
// a byte, so 18 includes the final exhaustion call and loop-exit check.
#[kani::proof]
#[kani::unwind(18)]
fn harness_char_searcher_forward_refinement() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: checking the real CharSearcher against the stub's contract is what makes the stubbed iterator proofs trustworthy; without it, the stubs could be weaker than the real searcher and nothing would notice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retained the forward and reverse real-CharSearcher refinement checks; both pass locally. These remain bounded supplementary checks. The required unbounded iterator proofs rely on the Pattern correctness assumption explicitly permitted by Challenge 22.

let ptr_x = address_x as *const u8;
let ptr_y = address_y as *const u8;
// u8 has alignment one; prove this instead of filtering inputs.
assert!(ptr_x.is_aligned());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: turning the old kani::assume(ptr_x.is_aligned()) into an assertion strengthens the existing harness rather than weakening it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both alignment checks remain assertions. No alignment assumption was reintroduced.

Comment thread library/core/src/str/iter.rs Outdated
// is discharged against the original body, with Kani generating the
// precondition rather than the harness assuming the target's safety.
#[kani::proof_for_contract(Bytes::__iterator_get_unchecked)]
pub fn harness_bytes_iterator_get_unchecked() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: the __iterator_get_unchecked contract (idx < self.0.len()) is already on main; this harness is what verifies it, which is what the challenge asks for.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept the existing contract unchanged and retained the proof_for_contract harness. It now verifies the actual body over a symbolic-length byte window, including windows whose cursor is inside a multibyte UTF-8 sequence.

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Challenge 22 requires: "The verification must be unbounded---it must hold for str of arbitrary length." That requirement is final. A Kani solution will only be accepted if it is unbounded in the input size for every required function. This PR still verifies at least part of the challenge with bounded harnesses (kani::unwind bounds and/or fixed-size inputs), so I'm requesting changes until every required function is verified without a bound on the input size.

@v3risec

v3risec commented Nov 16, 2026

Copy link
Copy Markdown
Author

@feliperodri Reworked the bounded harnesses into symbolic-length proofs for all 15 required safe methods and the Bytes contract. The actual target bodies are unchanged. Chars::advance_by uses four inductive loop contracts and accepts any usize count; no required proof has an input-size or unwind bound. Remaining unwinds concern fixed-size components and supplementary dependency checks.

All 26 harnesses passed locally, including all 164 explicit cover goals, using stock CBMC 6.11.0. Lengths remain subject to CBMC's object-model limit (2^51 - 1 bytes on this target).

The remaining toolchain blocker is model-checking/kani#5071: it needs to merge and be included in this repository's Kani pin before CI can validate the same configuration. Local runs use Kani 0aac16ef plus that patch. Kani's unsupported UB checks remain a limitation.

@v3risec

v3risec commented Nov 16, 2026

Copy link
Copy Markdown
Author

The two advance_by harnesses fail in CI with Check that var_27 is assignable, consistent with the known loop-temporary write-set issue addressed by model-checking/kani#5071. Both pass locally with that patch and unmodified CBMC; CI needs a Kani pin containing the fix.

Infer the chunk loop write set while preserving exact fold consumption. Capture iterator state locally and remove obsolete searcher stubs.
@v3risec

v3risec commented Nov 18, 2026

Copy link
Copy Markdown
Author

@feliperodri I reworked the Chars::advance_by proof to run with the repository's current Kani pin. The outer loop now uses an inferred write set, which includes the compiler-generated chunks.next() temporary that caused the var_27 assignability failure. The exact fold model still consumes each flag before calling the fold closure, and constructs the new range directly so CBMC can infer the write target. This removes the dependency on model-checking/kani#5071.

The loop contracts capture the input locally, and the slice model is now limited to the endpoint-based as_slice view, with a separate equivalence check. I also removed obsolete concrete Pattern stubs, retained the real CharSearcher regressions, and consolidated the shared proof helpers. All 15 required safe methods and the existing Bytes::__iterator_get_unchecked contract remain covered.

Locally, stock Kani c5e65fdf and CBMC 6.11.0 passed 29 harnesses with 159/159 covers satisfied in serial runs. The standalone advance_by run took 278.9 s end to end with a 3.18 GB sampled peak. The fault-injection run caught 9/9 single faults by failing verification properties. GitHub CI for this revision is pending.

For #753, the current vendored Pattern is still a safe trait. The model already preserves the incoming haystack's pointer and length. It will need an unsafe impl after the subtree imports rust-lang#165681. The updated description includes timings, the injected faults, and the proof's assumptions and limits.

@v3risec

v3risec commented Nov 18, 2026

Copy link
Copy Markdown
Author

All CI checks passed. Ready for review.

@v3risec

v3risec commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

The update in 4f6b418a addresses the arbitrary-length and CI resource concerns raised in review. All four Kani partitions passed on Ubuntu and macOS on the first workflow attempt. The full local rerun passed 29/29 harnesses, including all 16 required targets, with 158/158 covers on the repository pin.

All required proofs use symbolic input lengths through CBMC's x86-64 limit of 2^51 - 1 bytes. Chars::advance_by accepts any usize request, executes the real slice::Iter::as_slice, and proves all four loops by induction. The side-effect-free invariants inspect havoced cursor and flag representations with read_via_copy before the loop uses them as NonNull<T> or bool. The symbolic harness also checks that the byte read agrees with the original input and verifies the returned suffix and its UTF-8 boundary.

The fold model consumes each flag before invoking the callback and asserts that it is used on 32-element Boolean storage. Its independent comparison with the real fold checks callback order and count, the result, and the final live range for every valid subrange. The PR adds zero explicit unwind annotations. The 16-byte input limit and asserted 17-step budget apply to the auxiliary CharSearcher regressions. The required Pattern proofs retain symbolic lengths.

The harnesses also exercise arbitrary interior UTF-8 windows, zero-length slices at arbitrary nonzero addresses, and Bytes cursors inside a multibyte scalar. The harnesses initialize storage before symbolic use and check decoded scalar validity explicitly. The Bytes contract also passed in separate runs with -Z uninit-checks and -Z valid-value-checks. The summary records the remaining tool coverage limits and the original-haystack guarantee used by the Split proofs. Tool coverage #733 · Pattern #753

@v3risec v3risec changed the title Challenge 22: Verify safety of str iter with Kani Challenge 22: Unbounded verification for str iter with Kani Nov 19, 2026
@v3risec

v3risec commented Nov 19, 2026

Copy link
Copy Markdown
Author

This follow-up strengthens the SplitInternal and Chars::advance_by proofs. The Split harnesses derive the expected result from legal search responses chosen before the call. They check the exact returned slice, remaining window, search cursor, and state flags, including both outcomes of a second reverse search after skipping a trailing empty piece.

For advance_by, the fill proof checks the update at an arbitrary flag slot. The chunk proof then checks that the actual decrement equals the number of UTF-8 character starts in that block. The consuming fold model is compared with real fold for every valid live subrange, including callback order and count, result, and final live range.

The required proofs cover symbolic string lengths throughout CBMC's representable domain. advance_by accepts any usize request, uses the real slice::Iter methods, and proves all four loops by induction. The 32 flags represent one production chunk. The bounded concrete searcher regressions supplement the symbolic-length Pattern proofs.

On top of 8ef46db7, the follow-up passed 17/17 affected and related harnesses with 105/105 explicit covers on the repository pin. The symbolic advance_by proof took 383.80 seconds in Kani and peaked at 4.84 GB sampled process-group RSS. Five targeted mutations failed explicit assertions, including the delimiter omission accepted by the earlier Split proof.

@v3risec

v3risec commented Nov 21, 2026

Copy link
Copy Markdown
Author

Update. Commit 1ef00e2f877 adapts the Kani-only ModelPattern implementation to the upstream unsafe trait Pattern. The safety comment documents why the model satisfies the contract: into_searcher stores the provided haystack slice, and ModelSearcher::haystack returns that same slice.

This addresses the E0200 compilation error in Kani and in ESBMC's contract-generation step after the toolchain update. Issue #753

@v3risec
v3risec requested a review from feliperodri November 22, 2026 09:19
Check exact match results and searcher transitions. Carry byte classification through the chunk fill invariant and compare advance_by's decrement with an independent count.

Check the local UTF-8 rule, simplify the consuming fold model, and prove the existing small_slice_eq contract. Add reachability covers without adding unwind bounds.
@v3risec

v3risec commented Nov 24, 2026

Copy link
Copy Markdown
Author

This follow-up addresses the arbitrary-length review requirement for all 15 safe methods and the existing Bytes::__iterator_get_unchecked contract. Every required harness runs the production target body with a symbolic string length through CBMC's x86-64 representable limit of 2^51 - 1 bytes. Chars::advance_by takes an arbitrary usize, and all four of its loops are proved by induction on the repository's pinned Kani.

  • advance_by now carries the byte-to-flag relation through the fill loop. The invariant follows an arbitrary slot and checks its value against the corresponding input byte at loop exit. The proof then compares the decrement in the production sum pipeline with an independent count of those flags. It uses the real slice::Iter methods, checks the scalar loop's byte against the original input, and checks the returned suffix and its UTF-8 boundary.
  • The fold proof preserves the actual callback and consumption semantics. The model consumes each live Boolean flag before calling the closure. The independent comparison with real fold checks the result, callback sequence and count, and exact final live range for every valid subrange of the 32-element array.
  • The four Matches and MatchIndices proofs check exact results and search calls. They choose legal responses before the call and check the exact slice, index where applicable, and resulting cursor. The searcher protocol proof now checks all four directional operations. The exact Split state-transition checks remain in place, including both outcomes after skipping a trailing empty piece.
  • The follow-up adds zero kani::unwind attributes. Both remaining attributes in the affected files are upstream small_slice_eq annotations. All 16 required targets retain their own symbolic-length proofs.
  • The proof premises are explicit. A separate harness checks the local UTF-8 sequence rule. The proofs use the challenge's valid UTF-8 premise and the imported Pattern contract's same-haystack guarantee. The summary records the default tool's UB coverage limits and the scope of the advance_by postconditions. Challenges 20/21/22/10: "Assumption 3" is now a safety requirement of unsafe trait Pattern (rust-lang/rust#165681) #753

The local runs passed 30/30 harnesses and 218/218 covers on Kani 9834c96c and CBMC 6.11.0 using the repository's default flags and one worker. The symbolic advance_by proof took 430.16 s in Kani with a sampled peak process-group RSS of 4.95 GB.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Challenge Used to tag a challenge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Challenge 22: Verify the safety of str iter functions

2 participants