Challenge 23: Verify Vec Part1 safety with Kani#598
Open
v3risec wants to merge 2 commits into
Open
Conversation
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-based verification artifacts for
VecAPIs inlibrary/alloc/src/vec/mod.rsfor Challenge 23.The change introduces:
#[cfg(kani)]for all Challenge 23 listedVecentriesVechelpers for allocated, ZST, bounded, and reserve-sensitive casesNo non-verification runtime behavior is changed in normal builds.
Notes on Challenge 23 Function Signatures
Several Challenge 23 names do not exactly match the current repository source. This PR follows the checked-in API definitions.
Notable alignments include:
from_nonnullis verified asVec::from_parts, the currentNonNull<T>raw-parts constructor.from_nonnull_inis verified asVec::from_parts_in.append_elements,split_at_spare_mut_with_len,extend_with,spec_extend_from_within,extend_desugared, andextend_trustedare verified from insidevec::mod, where those private paths are accessible.Verification Coverage Report
Coverage: 36 / 36 Challenge 23 entries targeted
Contract-backed unsafe/API groups include:
Vec::from_raw_partsVec::from_partsVec::from_parts_inVec::set_lenVec::append_elementsVec::split_at_spare_mut_with_lenHarness-backed coverage includes:
truncate,swap_remove,insert,remove,push,push_within_capacity,pop,clearappend,drain,split_off,extend_from_within,extend_with,spec_extend_from_within,extend_desugared,extend_trusted,extract_ifspare_capacity_mut,split_at_spare_mut,split_at_spare_mut_with_lenDeref,DerefMut,IntoIterator,Drop, and[T; N]::try_from(Vec<T>)Approach
The verification strategy combines function contracts with executable harnesses:
kani::requires,kani::ensures, andkani::modifiesclauses for unsafe pointer/length APIs where the source safety requirements can be expressed.#[kani::proof_for_contract]harnesses for contract targets and#[kani::proof]harnesses for safe and internal APIs.usize/isize, unit/ZSTs, fixed arrays, nested arrays, and a clone-only type.SetLenOnDropundercfg(kani)so normal builds preserve the original behavior.Scope assumptions
Tis represented through a broad set of concrete instantiations used by the harness macros.Verification
All added Challenge 23 harnesses pass locally with Kani.
Resolves #284
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.