Repository navigation
Conversation
|
@feliperodri Not exactly. The main differences are:
So I would describe this PR as an alternative and strengthening of the Challenge 21 portion of #538, rather than a direct complement. |
feliperodri
left a comment
There was a problem hiding this comment.
Review: PR #621 — Challenge 21 (StrSearcher safety)
Verdict rationale
This PR is substantially and qualitatively different from the rejected #538. It does not repeat #538's fatal pattern, and it does real, careful verification work. However, it fails two required criteria that the author openly acknowledges in-code, so it cannot be approved as-is.
It is NOT the #538 body-swap / assume-the-conclusion failure (credit where due)
I classified all 12 #[cfg(not(kani))] blocks. None compile out TwoWaySearcher::new/next/next_back and replace them with pure nondeterministic stubs. Instead:
- Boundary-repair loop swaps — forward
Searcher::next(pattern.rsdiff L96/L177 → kani at L115-145) and reversenext_back(L334/L362/L443): the realsearcher.next::<RejectAndMatch>(...)/next_back::<...>call is preserved; only thewhile !is_char_boundary(b) { b += 1 }repair loop is summarized. - Candidate-loop swaps —
continue 'search(L807, L1093) replaced by suffix summaries (kani_stub_after_failed_forward_candidate/...reverse...). - Inner byte-scan
for-loop swaps — (L820, L859, L1101, L1152) replaced bykani_scan_forward/kani_scan_reverse, which still indexneedle[index]/haystack[position+index]at a nondeterministic representative index over the complete scan interval (diff L590-598), so memory-safety of the real indexing is genuinely checked. - Empty-needle char decode (L68) — real
.chars().next()retained in non-kani; kani models it as a nondet width 1..=4 bounded by remaining bytes plus a UTF-8 boundary assumption.
The real control flow, arithmetic (self.position += i - self.crit_pos + 1, self.position += self.period, etc.), and state transitions of the Two-Way algorithm are executed for one representative candidate. This is legitimate loop summarization, not a function-body swap.
Assume-the-conclusion check (FATAL in #538): PASS. The UTF-8 boundary facts on the Match path (assume_valid_utf8_two_way_match_boundaries, diff L1821-1855; assume_valid_utf8_two_way_reverse_match_start, L1857-1877) are gated behind assert!s that the relevant needle bytes were byte-equal to the haystack over the full final character, and the needle is valid UTF-8. Assuming the boundary then follows from "byte-equality with a valid-UTF-8 needle transfers the char boundary" — which is exactly a UTF-8 decoding fact Challenge 21 explicitly permits importing (assumptions 2 and 3). This is a defensible proof cut, not a raw assumption of the type-invariant conclusion.
Invariant is non-trivial: PASS. type_invariant_two_way_searcher (diff L2430-2482) constrains cursor bounds, char-boundaries of position/end, 1 <= period <= needle_len, crit_pos/crit_pos_back bounds, long/short-period sentinel consistency (memory/memory_back), and short-period boundary summaries. It is meaningful, not true.
Proof harnesses exist: 15 challenge #[kani::proof] harnesses (1 empty constructor + 6 empty methods + 6 Two-Way methods), plus the 2 retained small_slice_eq proofs. Absence of proof_for_contract is fine here since the challenge is invariant-based, not contract-based.
Blocking issue 1 — Verification is NOT unbounded (mandatory criterion FAILS)
The challenge states: "The verification must be unbounded—it must hold for inputs of arbitrary size." This PR hard-bounds inputs:
pattern.rsdiff L1271:const MAX_UTF8_BYTES: usize = 16;any_valid_utf8_str(L1273-1282) takes&[u8; MAX]and slices a 16-byte array; every harness buildshaystack/needlefrom[u8; MAX_UTF8_BYTES](e.g. L2752-2755).
So needle.len(), period, crit_pos, position, end are all bounded by 16. The author acknowledges this directly at diff L2748-2749 ("the concrete haystack and needle models remain bounded by MAX_UTF8_BYTES") and in the PR description ("the current harness models do not constitute an arbitrary-length input proof"). Summarizing the loops removes unwind bounds but does not make the input size unbounded. This is a clear failure of a mandatory requirement.
Blocking issue 2 — Creation does not establish C for TwoWay (success criterion 1 FAILS)
Criterion 1 requires proving that a searcher created from any valid UTF-8 haystack satisfies C. This is done for the empty needle via harness_str_searcher_empty_into_searcher (diff L2557-2565), which calls the real needle.into_searcher(haystack). But for the core Two-Way case there is no constructor harness: TwoWaySearcher::new is never invoked (grep: 0 references), and the invariant is only kani::assumed (e.g. L2772). The author explicitly disclaims this at diff L2745-2747: "Establishing it for the production preprocessing algorithm is a separate proof obligation and is not claimed by this module."
This is a real gap, not a formality: because the hand-written invariant is never cross-checked against what TwoWaySearcher::new actually produces, the preservation proofs (criterion 3) run over a hand-specified state set that is never tied to reachable states. If that set under-approximates reachable states, criterion 3 coverage is incomplete; the constructor harness is what closes this.
Non-blocking observations
- The loop-state relations (
valid_two_way_*_loop_state) are used as bothassume(loop head) andassert(loop exit) but are not independently shown to be inductive; soundness of the suffix summaries rests on them. Worth a reviewer note even after the blockers are fixed. kani::assume(false)is used to prune the continued-loop path (e.g.next_rejectdiff L271) after the per-iteration safety asserts fire — acceptable idiom, but each such site should be double-checked to confirm every concrete exit (Reject/Match/Done) is reachable via the symbolic prefix.
Direction to author
- Make inputs unbounded: drive the loop summaries/
type_invariantoff symbolic lengths rather than a fixed 16-byte array, or otherwise remove the input-size bound, so the proof holds for arbitrary-size haystack/needle. - Add a Two-Way constructor harness that runs the real
into_searcher/TwoWaySearcher::newon a valid UTF-8 (needle, haystack) and assertstype_invariant_two_way_searcher, closing criterion 1 for the core algorithm.
Once these two are addressed, the approach here (real algorithm + Challenge-21-permitted UTF-8 imports + non-trivial invariant) is a strong basis for approval.
|
@feliperodri Thank you for the detailed review. I checked the issues and non-blocking concerns as follows. Blocking issue 2 This issue is addressed by It requires a non-empty needle, checks that the resulting implementation is Non-blocking observation 1 I manually checked the preservation obligations for the These summaries are therefore supported by a documented trusted argument, and their preservation obligations have been manually checked against the production control flow. This is an informal manual justification rather than a separate Kani harness proving inductiveness for every loop transition. Non-blocking observation 2 I also checked the relevant The other Unbounded verification I agree that the current verification is bounded rather than genuinely unbounded. I experimented with a symbolic The remaining proof has an explicit bounded scope: the Two-Way constructor harness covers haystacks of up to 4 bytes and non-empty needles of up to 3 bytes. Within that domain, the constructive generator reaches every valid UTF-8 string and This is a justified bounded verification, but I am not claiming that it satisfies the challenge’s literal requirement for arbitrary-size inputs. I would appreciate any further feedback on this scope or on ways to make the summaries and harnesses more precise. I would be happy to make further changes or optimizations based on your suggestions. |
Review — changes requested (Challenge 21)Thanks for the submission. To set expectations up front: there are two Challenge 21 solutions (this PR and #538), and we give preference to #538 — it verifies the real Concerns (local review, pinned Kani
Acceptance bar (same for both PRs): the solution can only be accepted if it presents an unbounded proof that completes within CI resource limits, verifying the real algorithm rather than assuming the safety property. |
feliperodri
left a comment
There was a problem hiding this comment.
Challenge 21 requires: "The verification must be unbounded---it must hold for inputs of arbitrary size." 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.
|
@feliperodri I have reworked the verification in response to your review. The old small-array input model is replaced by independently symbolic haystack and needle lengths up to (1 << 51) - 1, matching the CI pointer-model limit. Maximum-length covers have been added. The production algorithm statements are preserved. The old cfg(not(kani)) replacements and explicit assume(false) path cuts are removed. Search loops use nontrivial loop contracts. Constructor harnesses cover Empty, Byte, Long and Short; the six interface proofs check safety, UTF-8 result boundaries and preservation of C. Contracts have corresponding proof_for_contract harnesses, and verification assumptions/assertions have reachability covers. Following #740, I am keeping the std changes separate from the Kani fixes. The supporting fixes have now been submitted as 3 focused PRs:
Some results still use external GOTO/SMT profiles, so these 3 fixes alone have not yet been shown sufficient for normal CI. After the necessary fixes and integration work, I will update the Kani pin and rerun the full suite and CI. I would appreciate feedback on the updated proof structure while those tool dependencies are addressed. |
|
@feliperodri The latest local follow-up establishes
These results are for the local follow-up to |
|
The eight Kani partitions and the Upstream Kani |
|
@feliperodri Thanks for the earlier feedback. All eight Kani partitions now pass on Ubuntu and macOS for b75c0c0 with the repository’s updated Kani pin 9834c96ce90f. The final update splits the short-period forward proof cases and simplifies the range-agreement proof so they complete in CI. The real constructor establishes C in all four cases, and all six required search methods are verified over symbolic-length inputs with inductive search loops. This addresses the earlier review points on input bounds, constructor coverage, the real search implementations, and CI runtime. |
|
@feliperodri The revised PR covers the constructor and all six The proof setup now meets the unbounded input-size requirement for every required function. Haystack and needle lengths are symbolic across all applicable searcher cases, up to the CI pointer model’s representable allocation size. The search loops use inductive contracts, including both Empty match filters. The Challenge 21 proofs use no The current Kani pin
I’ll rerun the affected harnesses once the relevant fixes reach the repository pin. I’d be happy to help move the open Kani PRs forward by sharing reproducers or running regression tests if that would be useful. |
Summary
This PR targets Challenge 21. It adds constructor and safety proofs for
StrSearcheracross Empty, Byte, short-period Two-Way, and long-period Two-Way needles. The proofs establish a type invariantCat construction and check that each of the six search methods preservesCand returns only ordered, in-bounds ranges on UTF-8 character boundaries.Follow-up status. Verification of the revision described below on the official toolchain is pending the Kani fixes listed below and a pin update.
Proof approach
--object-bits 12represents allocations up to2^51 - 1bytes. The Empty and Byte cases have their inherent needle lengths of zero and one byte. The required proofs use nokani::unwindannotations or fixed-size test inputs. The two#[kani::unwind(4)]annotations inpattern.rsbelong to pre-existing upstream harnesses.C. Forward and reverse cursors are independently in bounds and on UTF-8 boundaries.Calso ties the Empty and Byte states to their needles, and records the preprocessing and cached-scan facts needed by the two Two-Way cases.1feeadd9379. The realstr::ceil_char_boundaryloop has its own inductive invariant and write set.Pattern::into_searcherand use separate preprocessing lemmas for critical positions and periods. The search harnesses compose step contracts and checked summaries of the raw Two-Way and boundary-rounding code. Verified stubs have correspondingproof_for_contractharnesses. Explicit assumptions and assertions in the Challenge 21 module have reachability covers.Required coverage
<&str as Pattern>::into_searcherC, including the preprocessing facts for both Two-Way cases.Searcher::nextMatchandRejectranges, and preservation ofCfor forward steps includingDone.Searcher::next_matchC, including the Empty filter loop.Searcher::next_rejectCacross the forward filter loop.ReverseSearcher::next_backMatchandRejectranges, and preservation ofCfor reverse steps includingDone.ReverseSearcher::next_match_backC, including the Empty reverse filter loop.ReverseSearcher::next_reject_backCacross the reverse filter loop. The challenge document calls itnext_back_reject.Kani dependencies and verification status
The current Kani pin is
9834c96ce90fwith CBMC 6.11.0. It already includes Kani #5134 for match-arm attributes, #5135 for generic trait-method stubs and contracts, and #5136 for nested quantifier captures.next_rejectandnext_reject_backloops need Kani to account for the anonymousmatchtemporary under their explicitloop_modifies.ibinding produced by its nested, contractedforloop. The remaining regression will determine whether the upstream nested-local or lifetime fix covers it. The regression must also reject omitted user writes under an explicit write set.On local diagnostic runs, the proposed rust-lang#4957 and rust-lang#5071 changes let both Byte reject harnesses pass with CBMC 6.11.0. The Short reverse case still reported
Check that i is assignablewhen the experimental destination rule was removed. The rule itself could incorrectly admit a user write, so results from that experimental compiler are diagnostic only. The previous successful CI at89ed906e12aapplies to the earlier proof revision.Once the needed fixes reach the repository pin, I will rerun the two Byte rejection harnesses, the raw Short forward and reverse proofs and their public callers, both Empty match filters, and
harness_ceil_char_boundary. I will report those results and the regular PR CI status against the updated pin.Resolves #278
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.