Repository navigation
Conversation
Safety-precondition contracts and Kani harnesses for the Challenge 17 slice functions (library/core/src/slice/mod.rs): 43 harnesses in slice::verify — 10 unsafe (contracts; proof_for_contract where the impl resolves) and 27 safe (no-UB), should_panic pairs for the documented panics, and a kani::cover on every assume-bearing harness. Loop-bearing functions are verified at bounded lengths; genuine-unbounded and generic-T are disclosed in the PR description.
…2026-09-25, Kani 1640445) # Conflicts: # library/core/src/slice/mod.rs
feliperodri
requested changes
Nov 3, 2026
feliperodri
left a comment
Member
There was a problem hiding this comment.
Challenge 17 requires: "The verification must be unbounded---it must hold for slices 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.
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.
Towards #281. Verifies the safety of
core::slicefunctions with Kani (Challenge 17).Harnesses in
slice::verifyfor all 10 unsafe and all 27 safe functions;align_to,align_to_mut,reversepre-existing, unchanged. Each runs the real shipped body; additive, no#[cfg(kani)]rewrite. All pass viascripts/run-kani.shat Kani6ce55b9/ CBMC 6.11, with 33kani::coverreachability witnesses (all satisfied) and 4should_panicpairs.proof_for_contract, or a mirroredkani::assumefor theget_uncheckedtrio (Contracts below)run-kani.sh) and mutating-immutable-bytes (no Kani check class) are repo-wide gapsTContracts. Five unsafe fns (
swap_unchecked,split_at_unchecked/_mut_unchecked,as_chunks_unchecked/_mut) carry#[requires]+proof_for_contract. Theget_uncheckedtrio instead assume-mirrors theindex < lenprecondition:get_uncheckeddispatches through the genericSliceIndextrait, whose impls carry no#[requires]contract — onlyassert_unsafe_precondition!, with an index-type-specific bound — so there is nothing forproof_for_contractto target; the mirror states the concrete precondition and proves the same no-UB property.Bounded functions. Three take a
kani::unwindat a tool wall instead of an unbounded loop contract:binary_search_by(get_unchecked's precondition is not discharged when the comparator takes the element by reference);partition_dedup_by(an explicitloop_modifiescannot name the loop's compiler-generated temporaries); andswap_with_slice(the copy runs throughswap_nonoverlapping's shared chunked loop). A loop contract is size-independent, so each of these drops to unbounded once its upstream fix reaches this pin.rotate_left/rotate_rightverify all three algorithm arms (memmove,gcd,swap); thememmovearm is loop-free, thegcdandswaparms run under routine finite unwinds.Generic
T. Kani operates on concrete GOTO programs, so a single proof generic overTis not expressible; it is the open committee question (#734). The unsafe operations depend onsize_of,align_of, and drop glue, not type identity. Where a verified function branches on type size or alignment, the harnesses reach every arm:align_to/align_to_mutover theproof_for_contracttype matrix (align_of1–16 and the ZST arm), andptr_rotate'ssize_of-gated memmove/gcd/swap dispatch.Upstream Kani. We filed the
binary_search_byloop wall kani#4911 and its fix kani#4957 (open); it drops that bound once it lands.Verify with
scripts/run-kani.sh(the standard-Zflags,--object-bits 12).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.