Skip to content

Challenge 23: Unbounded verification of Vec Part 1 (36/36 functions, Kani + VeriFast) - #804

Open
EmreKaplaner wants to merge 2 commits into
model-checking:mainfrom
EmreKaplaner:ch23-vec-pt1
Open

EmreKaplaner wants to merge 2 commits into
model-checking:mainfrom
EmreKaplaner:ch23-vec-pt1

Conversation

@EmreKaplaner

@EmreKaplaner EmreKaplaner commented Nov 30, 2026 •

Copy link
Copy Markdown

Challenge 23: Unbounded Verification of alloc::vec::Vec Part 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 in library/alloc/src/vec/mod.rs (plus spec_extend_with.rs and set_len_on_drop.rs) using a multi-tool unbounded approach — 4 universally polymorphic generic-T VeriFast 26.10 proofs on normal-return portable paths paired with 33 monomorphic Kani unbounded proofs across 10 representative element types (-Z uninit-checks and partial -Z valid-value-checks remain unresolved under pinned Kani 0.68, and monomorphization vs. generic-T policy remains open under committee issue #734):

  • 33/36 functions verified in Kani (32 Kani-only + Vec::extend_with on SpecExtendWith<T: TrivialClone> — 213 Kani harnesses, 0 executable #[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], including 15 #[kani::should_panic] harnesses confirming at least one expected-class panic path is reachable, with zero trailing kani::assert(false, ...)) across symbolic capacities up to CBMC's object-model bound (MAX_ALLOCATION_BYTES = (1 << 51) - 1 under --object-bits 12, and usize::MAX for ZSTs; growth harnesses cap pre-growth capacity at MAX_ALLOCATION_BYTES / 2 so post-growth buffers stay representable), with 0 failures, 1,435 / 1,435 kani::cover properties satisfied (0 unreachable, 0 UNSATISFIABLE), full 0..cap valid typed-prefix initialization in allocate_vec_buffer_mode (including PaddedNiche and (char, u8)), MaybeUninit::uninit() spare-slot poisoning on extension harnesses with arbitrary newly published slot verification at write iteration on DropTracker/CloneZipFold and extend_trusted, legal over-allocated custom-allocator blocks with fitting-layout deallocation (OverAlloc), base-offset-0 interior-pointer rejection in vec_parts_valid, non-canonical zero-capacity pointers, and provenance-bearing plus non-canonical aligned ZST pointers (any_aligned_non_null_ptr).
  • 4/36 polymorphic user-callback / arbitrary-Drop loops verified in VeriFast 26.10 on normal-return portable paths (3 VeriFast-only — Vec::extend_desugared<I: Iterator<Item = T>>, Vec::retain_mut<F: FnMut(&mut T) -> bool>, and Vec::dedup_by<F: FnMut(&mut T, &mut T) -> bool> incl. Vec::dedup_tail — plus default fn SpecExtendWith::spec_extend_with<T: Clone> with SetLenOnDrop): verified strictly unbounded and universally polymorphic over arbitrary generic T, arbitrary Iterator / stateful FnMut, arbitrary Drop, and arbitrary A: Allocator on normal-return execution paths (-ignore_unwind_paths, portable non-SVE path) inside a single unified real-alloc VeriFast 26.10 crate (verifast-proofs/alloc/vec/mod.rs/, backed by real alloc::vec::Vec<T, A> and real alloc::raw_vec::RawVec<T, A> deterministically generated from accepted Challenge 19 PR #422 via sync_raw_vec.py and checked by python3 sync_raw_vec.py --check in verify.sh). Passes verifast (2,720 unified-crate statements verified, 0 errors, 0 assume(false)), standalone zero-assume companion set_len_on_drop_proof.rs (104 statements verified without -allow_assume, 7/8 production-derived + 1 surrogate-constructor scoped method-body checks + 0 assume enforcement against library/alloc/src/vec/set_len_on_drop.rs), both refinement-checker passes, all 3 byte-for-byte diff checks (vec/mod.rs, vec/spec_extend_with.rs, vec/set_len_on_drop.rs), update.sh / patch-verifast-proofs.sh registration, and a 6-mutant positive-controlled negative proof suite (verifast-proofs/alloc/vec/mod.rs-negative/).
  • Zero production body modifications & zero kani::loop_modifies in library/alloc/src/vec/mod.rs: shipped library/alloc/src/ non-Kani runtime execution bodies are untouched. library/alloc/src/lib.rs:217 enables #![feature(proc_macro_hygiene)]. library/alloc/src/vec/mod.rs adds #[cfg(kani)] use core::kani;, use safety::{ensures, requires};, Kani #[requires]/#[ensures] contracts on unsafe fns, the #[cfg(kani)] helper vec_parts_valid (vec/mod.rs:187), and private mod verify_ch23; (vec/mod.rs:174) under #[cfg(all(kani, not(no_global_oom_handling)))], with zero kani::loop_invariant / kani::loop_modifies annotations in vec/mod.rs (the 18 earlier monomorphic loop_modifies Kani harnesses for retain_mut and dedup_by were removed in favor of the polymorphic VeriFast proofs, which preserve all observable postconditions: len1 <= len0, len0 == 0 || len1 >= 1 for dedup_by, and exact base, cap, and alloc_id preservation). library/alloc/src/vec/set_len_on_drop.rs:28 adds one #[cfg(all(kani, not(no_global_oom_handling)))] helper (SetLenOnDrop::kani_trace_increment_len, calling verify_ch23::record_extend_trusted_len_ptr) for extend_trusted. library/alloc/src/vec/spec_extend_with.rs adds #[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 infallible TrivialClone specialization 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.sh flags, while -Z uninit-checks and partial -Z valid-value-checks remain unresolved under Kani 0.68 [§Strict-Flag Audit]. VeriFast 26.10 verifies spatial memory safety, initialized ownership array_at_lft/foreach(elems, own), absence of double-drop/use-after-free, and arithmetic bounds on normal-return paths for arbitrary generic T.)

# Challenge 23 Function Upstream Name (if renamed) Verification Tool Proven Domain & Unbounded Mechanism Harnesses / Scope
1 from_raw_parts Vec::from_raw_parts Kani (proof_for_contract) Symbolic cap up to 2^51-1 B (usize::MAX ZST), full typed-prefix init, base-offset-0, non-canonical zero-cap + provenance-bearing & non-canonical ZST ptrs 9 (u8, OverAligned, (), DropTracker, NonZero<u8>, PaddedNiche, (char, u8), NonPow2, AlignedZst)
2 from_nonnull Vec::from_parts Kani (proof_for_contract) Symbolic cap up to 2^51-1 B, base-offset-0, non-canonical zero-cap + provenance-bearing & non-canonical ZST ptrs 5
3 from_nonnull_in Vec::from_parts_in Kani (proof_for_contract) Symbolic cap up to 2^51-1 B, DropAlloc, OverAlloc (legal allocator slack + larger fitting-capacity dealloc + interior-pointer rejection) 8 (+2 OverAlloc: u8, OverAligned)
4 into_raw_parts_with_alloc Vec::into_raw_parts_with_allocator Kani Symbolic cap up to 2^51-1 B + DropAlloc 6
5 into_boxed_slice Vec::into_boxed_slice Kani Symbolic cap up to 2^51-1 B + model_shrinking_realloc 6 (+PaddedNiche)
6 truncate Vec::truncate Kani Symbolic cap up to 2^51-1 B + drop_tracker_slice_stub 5
7 set_len Vec::set_len Kani (proof_for_contract) Symbolic cap up to 2^51-1 B + can_dereference contract 5
8 swap_remove Vec::swap_remove Kani Symbolic cap up to 2^51-1 B + OOB should_panic (at least one panic reachable) 6
9 insert Vec::insert Kani Pre-growth cap <= 2^50-1 B + model_growing_realloc + OOB/ZST should_panic 9 (+LargeElem, +(char, u8))
10 remove Vec::remove Kani Symbolic cap up to 2^51-1 B + OOB should_panic 6
11 retain_mut Vec::retain_mut VeriFast 26.10 Polymorphic unbounded proof (both loops + 3-way partition, normal-return portable non-SVE path) over arbitrary T, stateful FnMut(&mut T) -> bool, arbitrary Drop, A: Allocator; proves len1 <= len0, exact base/cap/alloc_id, full survivor ownership, and public-API safety_proof Unified VF crate (2,720 total crate stmts) + negative OOB mutant
12 dedup_by Vec::dedup_by (+ dedup_tail) VeriFast 26.10 Polymorphic unbounded proof (search + gap-compaction loops, normal-return paths only) over arbitrary T, stateful FnMut(&mut T, &mut T) -> bool, arbitrary Drop, A: Allocator; proves len1 <= len0, `len0 == 0
13 push Vec::push Kani Pre-growth cap <= 2^50-1 B + model_growing_realloc + ZST overflow should_panic (all on CaDiCaL / MiniSat; 0 kissat) 8 (+PaddedNiche, +NonPow2)
14 push_within_capacity Vec::push_within_capacity Kani Symbolic cap up to 2^51-1 B 5
15 pop Vec::pop Kani Symbolic cap up to 2^51-1 B (arbitrary k, j, zero kani::assume tail restriction) 5
16 append Vec::append Kani Pre-growth caps <= 2^50-1 B + model_growing_realloc + ZST overflow should_panic 7 (+PaddedNiche)
17 append_elements Vec::append_elements Kani Pre-growth caps <= 2^50-1 B + model_growing_realloc 5
18 drain Vec::drain Kani Symbolic cap up to 2^51-1 B + invalid range should_panic (constructor; Drain::drop lives in library/alloc/src/vec/drain.rs, outside Ch. 23 & Ch. 24) 6
19 clear Vec::clear Kani Symbolic cap up to 2^51-1 B + drop_tracker_slice_stub 5
20 split_off Vec::split_off Kani Symbolic cap up to 2^51-1 B + OOB should_panic 6
21 leak Vec::leak Kani Symbolic cap up to 2^51-1 B 5
22 spare_capacity_mut Vec::spare_capacity_mut Kani Symbolic cap up to 2^51-1 B 5
23 split_at_spare_mut Vec::split_at_spare_mut Kani Symbolic cap up to 2^51-1 B 5
24 split_at_spare_mut_with_len Vec::split_at_spare_mut_with_len Kani (proof_for_contract) Symbolic cap up to 2^51-1 B 5
25 extend_from_within Vec::extend_from_within Kani Pre-growth cap <= 2^50-1 B + MaybeUninit::uninit() spare poison + model_growing_realloc + CloneZipFold (arbitrary newly published DropTracker slot verified at write iteration) 8 (+LargeElem, +DropTracker, invalid range, ZST overflow)
26 into_flattened Vec::into_flattened Kani Symbolic cap up to 2^51-1 B (N = 3, N = 0 ZST-element) + ZST overflow should_panic 7 (+n0_u8, +zst_overflow)
27 extend_with Vec::extend_with / SpecExtendWith::spec_extend_with Kani (TrivialClone) + VeriFast 26.10 (default T: Clone, normal-return paths + zero-assume SetLenOnDrop companion) Kani #[cfg_attr(kani, kani::loop_invariant/loop_modifies)] + MaybeUninit::uninit() spare poison; unified real-alloc VeriFast polymorphic proof proving full 0..len0+n element initialization from uninitialized array_at_lft_ spare capacity + zero-assume set_len_on_drop_proof.rs 7 Kani + unified VF crate (2,720 stmts) + 104 stmts set_len_on_drop_proof.rs
28 spec_extend_from_within ExtendFromWithinSpec::spec_extend_from_within Kani (proof_for_contract + CloneZipFold) Symbolic cap up to 2^51-1 B + MaybeUninit::uninit() spare poison; both TrivialClone (ptr::copy_nonoverlapping) and default T: Clone (DropTracker, arbitrary newly published slot verified at write iteration) 7 (+LargeElem, +PaddedNiche, +DropTracker)
29 deref <Vec<T, A> as Deref>::deref Kani Symbolic cap up to 2^51-1 B 5
30 deref_mut <Vec<T, A> as DerefMut>::deref_mut Kani Symbolic cap up to 2^51-1 B 5
31 into_iter IntoIterator for Vec<T, A>, &Vec<T, A>, &mut Vec<T, A> Kani Symbolic cap up to 2^51-1 B + DropAlloc + provenance-bearing & non-canonical aligned ZST ptrs (wrapping_byte_add_zst) + ref/mut-ref impls 13 (7 owned incl. AlignedZst + 3 &Vec + 3 &mut Vec)
32 extend_desugared Vec::extend_desugared VeriFast 26.10 Polymorphic unbounded loop proof (normal-return paths only) over arbitrary T, I: Iterator<Item = T>, A: Allocator in unified real-alloc crate Unified VF crate (2,720 total crate stmts) + negative OOB mutant
33 extend_trusted Vec::extend_trusted Kani Pre-growth cap <= 2^50-1 B + MaybeUninit::uninit() spare poison + unbounded #[kani::loop_invariant] over peeled SymbolicTrustedIter::for_each verifying arbitrary newly published slot target in 0..n at write iteration + kani_trace_increment_len 9 (+PaddedNiche, +AlignedZst, None overflow, ZST overflow)
34 extract_if Vec::extract_if Kani Symbolic cap up to 2^51-1 B + invalid range should_panic (constructor + 1st step; ExtractIf in extract_if.rs / Ch. 24) 6
35 drop <Vec<T, A> as Drop>::drop Kani Symbolic cap up to 2^51-1 B + DropAlloc + drop_tracker_slice_stub 8 (+LargeElem, +AlignedZst, +PaddedNiche)
36 try_from TryFrom<Vec<T, A>> for [T; N] Kani Symbolic cap up to 2^51-1 B (N = 3, N = 0) 6

(Sum of Kani harnesses across all 36 rows: 213 vec::verify_ch23::* harnesses (32 Kani-only functions + 1 dual-verified extend_with). All 4 VeriFast targets — Vec::extend_desugared, default fn SpecExtendWith::spec_extend_with, Vec::retain_mut, and Vec::dedup_by / dedup_tail — are verified together in a single VeriFast invocation over the unified alloc/vec/mod.rs crate totaling 2,720 verified statements, plus 104 verified statements in standalone zero-assume set_len_on_drop_proof.rs; note sync_raw_vec.py strips 6 uncalled Ch. 19 RawVec specs independently verified in verifast-proofs/alloc/raw_vec/mod.rs, so 2,720 is 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 || true against the verified commit 2c98de4171c0905392b86713dc4bfdbc00d97d5a (pushed as 0470eb1, whose sole delta from 2c98de4 is restoring upstream's patch_proof helper body in verifast-proofs/patch-verifast-proofs.sh and wording clarifications in verifast-proofs/alloc/vec/mod.rs/README.md — zero changes to any Rust source, Kani harness, or VeriFast proof file; base f94155ef2983580c9c012740b75793df2922d2e5) on Darwin 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), VeriFast 26.10 [sha256: b9b12f25e8868390cf3cfd307f562235c9d2c3b508ce1d888f9d04f2a115a940] with rustc 1.100.0-nightly (f7575a9da 2026-09-24)):

  1. Full vec:: Kani CI (scripts/run-kani.sh flags: --no-assert-contracts --jobs=6 --output-format=terse --cbmc-args --object-bits 12, 01_full_kani_vec.log):
    • 214 / 214 harnesses passed (213 vec::verify_ch23::* + 1 existing vec::verify::verify_swap_remove), 0 failures.
    • 1,435 / 1,435 kani::cover properties satisfied across all 213 / 213 Ch. 23 harnesses (0 unreachable, 0 UNSATISFIABLE).
    • Median Ch. 23 harness verification time: 1.89s; slowest harness: 93.69s (vec::verify_ch23::check_extend_from_within_drop_tracker; next slowest 67.00s on vec::verify_ch23::check_extend_trusted_overaligned).
  2. Full Non-Ch. 23 alloc Regression Check (02_alloc_regression.log):
    • 73 / 73 existing alloc harnesses passed, 0 failures (286 / 286 unique alloc harnesses passing across 01_full_kani_vec.log + 02_alloc_regression.log; vec::verify::verify_swap_remove appears in both runs).
  3. 100% End-to-End Apple Silicon macOS Per-Harness Peak RSS Audit (09_rss_e2e_report.txt & 09_rss_e2e_all.csv):
    • Warm-target, per-harness /usr/bin/time -l maxima across all 213 / 213 Ch. 23 harnesses via real kani verify-std --exact (cargo + goto-instrument --dfcc + cbmc) on Darwin arm64 (note: per-harness maxima do not directly establish concurrent multi-worker aggregate runner headroom):
      • 213 / 213 verified with rc == 0 and VERIFICATION:- SUCCESSFUL (0 solver-flag failures).
      • Median per-harness E2E peak RSS: 1,448.70 MiB (1.41 GiB).
      • Max per-harness E2E peak RSS: 3,195.09 MiB (3.12 GiB, vec::verify_ch23::check_extend_with_zst_capacity_overflow).
      • Harnesses >= 7,000 MiB: 0 (every individual harness peaks below 46% of 7 GiB; only 6 harnesses exceed 2,000 MiB: check_extend_with_zst_capacity_overflow 3,195.09 MiB, check_extend_trusted_overaligned 2,945.02 MiB, check_extend_with_overaligned 2,814.56 MiB, check_extend_with_aligned_zst 2,643.75 MiB, check_extend_with_zst 2,177.95 MiB, check_swap_remove_overaligned 2,118.66 MiB).
  4. Full VeriFast 26.10 CI (Positive & Negative, 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 Redux possible axiom inconsistency notice before its 0 errors found line; that notice belongs exclusively to the inherited Ch. 19 invocation and does not occur in the unified Ch. 23 alloc/vec/mod.rs run)
      • Unified real-alloc alloc/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), 0 assume(false), both refinement-checker passes (original -> with-directives -> verified), all 3 byte-for-byte diff checks (vec/mod.rs, vec/spec_extend_with.rs, vec/set_len_on_drop.rs), and python3 sync_raw_vec.py --check (3356 lines, 0 assume(false)).
      • Standalone companion verifast-proofs/alloc/vec/mod.rs/set_len_on_drop_proof.rs (run without -allow_assume): 0 errors found (104 statements verified), strictly zero assume, plus scoped brace-matched comment-stripped method-body sync check (7/8 production-derived methods + 1 surrogate constructor, 0 assume: OK).
    • verifast-proofs/check-verifast-proofs-negative.sh: exit 0 (note: unmodified upstream alloc/collections/linked_list.rs-negative is 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_base in both verifast and refinement-checker + set_len_on_drop_proof.rs in verifast), then dynamically injects 6 targeted 1-line faults (4 staged real-alloc + 2 non-overflowing companion) and requires exact mutated-term diagnostics in verifast plus clean ^ERROR: In function ... rejections (explicitly rejecting OCaml Fatal error exceptions) in refinement-checker:
      • extend_desugared OOB write (base_ptr.add(len + 1)): rejected by verifast on ptr_add_(base_ptr, (len0 + 1) and cleanly by refinement-checker.
      • default fn spec_extend_with OOB +2 advance (ptr.add(1).add(1)): rejected by verifast on Pointer may be out of bounds.*ptr_add_(ptr_add_(ptr0, 1 and cleanly by refinement-checker (^ERROR: In function <vec::Vec<T, A> as vec::spec_extend_with::SpecExtendWith<T>>::spec_extend_with, zero Fatal error).
      • retain_mut OOB read (g.v.as_mut_ptr().add(g.read + 1)): rejected by verifast on PanicGuard_read(g_cur) + 1 and cleanly by refinement-checker.
      • dedup_tail OOB read (start.add(gap.read + 1)): rejected by verifast on FillGapOnDrop_read(gap_cur) + 1 and cleanly by refinement-checker.
      • SetLenOnDropTrait::drop non-overflowing OOB writeback (*self.len = usize::MAX;): rejected by verifast (without -allow_assume) with Cannot prove 18446744073709551615 <= bound.
      • SetLenOnDrop::drop_writeback_exact non-overflowing wrong-value writeback (*self.len = self.local_len.wrapping_sub(1);): rejected by verifast (without -allow_assume) with Cannot prove $_3 == get_SetLenOnDrop_local_len(s0).
  5. Upstream Formatting & Non-Kani Compilation Parity (06_rustfmt_direct.log, 07_check_rustc.log, 08_nonkani_cargo_check.log):
    • Direct rustfmt +nightly-2026-11-21 --unstable-features --skip-children --edition 2024 --check using upstream rust-lang/rust rustfmt.toml across all 5 touched library/alloc/src/ files including verify_ch23.rs: exit 0 (06_rustfmt_direct.log).
    • ./scripts/check_rustc.sh (exact .github/workflows/rustc.yml CI; checked 7,462 files): exit 0 (0:00:36, 07_check_rustc.log).
    • Non-Kani RUSTFLAGS="--check-cfg cfg(kani)" cargo +nightly-2026-11-21 check --manifest-path library/alloc/Cargo.toml: exit 0 (0 errors, 0 warnings in alloc; 4 warnings in untouched library/core/src/, 08_nonkani_cargo_check.log).
  6. Hardened Property-Level 1-Line Mutation Kills (18 / 18 combined, 0 false kills, 0 survived — 10_mutants_12_kani.log & 04_verifast_negative.log):
    • run_mutants.py enforces all four strict kill criteria before counting any Kani mutant KILLED: (1) zero compile errors, (2) zero OOM/timeout/SIGKILL/CBMC aborts, (3) VERIFICATION:- FAILED with non-empty parsed Failed Checks:, and (4) at least one parsed Failed Checks: line matching an explicit per-mutant semantic property regex. Combined totals are parsed dynamically from CH23_VF_NEG_LOG (no hardcoded offset).
    • 12/12 Kani exact property-matched kills (0 false kills, 0 survived):
      • 7 memory-safety/UB kills: 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.
      • 5 contract/functional kills: 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 (CloneZipFold loop invariant), extend_from_within_skip_reserve (harness capacity assertion).
    • 6/6 VeriFast negative kills: 4 staged real-alloc OOB UB mutants (extend_desugared, default spec_extend_with, retain_mut, dedup_tail) + 2 non-overflowing companion SetLenOnDrop writeback mutants.
  7. Strict-Flag Diagnostic Audit (-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 / 21 passed, 14 / 21 not checkable under Kani 0.68 (0 invalid-value / niche-UB failures detected; 0 OOMs):
      • 7 passed (check_from_raw_parts_{aligned_zst,drop_tracker,nonpow2,overaligned,u8}, check_into_iter_aligned_zst, check_insert_large).
      • 11 failed exclusively with Kani 0.68's unsupported-check diagnostic Kani currently doesn't support checking validity of 'mutable cast' for *mut T inside upstream core/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 diagnostic Kani currently doesn't support checking validity of 'mutable cast' inside UnsafeCell::get (core/src/cell.rs:2439) on OverAlloc's Cell<Option<(NonNull<u8>, usize, Layout)>>.
      • 1 (check_extend_from_within_large) failed exclusively with Kani 0.68's unsupported-check diagnostic Kani currently doesn't support checking validity of 'copy_nonoverlapping' for *const LargeElem (core/src/ptr/mod.rs:587).
      • Value-validity checking for those 14/21 cases therefore remains unresolved under Kani 0.68 (upstream scripts/run-kani.sh does not enable -Z valid-value-checks).
    • -Z uninit-checks: 0 / 21 passed, 21 / 21 failed (0 OOMs):
      • Uninitialized-memory UB is NOT machine-checked by Kani 0.68 for the Kani-verified functions (whereas VeriFast 26.10 DOES machine-check full initialized ownership array_at_lft / foreach(elems, own) across 0..len on extend_desugared, default fn spec_extend_with, retain_mut, and dedup_by / dedup_tail).
      • Individual attribution across all 21 failures under Kani 0.68 -Z uninit-checks:
        1. Kani 0.68 RawVecInner / Vec MEM_INIT_STATE bug: false uninit reads on NonNull<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); and vec![1u8, 2, 3] vs. passing control_safe_array, recorded in 11_uninit_kani068_repro.log and included in the SHA-256 manifest).
        2. Kani 0.68 shadow-memory blindness to __CPROVER_array_set: __CPROVER_array_set initializes CBMC's value memory for 0..cap but does not mark Kani's separate shadow-memory map initialized, triggering drop_in_place / assert_is_initialized uninit diagnostics at core/src/ptr/mod.rs:875 and core/src/lib.rs:365.
        3. Kani 0.68 enum-niche / union / closure shadow-layout & mem_init.rs limitations: 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), and library/kani_core/src/mem_init.rs:{119,395}.

Honest Disclosure of Stubs, Solvers, Modeling Boundaries & Trust Boundaries

  1. Generic-T Monomorphization & Element Layouts (Tracking Issue #734):
    • Kani requires monomorphic harnesses; as tracked in open issue #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, hitting MIN_NON_ZERO_CAP == 1], PaddedNiche(NonZero<u8>, u32) [3B interior padding + niche], (char, u8) [3B trailing padding + niche]) — plus DropAlloc, TrackPtrAlloc, and OverAlloc (over-allocating, storing (orig_ptr, req_size, actual_layout) to enforce Rust's fitting-layout deallocation rule) custom allocators. into_flattened and try_from instantiate concrete N = 3 and N = 0; [T; 3] forwards HAS_PADDING, bulk_init_byte, when_non_zst, when_zst, and when_needs_drop from T.
    • allocate_vec_buffer_mode (verify_ch23.rs:397) initializes 0..cap bytes via CBMC's __CPROVER_array_set(raw.as_ptr(), T::bulk_init_byte(fill)) on *mut u8 before casting to NonNull<T> (zero ptr::write_bytes over padded structs), refreshes witness slots with typed ptr::write, and on extension harnesses (spec_extend_from_within, extend_from_within, extend_with, extend_trusted) explicitly poisons an arbitrary symbolic destination spare slot old_len + target with MaybeUninit::uninit() before invoking the target. On DropTracker (CloneZipFold) and extend_trusted (SymbolicTrustedIter), the loop contract verifies that iteration i == target overwrites that poisoned slot with the exact expected value for arbitrary symbolic target up to 2^50 - 1; on the TrivialClone ptr::copy_nonoverlapping (memcpy) and spec_extend_with paths, CBMC verifies bounds/non-overlap/assigns without per-element post-memcpy/quantified readback across 51-bit symbolic arrays (while VeriFast 26.10 proves full 0..len0+n element-by-element initialization from uninitialized array_at_lft_ spare memory for default fn spec_extend_with).
    • All 4 VeriFast proofs (Vec::extend_desugared, default fn spec_extend_with, Vec::retain_mut, Vec::dedup_by / dedup_tail) are universally polymorphic over arbitrary generic T, arbitrary Iterator / stateful FnMut, arbitrary Drop, and arbitrary A: Allocator on normal-return portable paths.
  2. All 7 Distinct Kani Stubs (56 total #[kani::stub] annotations in verify_ch23.rs):
    • crate::alloc::__rust_realloc -> model_growing_realloc (35x, verify_ch23.rs:1507) and model_shrinking_realloc (5x, verify_ch23.rs:2541): assert size ordering, Layout::from_size_align validity on both old_size and new_size, input alignment, and exact remaining extent, delegate to CBMC's C realloc, and assert new_ptr.is_null() || new_ptr.addr().is_multiple_of(align.as_usize()).
    • SetLenOnDrop::increment_len -> SetLenOnDrop::kani_trace_increment_len (7x, on extend_trusted non-overflow harnesses): Kani-only wrapper (set_len_on_drop.rs:28-37) executing self.local_len += increment identically while recording &raw mut self.local_len on the peeled iteration of SymbolicTrustedIter::for_each.
    • ptr::drop_in_place -> drop_tracker_slice_stub (3x, on check_{truncate,clear,drop}_drop_tracker, verify_ch23.rs:2081): models compiler-synthesized [DropTracker] drop glue; checks can_write, can_dereference, alignment, and checked_size_of_raw, reads a symbolic element, and adds count to DROPS (zero transmute_unchecked).
    • iter::zip -> capture_clone_zip (2x, verify_ch23.rs:3432) and <Zip<...> as Iterator>::fold -> CloneZipFold::fold (2x, impl at verify_ch23.rs:3464, fn fold at :3469): attach an unbounded #[kani::loop_invariant] to Zip::fold while executing zip.__iterator_get_unchecked(i) and both shipped map/for_each closures, mirroring upstream library/core/src/iter/adapters/zip.rs:277-292 (faithfulness to core's ZipImpl::fold is trusted).
    • <*mut ()>::wrapping_byte_add -> wrapping_byte_add_zst (1x, on check_into_iter_zst) and <*mut AlignedZst>::wrapping_byte_add -> wrapping_byte_add_zst (1x, on check_into_iter_aligned_zst, verify_ch23.rs:2870): asserts T::IS_ZST && !base.is_null() && base.is_aligned() and computes ptr::without_provenance_mut(base.addr().wrapping_add(offset)).
  3. Kani Modeling Boundaries & Solvers:
    • Object-size & growth domain: Under --object-bits 12, CBMC's maximum object size is MAX_ALLOCATION_BYTES = (1 << 51) - 1; growth harnesses cap pre-growth capacities at MAX_ALLOCATION_BYTES / 2 bytes (including on in-place paths within those growth harnesses), while ZSTs test up to usize::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): checks length <= capacity, non-null and aligned ptr, 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 pointer ptr.add(1) in verify_from_parts_in_overallocated), and in-bounds byte extent of at least capacity * size_of::<T>() (permitting legal custom-allocator over-allocation slack). As documented directly at mod.rs:181-185, three caller safety obligations are NOT machine-checked by this predicate and remain documented caller preconditions: (1) ptr was allocated via the matching Allocator instance, (2) ptr was allocated with T's exact alignment and a fitting layout (requested_size <= capacity * size_of::<T>() <= actual_size), and (3) the first length elements are initialized to valid values of T.
    • Abort-on-panic semantics: Kani compiles with -C panic=abort, so unwind-only drop guards (PanicGuard::drop in retain_mut and FillGapOnDrop::drop in dedup_tail) are not exercised by Kani; likewise VeriFast runs with -ignore_unwind_paths matching upstream linked_list.rs and raw_vec/mod.rs.
    • Platform-gated path: retain_mut's aarch64 SVE fast path (sve_retain.rs, gated by #[cfg(all(target_arch = "aarch64", target_feature = "sve"))]) is compiled out on x86_64 and Apple Silicon CI targets; the portable retain_mut implementation is verified unbounded in VeriFast 26.10.
    • Solvers: Harnesses use CBMC's default CaDiCaL (with down_from) and #[kani::solver(minisat)] (116 harnesses, with any_up_to and hoisted assertions per kani#4905). 0 #[kani::solver(kissat)] harnesses (check_push_nonpow2 runs on minisat).
  4. Local vs. Inherited VeriFast 26.10 Trust-Boundary Inventory & Upstream Attribution (verifast-proofs/alloc/vec/mod.rs/):
    • Upstream Attribution & MIT License Notice: Builds on and credits (1) VeriFast 26.10 (release 26.10, LICENSE.md, Copyright (c) 2008-2016 Katholieke Universiteit Leuven, MIT License — full verbatim MIT permission notice included in verifast-proofs/alloc/vec/mod.rs/README.md) for core Vec ownership/sharing predicates, Vec::{len, capacity, as_mut_ptr, set_len} idioms, call_fn_mut wrapper idiom, and staged non-vec support modules; and (2) Accepted Challenge 19 (verifast-proofs/alloc/raw_vec/mod.rs, PR #422), from which verified/raw_vec_mod.rs is deterministically generated via sync_raw_vec.py.
    • Zero assume(false) anywhere in verified/{vec_mod.rs, spec_extend_with.rs, set_len_on_drop.rs, raw_vec_mod.rs} or set_len_on_drop_proof.rs.
    • Single trusted RawVecInner::reserve spec (raw_vec_mod.rs:2675, //@ assume_correct at :2690): captures both capacity growth (len > capacity0 || len + additional <= capacity1, matching Ch. 19's verified RawVecInner::try_reserve at :1654, because VeriFast 26.10's preprocessor rejects specs on nested fn do_reserve_and_handle) and 0..len * elem_layout.size() byte-prefix preservation (because VeriFast 26.10's installed Allocator::grow spec returns uninitialized bytes). RawVec::reserve (raw_vec_mod.rs:1574) and Vec::reserve (vec_mod.rs:2095) are verified ghost wrappers on top of RawVecInner::reserve with zero extra assumes.
    • 6 stripped uncalled Ch. 19 specs (sync_raw_vec.py): RawVec::{into_box, with_capacity_in, shrink_to_fit}, RawVecInner::{with_capacity_in, shrink_to_fit}, and handle_error (independently verified in verifast-proofs/alloc/raw_vec/mod.rs).
    • 2 explicitly skipped internal SetLenOnDrop methods in the unified crate & standalone zero-assume companion (verified/set_len_on_drop.rs + set_len_on_drop_proof.rs):
      • In the unified crate, SetLenOnDrop::drop (verified/set_len_on_drop.rs:105-110) and specless SetLenOnDrop::increment_len (verified/set_len_on_drop.rs:83-85, bridged by set_len_on_drop_increment_one__VeriFast_wrapper) are skipped under -skip_specless_fns (due to VeriFast 26.10's elided-'_ Drop restriction and pub(super) safety-proof behavior), so spec_extend_with relies on SetLenOnDrop::drop preserving SetLenOnDrop_fbc (final_len <= len0 + n).
      • To independently verify those bodies with strictly zero assume statements, set_len_on_drop_proof.rs is checked by verify.sh without -allow_assume (104 statements verified, 0 assume), proving both SetLenOnDrop<'a> (exact &'a mut usize struct: new_checked, increment_len_checked, increment_len_preserves_bound, drop_writeback_preserves_fbc, drop_writeback_exact) AND a full Rust impl<'a> Drop for SetLenOnDropTrait<'a> carrying the unified crate's exact bounded SetLenOnDrop_fbc(s.len, bound) invariant (storing len: *mut usize + invariant PhantomData<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 from SetLenOnDrop_fbc), with verify.sh comparing 7/8 production-derived scoped executable method bodies against library/alloc/src/vec/set_len_on_drop.rs plus the 1 surrogate constructor SetLenOnDropTrait::new.
    • Local vs. Inherited assume(...) lines across all 5 local VeriFast files (9 local ghost assumes; vec_mod.rs:4345 is shipped Rust intrinsics::assume; set_len_on_drop_proof.rs has 0):
      • Inherited from upstream VeriFast 26.10 (tests/rust/safe_abstraction/vec/verified/vec/mod.rs:849-855): vec_mod.rs:940 (Vec_share_full lifetime-inclusion assumption absent from its precondition), plus VeriFast 26.10's installed std/lib.rsspec contracts (note: std/lib.rsspec:304 specifies ptr_offset_from in byte units rather than element units; none of the 4 verified loops invoke cross-allocation offset_from).
      • Added / replaced by Challenge 23 (8 verifast#610 upcast/subtype-monotone identity axioms replacing upstream/Ch. 19 assume(false) placeholders): vec_mod.rs:580,598,599, set_len_on_drop.rs:50, raw_vec_mod.rs:204,765,766,767.
    • Local //@ assume_correct directives across all 5 local VeriFast files (10 total: 1 reserve spec + 9 single-line wrappers verified for MIR refinement by refinement-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 require thread_token, full initialized prefix array_at_lft + foreach(elems, own), exclusive [q]lifetime_token(alloc_id.lft), and index < 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 for thread_token, a live full_borrow(k, Vec_exact_fbc(...)), and valid cursor ordering 0 <= write <= read <= orig_len; no req true; the guard-to-borrow link is established at the two call sites).
    • Staging & safety_stub.rs: verifast-proofs/alloc/vec/mod.rs/verify.sh stages unmodified non-vec support modules from $VERIFAST_HOME/tests/rust/safe_abstraction/vec/original (matching VeriFast 26.10's pinned nightly-2026-09-25 toolchain, auto-installed if absent) and compiles a 22-line no-op safety_stub.rs proc-macro for upstream use safety::{requires, ensures}; in boxed.rs/vec/into_iter.rs, while diff-checking original/{vec_mod.rs, spec_extend_with.rs, set_len_on_drop.rs} byte-for-byte against library/alloc/src/vec/ and enforcing python3 sync_raw_vec.py --check.

@EmreKaplaner
EmreKaplaner requested a review from a team as a code owner November 30, 2026 21:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant