Repository navigation
Conversation
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @kasimte, and apologies — this was also missed in the Challenge 26 round (created after our triage snapshot). Reviewed now.
This is excellent and essentially equal on verification merit to the solution we approved: 12/12 unsafe fns with genuine safety::{requires,ensures} + matching #[kani::proof_for_contract] (21 macro sites, sized + unsized/slice; real provenance/validity preconditions and checkable postconditions, satisfied by construction not assume) and ~54/54 safe abstractions (≥75%). Clean on T1/T2/T7, symbolic inputs, kani::cover non-vacuity witnesses, should_panic refcount-overflow twins.
Requesting changes for two reasons:
- One runtime-code edit.
Weak::dropis reformatted from upstream's one-liner (let inner = if let Some(inner) = self.inner() { inner } else { return };) to a 5-line block. Semantically identical, but per CLAUDE.md this repo must not change std runtime logic / must stay in upstream sync, and it will diverge from upstream rustfmt (risk ofcheck_rustc.shformat mismatch). Please revert that line. - Prioritization: we reviewed both open Ch26 solutions and approved #582 (v3risec) — same 12/12 real proof_for_contract + ~54/54 coverage, but with no runtime-source edit and a leaner harness count (yours expands to ~1,293 harnesses = higher CI cost). We're keeping this as the strong alternative.
Minor: 5 loop-bearing safe fns use #[kani::unwind(5)] (bounded, len-3 inputs) — fine and challenge-permitted, but a weaker guarantee than an inductive proof. Superb work; revert the Weak::drop reflow and it's a clean equal to #582.
715ea53 to
27dae19
Compare
|
Thanks @feliperodri — appreciate you circling back. Addressed both points:
I've re-requested review — thanks again for the careful read. |
27dae19 to
7f134cd
Compare
Rc::into_array now returns Result<Rc<[T; N]>, Rc<[T]>> instead of Option; adapt the harness binding and assertion accordingly.
The gotoc backend handles `abort` but not `abort_immediate`. As of nightly-2026-10-11, `core::intrinsics` no longer declares `abort`. `abort_immediate` is its renamed successor, and the standard library calls it directly (e.g. in `Rc`'s reference-count overflow guards). Harnesses reaching it fail with `Unsupported intrinsic abort_immediate`. This handles `abort_immediate` exactly like `abort`: reaching it is a failed assertion. Manual testing: against verify-rust-std at its nightly-2026-10-11 pin, the two `Rc` overflow `should_panic` harnesses in [model-checking/verify-rust-std#661](model-checking/verify-rust-std#661) fail with the unsupported-intrinsic error before this change and verify successfully with it. Resolves model-checking#5036 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
Towards #382. Solves Challenge 26: Safety of
Rc.Verifies the safety of
RcandWeakinalloc::rcwith Kani. The change is additive: one newmod verifyinlibrary/alloc/src/rc.rs, with no change to anystdruntime body. All 12 requiredpub unsafefunctions and all 54 listed safe functions carry Kani harnesses. Inputs are symbolic, and every input-bearing harness carries akani::coverwitness, so no harness passes vacuously. There are nocfg(kani)body swaps, so the code Kani verifies is the code that runs. All harnesses pass throughscripts/run-kani.sh.Scope follows the challenge. Generic
Tis limited to primitives, and allocator coverage isGlobal, both explicit and default.Systemlives instdand is not nameable fromalloc. To keep CI cost down, harnesses run over a fixed set of primitive types: i8, i128, u8, u128, bool, unit,[u8; 4], and[u8]/[u128]slices.Unsafe functions (12/12)
Each function is verified by
#[kani::proof_for_contract]against asafety::requiresprecondition. Eleven also carry asafety::ensurespostcondition. The four strong-count mutators assert the strong count changes by exactly ±1 and carrykani::modifiesframe conditions.Rc<MaybeUninit<T>, A>::assume_initrc_check_assume_initRc<[MaybeUninit<T>], A>::assume_initrc_check_assume_init_sliceRc<T>::from_rawrc_check_from_raw_{sized,unsized}Rc<T>::increment_strong_countRc<T>::decrement_strong_countRc<T, A>::from_raw_inRc<T, A>::increment_strong_count_inRc<T, A>::decrement_strong_count_inRc<T, A>::get_mut_uncheckedRc<dyn Any, A>::downcast_uncheckedVecpayloadsWeak<T>::from_rawWeak<T, A>::from_raw_inSafe functions (54/54)
Every function in the challenge table has a
rc_check_*harness, by API area:pin/pin_inuse a!Unpinsentinel.get_mut,make_mut,try_unwrap, anddowncastare each exercised across their documented states.From/FromIterator/TryFrom, including bothTryFrom<Rc<[T]>>match arms.unique/shared/weak_present, and theWeakmethods across live / dangling / strong-zero.RcInnerPtrrefcount ops and theUniqueRc/UniqueRcUninitfamily.The two
RcFromSlicepaths are both reached directly: theT: Copyspecialization (today'sTrivialCloneimpl) by primitives, and theT: Clonedefault through a manual-Clonewrapper, since no primitive reaches theClonedefault.Contracts
safety::{requires, ensures}. The fourmodifiesclauses usecfg_attr(kani, kani::modifies(...)), because thesafetycrate exposes nomodifieswrapper.ptr::addr_eq, checks size and alignment withkani::mem::checked_size_of_rawandchecked_align_of_raw, and requiresstrong >= 1. No contract constructs or consumes anRc.Soundness
kani::coverwitness (141 total), placed after the last assumption and before the operation under test (before the panicking operation inshould_panicharnesses). Every harness reportsN of N cover properties satisfied, so everykani::assumehas a reachability witness downstream of it.Some/None,Ok/Err, strong and weak count relations, pointer identity, post-dropupgrade()behavior, andmake_mut's clone-on-write and weak-disassociation effects. Constructor harnesses assert value preservation.inc_strongandinc_weakrefcount overflows, have#[kani::should_panic]harnesses. A sweep of the remainingassert!/panic!/unwrapsites found no other reachable guard under the documented preconditions: theLayout::array().unwrap()sites are unreachable under the layout-validity assumptions, and theTrustedLencapacity-overflow panic needs an iterator longer thanusize::MAX.Loop verification
from_iter_exact's element-writing loop is verified against the unmodified upstreamfor-loop by bounded unrolling, with#[kani::unwind(5)]over length-3 inputs and a justification in-code. A loop-contract formulation cannot carry the element-value postconditions these harnesses assert: under invariant havoc, no invariant relates an opaqueimpl Iterator's yielded prefix to the memory the harness checks.Bounds
sz <= 100, a CI tractability measure, not a safety precondition. Three sampled harnesses re-verify locally with the bound removed:clone_rc_vec_u8(22.4s),from_raw_vec_u8(40.5s), andget_mut_vec_u8_shared_none(35.2s), all with covers satisfied.assume_init_sliceharnesses carry the samelen <= 100bound for runner memory on wide element types. The unbounded form verifies on the Linux CI runners, but the widest variants exceed macOS runner memory.len 3, andN = 100ininto_array) carry in-code justifications.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.