Repository navigation
Conversation
feliperodri
requested changes
Nov 3, 2026
feliperodri
left a comment
Member
There was a problem hiding this comment.
Challenge 10 requires: "Ones marked as unbounded must be verified for any string/slice length." That requirement is final. A Kani solution will only be accepted if the functions marked "(unbounded)" (from_utf16le, from_utf16le_lossy, from_utf16be, from_utf16be_lossy, remove_matches, retain, insert_str, split_off, replace_range) are verified without a bound on the string or slice length. This PR still verifies at least some of them with bounded inputs, so I'm requesting changes until all of them are unbounded.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR adds Kani proof harnesses for the 15
Stringfunctions targeted by Challenge 10 inlibrary/alloc/src/string.rs.It introduces 34 verification harnesses: 15 for normal execution and 19 for documented panic conditions. All harnesses exercise the real implementations. No production function bodies are changed or replaced with Kani-specific abstractions, and no
kani::assumeis used to assume the safety of the operations under test.Verification approach
Construct initialized, valid UTF-8 strings using zero-initialized buffers and complete encodings of symbolic Unicode characters.
Use symbolic string lengths, capacities, and indices to exercise pointer arithmetic, copying, reallocation, and boundary conditions.
Exercise real
ptr::copy,ptr::copy_nonoverlapping,Vec::splice, and iterator-based implementations.Use
kani::coverto demonstrate reachability of important paths, including reallocation, middle insertion/removal, multibyte character movement, and UTF-16 decoding cases.Keep the normal-path proofs separate from the panic proofs so that invalid inputs do not obscure memory-safety failures.
Coverage of the 9 unbounded-required functions
insert_strsplit_offreplace_rangeremove_matchesSearcher; up to 5 matchesretainfrom_utf16lefrom_utf16le_lossyfrom_utf16befrom_utf16be_lossyThe
insert_strandsplit_offproofs have no fixed small input-length bound, apart from CBMC's object model. The symbolic allocation limit is2^51 - 1under the configured--object-bits 12model.For
replace_rangeandremove_matches, the receiver length is symbolic, but the number of edited bytes or matches remains bounded. These are partial unbounded proofs, not full proofs over arbitrary edit or match counts.The remaining 5 functions are explicitly bounded because their real implementations contain input-dependent loops that cannot currently be verified without additional proof techniques.
Panic verification
The 19
#[kani::should_panic]harnesses cover:Indices strictly inside multibyte UTF-8 characters.
Indices beyond the end of a string.
removeat the end of the string.Invalid range endpoints and reversed ranges in
drainandreplace_range.The different panic causes are tested separately to avoid the vacuity problem where one reachable panic can mask another untested panic condition.
The five
replace_rangepanic harnesses are individual functions with#[kani::unwind(2)], avoiding unnecessary expansion of internalVec::Spliceloops on paths that should panic before the splice operation.UTF-8 and UTF-16 validity
All generated
Stringinputs are valid UTF-8 by construction.The
retainharness exercises its real implementation, including character iteration and byte movement. A Kani-only stub replacescore::str::from_utf8in the debug validation path, using an explicit UTF-8 byte validator for the bounded input. It does not replaceString::retainor its memory operations.The UTF-16 harnesses use an independent specification to check strict decoding success and the expected output length for lossy decoding. They cover aligned and unaligned inputs, odd lengths, surrogate pairs, and invalid surrogate sequences within the documented bounds.
Limitations
This PR does not claim to have completed all 9 strict unbounded requirements.
In particular:
replace_rangeandremove_matchesstill have bounded loop-dependent operations.retainand all 4 UTF-16 functions remain bounded.Kani's default memory-safety checks do not provide complete coverage of every Rust undefined-behavior category, including uninitialized reads and aliasing/immutability violations.
These restrictions are documented rather than hidden behind assumptions, disabled unwinding checks, or changes to the implementations under test.
Resolves #61
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.