Repository navigation
Challenge 23: Unbounded verification of Vec Part 1 (36/36 functions, Kani + VeriFast) - #804
Open
EmreKaplaner wants to merge 2 commits into
Open
EmreKaplaner wants to merge 2 commits into
EmreKaplaner wants to merge 2 commits into
Conversation
EmreKaplaner
force-pushed
the
ch23-vec-pt1
branch
from
November 30, 2026 22:34
3aeb158 to
91877f8
Compare
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.
Challenge 23: Unbounded Verification of
alloc::vec::VecPart 1 (36/36 Functions Exercised/Verified, Kani + VeriFast)Addresses Challenge 23 (
doc/src/challenges/0023-vec-pt1.md, tracking issue#284) with 36/36 functions exercised/verified inlibrary/alloc/src/vec/mod.rs(plusspec_extend_with.rsandset_len_on_drop.rs) using a multi-tool unbounded approach —4universally polymorphic generic-TVeriFast 26.10 proofs on normal-return portable paths paired with33monomorphic Kani unbounded proofs across 10 representative element types (-Z uninit-checksand partial-Z valid-value-checksremain unresolved under pinned Kani 0.68, and monomorphization vs. generic-Tpolicy remains open under committee issue#734):32Kani-only +Vec::extend_withonSpecExtendWith<T: TrivialClone>—213Kani harnesses,0executable#[kani::unwind]caps,0#[kani::solver(kissat)]): verified unbounded in Kani (library/alloc/src/vec/verify_ch23.rs,175#[kani::proof]+38#[kani::proof_for_contract], including15#[kani::should_panic]harnesses confirming at least one expected-class panic path is reachable, with zero trailingkani::assert(false, ...)) across symbolic capacities up to CBMC's object-model bound (MAX_ALLOCATION_BYTES = (1 << 51) - 1under--object-bits 12, andusize::MAXfor ZSTs; growth harnesses cap pre-growth capacity atMAX_ALLOCATION_BYTES / 2so post-growth buffers stay representable), with 0 failures,1,435 / 1,435kani::coverproperties satisfied (0unreachable,0UNSATISFIABLE), full0..capvalid typed-prefix initialization inallocate_vec_buffer_mode(includingPaddedNicheand(char, u8)),MaybeUninit::uninit()spare-slot poisoning on extension harnesses with arbitrary newly published slot verification at write iteration onDropTracker/CloneZipFoldandextend_trusted, legal over-allocated custom-allocator blocks with fitting-layout deallocation (OverAlloc), base-offset-0 interior-pointer rejection invec_parts_valid, non-canonical zero-capacity pointers, and provenance-bearing plus non-canonical aligned ZST pointers (any_aligned_non_null_ptr).Droploops verified in VeriFast 26.10 on normal-return portable paths (3VeriFast-only —Vec::extend_desugared<I: Iterator<Item = T>>,Vec::retain_mut<F: FnMut(&mut T) -> bool>, andVec::dedup_by<F: FnMut(&mut T, &mut T) -> bool>incl.Vec::dedup_tail— plusdefault fn SpecExtendWith::spec_extend_with<T: Clone>withSetLenOnDrop): verified strictly unbounded and universally polymorphic over arbitrary genericT, arbitraryIterator/ statefulFnMut, arbitraryDrop, and arbitraryA: Allocatoron normal-return execution paths (-ignore_unwind_paths, portable non-SVE path) inside a single unified real-allocVeriFast 26.10 crate (verifast-proofs/alloc/vec/mod.rs/, backed by realalloc::vec::Vec<T, A>and realalloc::raw_vec::RawVec<T, A>deterministically generated from accepted Challenge 19 PR#422viasync_raw_vec.pyand checked bypython3 sync_raw_vec.py --checkinverify.sh). Passesverifast(2,720unified-crate statements verified,0errors,0assume(false)), standalone zero-assumecompanionset_len_on_drop_proof.rs(104statements verified without-allow_assume,7/8production-derived +1surrogate-constructor scoped method-body checks +0 assumeenforcement againstlibrary/alloc/src/vec/set_len_on_drop.rs), bothrefinement-checkerpasses, all 3 byte-for-bytediffchecks (vec/mod.rs,vec/spec_extend_with.rs,vec/set_len_on_drop.rs),update.sh/patch-verifast-proofs.shregistration, and a 6-mutant positive-controlled negative proof suite (verifast-proofs/alloc/vec/mod.rs-negative/).kani::loop_modifiesinlibrary/alloc/src/vec/mod.rs: shippedlibrary/alloc/src/non-Kani runtime execution bodies are untouched.library/alloc/src/lib.rs:217enables#![feature(proc_macro_hygiene)].library/alloc/src/vec/mod.rsadds#[cfg(kani)] use core::kani;,use safety::{ensures, requires};, Kani#[requires]/#[ensures]contracts onunsafe fns, the#[cfg(kani)]helpervec_parts_valid(vec/mod.rs:187), and privatemod verify_ch23;(vec/mod.rs:174) under#[cfg(all(kani, not(no_global_oom_handling)))], with zerokani::loop_invariant/kani::loop_modifiesannotations invec/mod.rs(the 18 earlier monomorphicloop_modifiesKani harnesses forretain_mutanddedup_bywere removed in favor of the polymorphic VeriFast proofs, which preserve all observable postconditions:len1 <= len0,len0 == 0 || len1 >= 1fordedup_by, and exactbase,cap, andalloc_idpreservation).library/alloc/src/vec/set_len_on_drop.rs:28adds one#[cfg(all(kani, not(no_global_oom_handling)))]helper (SetLenOnDrop::kani_trace_increment_len, callingverify_ch23::record_extend_trusted_len_ptr) forextend_trusted.library/alloc/src/vec/spec_extend_with.rsadds#[cfg(kani)] use core::kani;,#[cfg_attr(kani, kani::loop_invariant(i <= n))], and#[cfg_attr(kani, kani::loop_modifies(&i, ptr::slice_from_raw_parts_mut(ptr, n)))]on the infallibleTrivialClonespecialization loop.Complete 36/36 Function Coverage Matrix
(Note on UB classes: Kani harnesses verify memory safety, pointer validity/alignment/bounds, overflow, and functional/contract assertions under standard
scripts/run-kani.shflags, while-Z uninit-checksand partial-Z valid-value-checksremain unresolved under Kani 0.68 [§Strict-Flag Audit]. VeriFast 26.10 verifies spatial memory safety, initialized ownershiparray_at_lft/foreach(elems, own), absence of double-drop/use-after-free, and arithmetic bounds on normal-return paths for arbitrary genericT.)from_raw_partsVec::from_raw_partsproof_for_contract)2^51-1B (usize::MAXZST), full typed-prefix init, base-offset-0, non-canonical zero-cap + provenance-bearing & non-canonical ZST ptrsu8,OverAligned,(),DropTracker,NonZero<u8>,PaddedNiche,(char, u8),NonPow2,AlignedZst)from_nonnullVec::from_partsproof_for_contract)2^51-1B, base-offset-0, non-canonical zero-cap + provenance-bearing & non-canonical ZST ptrsfrom_nonnull_inVec::from_parts_inproof_for_contract)2^51-1B,DropAlloc,OverAlloc(legal allocator slack + larger fitting-capacity dealloc + interior-pointer rejection)+2OverAlloc:u8,OverAligned)into_raw_parts_with_allocVec::into_raw_parts_with_allocator2^51-1B +DropAllocinto_boxed_sliceVec::into_boxed_slice2^51-1B +model_shrinking_realloc+PaddedNiche)truncateVec::truncate2^51-1B +drop_tracker_slice_stubset_lenVec::set_lenproof_for_contract)2^51-1B +can_dereferencecontractswap_removeVec::swap_remove2^51-1B + OOBshould_panic(at least one panic reachable)insertVec::insert<= 2^50-1B +model_growing_realloc+ OOB/ZSTshould_panic+LargeElem,+(char, u8))removeVec::remove2^51-1B + OOBshould_panicretain_mutVec::retain_mutT, statefulFnMut(&mut T) -> bool, arbitraryDrop,A: Allocator; proveslen1 <= len0, exactbase/cap/alloc_id, full survivor ownership, and public-APIsafety_proof2,720total crate stmts) + negative OOB mutantdedup_byVec::dedup_by(+dedup_tail)T, statefulFnMut(&mut T, &mut T) -> bool, arbitraryDrop,A: Allocator; proveslen1 <= len0, `len0 == 0pushVec::push<= 2^50-1B +model_growing_realloc+ ZST overflowshould_panic(all on CaDiCaL / MiniSat; 0kissat)+PaddedNiche,+NonPow2)push_within_capacityVec::push_within_capacity2^51-1BpopVec::pop2^51-1B (arbitraryk, j, zerokani::assumetail restriction)appendVec::append<= 2^50-1B +model_growing_realloc+ ZST overflowshould_panic+PaddedNiche)append_elementsVec::append_elements<= 2^50-1B +model_growing_reallocdrainVec::drain2^51-1B + invalid rangeshould_panic(constructor;Drain::droplives inlibrary/alloc/src/vec/drain.rs, outside Ch. 23 & Ch. 24)clearVec::clear2^51-1B +drop_tracker_slice_stubsplit_offVec::split_off2^51-1B + OOBshould_panicleakVec::leak2^51-1Bspare_capacity_mutVec::spare_capacity_mut2^51-1Bsplit_at_spare_mutVec::split_at_spare_mut2^51-1Bsplit_at_spare_mut_with_lenVec::split_at_spare_mut_with_lenproof_for_contract)2^51-1Bextend_from_withinVec::extend_from_within<= 2^50-1B +MaybeUninit::uninit()spare poison +model_growing_realloc+CloneZipFold(arbitrary newly publishedDropTrackerslot verified at write iteration)+LargeElem,+DropTracker, invalid range, ZST overflow)into_flattenedVec::into_flattened2^51-1B (N = 3,N = 0ZST-element) + ZST overflowshould_panic+n0_u8,+zst_overflow)extend_withVec::extend_with/SpecExtendWith::spec_extend_withTrivialClone) + VeriFast 26.10 (default T: Clone, normal-return paths + zero-assumeSetLenOnDropcompanion)#[cfg_attr(kani, kani::loop_invariant/loop_modifies)]+MaybeUninit::uninit()spare poison; unified real-allocVeriFast polymorphic proof proving full0..len0+nelement initialization from uninitializedarray_at_lft_spare capacity + zero-assumeset_len_on_drop_proof.rs2,720stmts) +104stmtsset_len_on_drop_proof.rsspec_extend_from_withinExtendFromWithinSpec::spec_extend_from_withinproof_for_contract+CloneZipFold)2^51-1B +MaybeUninit::uninit()spare poison; bothTrivialClone(ptr::copy_nonoverlapping) anddefault T: Clone(DropTracker, arbitrary newly published slot verified at write iteration)+LargeElem,+PaddedNiche,+DropTracker)deref<Vec<T, A> as Deref>::deref2^51-1Bderef_mut<Vec<T, A> as DerefMut>::deref_mut2^51-1Binto_iterIntoIteratorforVec<T, A>,&Vec<T, A>,&mut Vec<T, A>2^51-1B +DropAlloc+ provenance-bearing & non-canonical aligned ZST ptrs (wrapping_byte_add_zst) + ref/mut-ref impls7owned incl.AlignedZst+3&Vec+3&mut Vec)extend_desugaredVec::extend_desugaredT,I: Iterator<Item = T>,A: Allocatorin unified real-alloccrate2,720total crate stmts) + negative OOB mutantextend_trustedVec::extend_trusted<= 2^50-1B +MaybeUninit::uninit()spare poison + unbounded#[kani::loop_invariant]over peeledSymbolicTrustedIter::for_eachverifying arbitrary newly published slottarget in 0..nat write iteration +kani_trace_increment_len+PaddedNiche,+AlignedZst,Noneoverflow, ZST overflow)extract_ifVec::extract_if2^51-1B + invalid rangeshould_panic(constructor + 1st step;ExtractIfinextract_if.rs/ Ch. 24)drop<Vec<T, A> as Drop>::drop2^51-1B +DropAlloc+drop_tracker_slice_stub+LargeElem,+AlignedZst,+PaddedNiche)try_fromTryFrom<Vec<T, A>> for [T; N]2^51-1B (N = 3,N = 0)(Sum of Kani harnesses across all 36 rows: 213
vec::verify_ch23::*harnesses (32Kani-only functions +1dual-verifiedextend_with). All 4 VeriFast targets —Vec::extend_desugared,default fn SpecExtendWith::spec_extend_with,Vec::retain_mut, andVec::dedup_by/dedup_tail— are verified together in a single VeriFast invocation over the unifiedalloc/vec/mod.rscrate totaling2,720verified statements, plus104verified statements in standalone zero-assumeset_len_on_drop_proof.rs; notesync_raw_vec.pystrips 6 uncalled Ch. 19RawVecspecs independently verified inverifast-proofs/alloc/raw_vec/mod.rs, so2,720is reported strictly as the unified crate total.)Clean-HEAD CI Evidence, 100% E2E macOS Peak RSS, Strict-Flag Diagnostic Audit & Mutant Kills
All verification runs below executed with zero
|| trueagainst the verified commit2c98de4171c0905392b86713dc4bfdbc00d97d5a(pushed as0470eb1, whose sole delta from2c98de4is restoring upstream'spatch_proofhelper body inverifast-proofs/patch-verifast-proofs.shand wording clarifications inverifast-proofs/alloc/vec/mod.rs/README.md— zero changes to any Rust source, Kani harness, or VeriFast proof file; basef94155ef2983580c9c012740b75793df2922d2e5) onDarwin 25.4.0 arm64(Apple Silicon,Kani Rust Verifier 0.68.0 (standalone),CBMC 6.11.0,rustc 1.102.0-nightly (c7d5ba59d 2026-11-20),rustfmt 1.12.0-nightly (c7d5ba59d8 2026-11-20), VeriFast26.10[sha256: b9b12f25e8868390cf3cfd307f562235c9d2c3b508ce1d888f9d04f2a115a940] withrustc 1.100.0-nightly (f7575a9da 2026-09-24)):vec::Kani CI (scripts/run-kani.shflags:--no-assert-contracts --jobs=6 --output-format=terse --cbmc-args --object-bits 12,01_full_kani_vec.log):214 / 214harnesses passed (213vec::verify_ch23::*+1existingvec::verify::verify_swap_remove),0failures.1,435 / 1,435kani::coverproperties satisfied across all213 / 213Ch. 23 harnesses (0unreachable,0UNSATISFIABLE).1.89s; slowest harness:93.69s(vec::verify_ch23::check_extend_from_within_drop_tracker; next slowest67.00sonvec::verify_ch23::check_extend_trusted_overaligned).allocRegression Check (02_alloc_regression.log):73 / 73existingallocharnesses passed,0failures (286 / 286uniqueallocharnesses passing across01_full_kani_vec.log+02_alloc_regression.log;vec::verify::verify_swap_removeappears in both runs).09_rss_e2e_report.txt&09_rss_e2e_all.csv):/usr/bin/time -lmaxima across all213 / 213Ch. 23 harnesses via realkani verify-std --exact(cargo+goto-instrument --dfcc+cbmc) onDarwin arm64(note: per-harness maxima do not directly establish concurrent multi-worker aggregate runner headroom):213 / 213verified withrc == 0andVERIFICATION:- SUCCESSFUL(0solver-flag failures).1,448.70 MiB(1.41 GiB).3,195.09 MiB(3.12 GiB,vec::verify_ch23::check_extend_with_zst_capacity_overflow).>= 7,000 MiB:0(every individual harness peaks below 46% of 7 GiB; only6harnesses exceed2,000 MiB:check_extend_with_zst_capacity_overflow3,195.09 MiB,check_extend_trusted_overaligned2,945.02 MiB,check_extend_with_overaligned2,814.56 MiB,check_extend_with_aligned_zst2,643.75 MiB,check_extend_with_zst2,177.95 MiB,check_swap_remove_overaligned2,118.66 MiB).03_verifast_positive.log&04_verifast_negative.log):verifast-proofs/check-verifast-proofs.sh: exit 0:alloc/collections/linked_list.rs:0 errors found (1541 statements verified)alloc/raw_vec/mod.rs:0 errors found (1690 statements verified)(note: this inherited standalone Ch. 19 invocation emits a VeriFast Reduxpossible axiom inconsistencynotice before its0 errors foundline; that notice belongs exclusively to the inherited Ch. 19 invocation and does not occur in the unified Ch. 23alloc/vec/mod.rsrun)allocalloc/vec/mod.rs(vec_mod.rs+spec_extend_with.rs+set_len_on_drop.rs+raw_vec_mod.rs):0 errors found (2720 statements verified),0assume(false), bothrefinement-checkerpasses (original->with-directives->verified), all 3 byte-for-bytediffchecks (vec/mod.rs,vec/spec_extend_with.rs,vec/set_len_on_drop.rs), andpython3 sync_raw_vec.py --check(3356 lines, 0 assume(false)).verifast-proofs/alloc/vec/mod.rs/set_len_on_drop_proof.rs(run without-allow_assume):0 errors found (104 statements verified), strictly zeroassume, plus scoped brace-matched comment-stripped method-body sync check (7/8production-derived methods +1surrogate constructor,0 assume: OK).verifast-proofs/check-verifast-proofs-negative.sh: exit 0 (note: unmodified upstreamalloc/collections/linked_list.rs-negativeis outside Ch. 23 scope and fails its VeriFast invocation on a pre-existing specification type mismatch before its refinement-checker check). Our Ch. 23 suite (alloc/vec/mod.rs-negative/verify.sh) first passes an unmutated positive control (verified_basein bothverifastandrefinement-checker+set_len_on_drop_proof.rsinverifast), then dynamically injects 6 targeted 1-line faults (4 staged real-alloc+ 2 non-overflowing companion) and requires exact mutated-term diagnostics inverifastplus clean^ERROR: In function ...rejections (explicitly rejecting OCamlFatal errorexceptions) inrefinement-checker:extend_desugaredOOB write (base_ptr.add(len + 1)): rejected byverifastonptr_add_(base_ptr, (len0 + 1)and cleanly byrefinement-checker.default fn spec_extend_withOOB +2 advance (ptr.add(1).add(1)): rejected byverifastonPointer may be out of bounds.*ptr_add_(ptr_add_(ptr0, 1and cleanly byrefinement-checker(^ERROR: In function <vec::Vec<T, A> as vec::spec_extend_with::SpecExtendWith<T>>::spec_extend_with, zeroFatal error).retain_mutOOB read (g.v.as_mut_ptr().add(g.read + 1)): rejected byverifastonPanicGuard_read(g_cur) + 1and cleanly byrefinement-checker.dedup_tailOOB read (start.add(gap.read + 1)): rejected byverifastonFillGapOnDrop_read(gap_cur) + 1and cleanly byrefinement-checker.SetLenOnDropTrait::dropnon-overflowing OOB writeback (*self.len = usize::MAX;): rejected byverifast(without-allow_assume) withCannot prove 18446744073709551615 <= bound.SetLenOnDrop::drop_writeback_exactnon-overflowing wrong-value writeback (*self.len = self.local_len.wrapping_sub(1);): rejected byverifast(without-allow_assume) withCannot prove $_3 == get_SetLenOnDrop_local_len(s0).06_rustfmt_direct.log,07_check_rustc.log,08_nonkani_cargo_check.log):rustfmt +nightly-2026-11-21 --unstable-features --skip-children --edition 2024 --checkusing upstreamrust-lang/rustrustfmt.tomlacross all 5 touchedlibrary/alloc/src/files includingverify_ch23.rs: exit 0 (06_rustfmt_direct.log)../scripts/check_rustc.sh(exact.github/workflows/rustc.ymlCI; checked 7,462 files): exit 0 (0:00:36,07_check_rustc.log).RUSTFLAGS="--check-cfg cfg(kani)" cargo +nightly-2026-11-21 check --manifest-path library/alloc/Cargo.toml: exit 0 (0errors,0warnings inalloc;4warnings in untouchedlibrary/core/src/,08_nonkani_cargo_check.log).18 / 18combined,0false kills,0survived —10_mutants_12_kani.log&04_verifast_negative.log):run_mutants.pyenforces all four strict kill criteria before counting any Kani mutantKILLED: (1) zero compile errors, (2) zero OOM/timeout/SIGKILL/CBMC aborts, (3)VERIFICATION:- FAILEDwith non-empty parsedFailed Checks:, and (4) at least one parsedFailed Checks:line matching an explicit per-mutant semantic property regex. Combined totals are parsed dynamically fromCH23_VF_NEG_LOG(no hardcoded offset).0false kills,0survived):split_off_copy_oob,spec_extend_from_within_trivial_copy_oob,spec_extend_with_trivial_write_oob,extend_trusted_write_oob,push_skip_grow,insert_copy_oob,remove_copy_oob.from_raw_parts_len_off_by_one(#[ensures]),set_len_off_by_one(#[ensures]),into_flattened_cap_oob(harness capacity assertion),spec_extend_from_within_clone_len_bump(CloneZipFoldloop invariant),extend_from_within_skip_reserve(harness capacity assertion).allocOOB UB mutants (extend_desugared,default spec_extend_with,retain_mut,dedup_tail) + 2 non-overflowing companionSetLenOnDropwriteback mutants.-Z valid-value-checks&-Z uninit-checks, 21 representative harnesses — DIAGNOSTIC COLLECTION,rc=1, NOT A PASSING CI GATE;05_strict_flags_summary.log,10of10_strict_valid_value.log,10of10_strict_uninit.log,11_uninit_kani068_repro.log):-Z valid-value-checks:7 / 21passed,14 / 21not checkable under Kani 0.68 (0invalid-value / niche-UB failures detected;0OOMs):7passed (check_from_raw_parts_{aligned_zst,drop_tracker,nonpow2,overaligned,u8},check_into_iter_aligned_zst,check_insert_large).11failed exclusively with Kani 0.68's unsupported-check diagnosticKani currently doesn't support checking validity of 'mutable cast' for *mut Tinside upstreamcore/src/ptr/{mut_ptr.rs:36, non_null.rs:560}on niche/ZST types ((char, u8),PaddedNiche,NonZero<u8>,()).2(check_from_parts_in_overallocated_{u8,overaligned}) failed exclusively with Kani 0.68's unsupported-check diagnosticKani currently doesn't support checking validity of 'mutable cast'insideUnsafeCell::get(core/src/cell.rs:2439) onOverAlloc'sCell<Option<(NonNull<u8>, usize, Layout)>>.1(check_extend_from_within_large) failed exclusively with Kani 0.68's unsupported-check diagnosticKani currently doesn't support checking validity of 'copy_nonoverlapping' for *const LargeElem(core/src/ptr/mod.rs:587).scripts/run-kani.shdoes not enable-Z valid-value-checks).-Z uninit-checks:0 / 21passed,21 / 21failed (0OOMs):array_at_lft/foreach(elems, own)across0..lenonextend_desugared,default fn spec_extend_with,retain_mut, anddedup_by/dedup_tail).-Z uninit-checks:RawVecInner/VecMEM_INIT_STATEbug: false uninit reads onNonNull<u8>/UsizeNoHighBit/usize(raw_vec/mod.rs:635,640,vec/mod.rs:3218), independently reproduced on pure safe Rust (let mut v: Vec<u8> = Vec::with_capacity(4); v.push(1);andvec![1u8, 2, 3]vs. passingcontrol_safe_array, recorded in11_uninit_kani068_repro.logand included in the SHA-256 manifest).__CPROVER_array_set:__CPROVER_array_setinitializes CBMC's value memory for0..capbut does not mark Kani's separate shadow-memory map initialized, triggeringdrop_in_place/assert_is_initializeduninit diagnostics atcore/src/ptr/mod.rs:875andcore/src/lib.rs:365.mem_init.rslimitations:TryReserveErrorKind(core/src/option.rs:1340),Option<(NonNull<u8>, usize, Layout)>(verify_ch23.rs:826),[MaybeUninit<LargeElem>](core/src/slice/raw.rs:208),ptr::write::<MaybeUninit<_>>(core/src/ptr/mod.rs:2009), closure layout (verify_ch23.rs:4098), andlibrary/kani_core/src/mem_init.rs:{119,395}.Honest Disclosure of Stubs, Solvers, Modeling Boundaries & Trust Boundaries
TMonomorphization & Element Layouts (Tracking Issue#734):#734(no finalized committee policy ruling yet), Kani harnesses instantiate across 10 representative element types — 2 ZSTs ((),AlignedZst), 4 unpadded types (u8,NonZero<u8>[constructed via#[repr(transparent)]transmute],DropTracker,NonPow2([u8; 3])), and 4 padded types (OverAligned(u8)[align(16), 15B padding],LargeElem(u8)[align(2048), 2047B padding, hittingMIN_NON_ZERO_CAP == 1],PaddedNiche(NonZero<u8>, u32)[3B interior padding + niche],(char, u8)[3B trailing padding + niche]) — plusDropAlloc,TrackPtrAlloc, andOverAlloc(over-allocating, storing(orig_ptr, req_size, actual_layout)to enforce Rust's fitting-layout deallocation rule) custom allocators.into_flattenedandtry_frominstantiate concreteN = 3andN = 0;[T; 3]forwardsHAS_PADDING,bulk_init_byte,when_non_zst,when_zst, andwhen_needs_dropfromT.allocate_vec_buffer_mode(verify_ch23.rs:397) initializes0..capbytes via CBMC's__CPROVER_array_set(raw.as_ptr(), T::bulk_init_byte(fill))on*mut u8before casting toNonNull<T>(zeroptr::write_bytesover padded structs), refreshes witness slots with typedptr::write, and on extension harnesses (spec_extend_from_within,extend_from_within,extend_with,extend_trusted) explicitly poisons an arbitrary symbolic destination spare slotold_len + targetwithMaybeUninit::uninit()before invoking the target. OnDropTracker(CloneZipFold) andextend_trusted(SymbolicTrustedIter), the loop contract verifies that iterationi == targetoverwrites that poisoned slot with the exact expected value for arbitrary symbolictargetup to2^50 - 1; on theTrivialCloneptr::copy_nonoverlapping(memcpy) andspec_extend_withpaths, CBMC verifies bounds/non-overlap/assigns without per-element post-memcpy/quantified readback across 51-bit symbolic arrays (while VeriFast 26.10 proves full0..len0+nelement-by-element initialization from uninitializedarray_at_lft_spare memory fordefault fn spec_extend_with).Vec::extend_desugared,default fn spec_extend_with,Vec::retain_mut,Vec::dedup_by/dedup_tail) are universally polymorphic over arbitrary genericT, arbitraryIterator/ statefulFnMut, arbitraryDrop, and arbitraryA: Allocatoron normal-return portable paths.56total#[kani::stub]annotations inverify_ch23.rs):crate::alloc::__rust_realloc -> model_growing_realloc(35x,verify_ch23.rs:1507) andmodel_shrinking_realloc(5x,verify_ch23.rs:2541): assert size ordering,Layout::from_size_alignvalidity on bothold_sizeandnew_size, input alignment, and exact remaining extent, delegate to CBMC's Crealloc, and assertnew_ptr.is_null() || new_ptr.addr().is_multiple_of(align.as_usize()).SetLenOnDrop::increment_len -> SetLenOnDrop::kani_trace_increment_len(7x, onextend_trustednon-overflow harnesses): Kani-only wrapper (set_len_on_drop.rs:28-37) executingself.local_len += incrementidentically while recording&raw mut self.local_lenon the peeled iteration ofSymbolicTrustedIter::for_each.ptr::drop_in_place -> drop_tracker_slice_stub(3x, oncheck_{truncate,clear,drop}_drop_tracker,verify_ch23.rs:2081): models compiler-synthesized[DropTracker]drop glue; checkscan_write,can_dereference, alignment, andchecked_size_of_raw, reads a symbolic element, and addscounttoDROPS(zerotransmute_unchecked).iter::zip -> capture_clone_zip(2x,verify_ch23.rs:3432) and<Zip<...> as Iterator>::fold -> CloneZipFold::fold(2x,implatverify_ch23.rs:3464,fn foldat:3469): attach an unbounded#[kani::loop_invariant]toZip::foldwhile executingzip.__iterator_get_unchecked(i)and both shippedmap/for_eachclosures, mirroring upstreamlibrary/core/src/iter/adapters/zip.rs:277-292(faithfulness tocore'sZipImpl::foldis trusted).<*mut ()>::wrapping_byte_add -> wrapping_byte_add_zst(1x, oncheck_into_iter_zst) and<*mut AlignedZst>::wrapping_byte_add -> wrapping_byte_add_zst(1x, oncheck_into_iter_aligned_zst,verify_ch23.rs:2870): assertsT::IS_ZST && !base.is_null() && base.is_aligned()and computesptr::without_provenance_mut(base.addr().wrapping_add(offset)).--object-bits 12, CBMC's maximum object size isMAX_ALLOCATION_BYTES = (1 << 51) - 1; growth harnesses cap pre-growth capacities atMAX_ALLOCATION_BYTES / 2bytes (including on in-place paths within those growth harnesses), while ZSTs test up tousize::MAX. Note also that Kani's feature support table lists mutation of immutable data (UnsafeCell/ provenance aliasing) as unsupported.vec_parts_valid(library/alloc/src/vec/mod.rs:187): checkslength <= capacity, non-null and alignedptr,Layout::array::<T>(capacity).is_ok(),ub_checks::can_write(slice_from_raw_parts_mut(ptr, capacity)), base-offset-0 via!kani::mem::same_allocation(ptr as *const u8, (ptr as *const u8).wrapping_byte_sub(1))(explicitly verified to reject interior pointerptr.add(1)inverify_from_parts_in_overallocated), and in-bounds byte extent of at leastcapacity * size_of::<T>()(permitting legal custom-allocator over-allocation slack). As documented directly atmod.rs:181-185, three caller safety obligations are NOT machine-checked by this predicate and remain documented caller preconditions: (1)ptrwas allocated via the matchingAllocatorinstance, (2)ptrwas allocated withT's exact alignment and a fitting layout (requested_size <= capacity * size_of::<T>() <= actual_size), and (3) the firstlengthelements are initialized to valid values ofT.-C panic=abort, so unwind-only drop guards (PanicGuard::dropinretain_mutandFillGapOnDrop::dropindedup_tail) are not exercised by Kani; likewise VeriFast runs with-ignore_unwind_pathsmatching upstreamlinked_list.rsandraw_vec/mod.rs.retain_mut'saarch64SVE fast path (sve_retain.rs, gated by#[cfg(all(target_arch = "aarch64", target_feature = "sve"))]) is compiled out onx86_64and Apple Silicon CI targets; the portableretain_mutimplementation is verified unbounded in VeriFast 26.10.down_from) and#[kani::solver(minisat)](116harnesses, withany_up_toand hoisted assertions perkani#4905).0#[kani::solver(kissat)]harnesses (check_push_nonpow2runs onminisat).verifast-proofs/alloc/vec/mod.rs/):Copyright (c) 2008-2016 Katholieke Universiteit Leuven, MIT License — full verbatim MIT permission notice included inverifast-proofs/alloc/vec/mod.rs/README.md) for coreVecownership/sharing predicates,Vec::{len, capacity, as_mut_ptr, set_len}idioms,call_fn_mutwrapper idiom, and staged non-vecsupport modules; and (2) Accepted Challenge 19 (verifast-proofs/alloc/raw_vec/mod.rs, PR #422), from whichverified/raw_vec_mod.rsis deterministically generated viasync_raw_vec.py.assume(false)anywhere inverified/{vec_mod.rs, spec_extend_with.rs, set_len_on_drop.rs, raw_vec_mod.rs}orset_len_on_drop_proof.rs.RawVecInner::reservespec (raw_vec_mod.rs:2675,//@ assume_correctat:2690): captures both capacity growth (len > capacity0 || len + additional <= capacity1, matching Ch. 19's verifiedRawVecInner::try_reserveat:1654, because VeriFast 26.10's preprocessor rejects specs on nestedfn do_reserve_and_handle) and0..len * elem_layout.size()byte-prefix preservation (because VeriFast 26.10's installedAllocator::growspec returns uninitialized bytes).RawVec::reserve(raw_vec_mod.rs:1574) andVec::reserve(vec_mod.rs:2095) are verified ghost wrappers on top ofRawVecInner::reservewith zero extraassumes.sync_raw_vec.py):RawVec::{into_box, with_capacity_in, shrink_to_fit},RawVecInner::{with_capacity_in, shrink_to_fit}, andhandle_error(independently verified inverifast-proofs/alloc/raw_vec/mod.rs).SetLenOnDropmethods in the unified crate & standalone zero-assumecompanion (verified/set_len_on_drop.rs+set_len_on_drop_proof.rs):SetLenOnDrop::drop(verified/set_len_on_drop.rs:105-110) and speclessSetLenOnDrop::increment_len(verified/set_len_on_drop.rs:83-85, bridged byset_len_on_drop_increment_one__VeriFast_wrapper) are skipped under-skip_specless_fns(due to VeriFast 26.10's elided-'_Droprestriction andpub(super)safety-proof behavior), sospec_extend_withrelies onSetLenOnDrop::droppreservingSetLenOnDrop_fbc(final_len <= len0 + n).assumestatements,set_len_on_drop_proof.rsis checked byverify.shwithout-allow_assume(104statements verified,0 assume), proving bothSetLenOnDrop<'a>(exact&'a mut usizestruct:new_checked,increment_len_checked,increment_len_preserves_bound,drop_writeback_preserves_fbc,drop_writeback_exact) AND a full Rustimpl<'a> Drop for SetLenOnDropTrait<'a>carrying the unified crate's exact boundedSetLenOnDrop_fbc(s.len, bound)invariant (storinglen: *mut usize+ invariantPhantomData<fn(&'a ()) -> &'a ()>because VeriFast 26.10's automatic Drop-glue check requires<&'a mut usize>.own == full_borrow('a, usize_full_borrow_content), which cannot be weakened fromSetLenOnDrop_fbc), withverify.shcomparing7/8production-derived scoped executable method bodies againstlibrary/alloc/src/vec/set_len_on_drop.rsplus the1surrogate constructorSetLenOnDropTrait::new.assume(...)lines across all 5 local VeriFast files (9local ghostassumes;vec_mod.rs:4345is shipped Rustintrinsics::assume;set_len_on_drop_proof.rshas0):tests/rust/safe_abstraction/vec/verified/vec/mod.rs:849-855):vec_mod.rs:940(Vec_share_fulllifetime-inclusion assumption absent from its precondition), plus VeriFast 26.10's installedstd/lib.rsspeccontracts (note:std/lib.rsspec:304specifiesptr_offset_fromin byte units rather than element units; none of the 4 verified loops invoke cross-allocationoffset_from).verifast#610upcast/subtype-monotone identity axioms replacing upstream/Ch. 19assume(false)placeholders):vec_mod.rs:580,598,599,set_len_on_drop.rs:50,raw_vec_mod.rs:204,765,766,767.//@ assume_correctdirectives across all 5 local VeriFast files (10total: 1 reserve spec + 9 single-line wrappers verified for MIR refinement byrefinement-checker):raw_vec_mod.rs:2690:RawVecInner::reserve,spec_extend_with.rs:17:clone__VeriFast_wrapper(val.clone()),spec_extend_with.rs:30:set_len_on_drop_increment_one__VeriFast_wrapper(guard.increment_len(1)),vec_mod.rs:5521:size_hint_lower__VeriFast_wrapper(it.size_hint().0),vec_mod.rs:5531:saturating_add_one_usize__VeriFast_wrapper(a.saturating_add(1)),vec_mod.rs:5539:call_fn_mut1__VeriFast_wrapper(f(a)),vec_mod.rs:5551:call_fn_mut2__VeriFast_wrapper(f(a, b)),vec_mod.rs:5560:hint_unlikely__VeriFast_wrapper(hint::unlikely(b)),vec_mod.rs:5613:vec_get_unchecked_mut__VeriFast_wrapper(v.get_unchecked_mut(index)— strengthened to requirethread_token, full initialized prefixarray_at_lft+foreach(elems, own), exclusive[q]lifetime_token(alloc_id.lft), andindex < len, returning a scoped exclusive element borrow restored after the callback),vec_mod.rs:5636:forget_vec_guard__VeriFast_wrapper(mem::forget(g)— requires caller-supplied ghost witnesses forthread_token, a livefull_borrow(k, Vec_exact_fbc(...)), and valid cursor ordering0 <= write <= read <= orig_len; noreq true; the guard-to-borrow link is established at the two call sites).safety_stub.rs:verifast-proofs/alloc/vec/mod.rs/verify.shstages unmodified non-vecsupport modules from$VERIFAST_HOME/tests/rust/safe_abstraction/vec/original(matching VeriFast 26.10's pinnednightly-2026-09-25toolchain, auto-installed if absent) and compiles a 22-line no-opsafety_stub.rsproc-macro for upstreamuse safety::{requires, ensures};inboxed.rs/vec/into_iter.rs, whilediff-checkingoriginal/{vec_mod.rs, spec_extend_with.rs, set_len_on_drop.rs}byte-for-byte againstlibrary/alloc/src/vec/and enforcingpython3 sync_raw_vec.py --check.