Repository navigation
Challenge 27: Verify Arc and Weak safety with VeriFast and Kani - #817
Open
YuguangTong wants to merge 2 commits into
Open
YuguangTong wants to merge 2 commits into
YuguangTong wants to merge 2 commits into
Conversation
YuguangTong
marked this pull request as ready for review
December 3, 2026 00:18
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.
Addresses #383 (Challenge 27: Verify atomically reference-counted
Arc/Weakimplementation inlibrary/alloc/src/rcs/arc.rs).Summary & Coverage
This PR verifies
Arc,Weak,UniqueArc, andUniqueArcUninitinlibrary/alloc/src/rcs/arc.rsusing VeriFast 26.10 (concurrent separation logic + RustBelt semantic well-typedness) complemented by Kani 0.68.0 for the twodyn Anydowncast methods currently unsupported by VeriFast's frontend (Dynamic types are not yet supported).doc/src/challenges/0027-arc.md)pub unsafe fns (12 total)downcast_unchecked)>= 75%/ 44 required)downcast)assume_correctallocation helpers +rc::is_dangling)kani::cover)Tool Split & Key Artifacts
verifast-proofs/alloc/rcs/arc.rs/):atomic_model/: Trusted-extern_specforcore::sync::atomic(Relaxed/Acquire/Release/AcqRel+fence(Acquire)pending_acquire+ adversarial spurious CAS failure) + standalone 6-stateArc_invprotocol test (arc_weak_test.rs: 1,170 statements verified, 0 errors).verified/arc.rs: 3,634 statements verified, 0 errors across 11/12pub unsafe fns (full concurrent separation-logic contractsArc_own,Arc_own_in,Arc_raw_own,Weak_own,Weak_raw_own,full_borrow_content), 46/58 safe-with-unsafe fns (proven unconditionally safe under RustBelt semantic well-typedness), and 50 additional concurrent/helper fns (Arc::{downgrade, is_unique, strong_count, weak_count, deref},Weak::{new*, clone, strong_count, weak_count},UniqueArc::{new*, try_new*, weak_count, assume_init}, etc.).verify.sh: Runs VeriFast,refinement-checker(with exact full-body token equality enforced on BOTHverified/arc.rsandwith-directives/arc.rsfor the 23 frontend-limited functions),compat.patchcheck, anddiff original/arc.rs ../../../../library/alloc/src/rcs/arc.rs(0 diff).verifast-proofs/check-verifast-proofs.sh,verifast-proofs/patch-verifast-proofs.sh(update.sh), andverifast-proofs/README.md. Detailed proof tour & caveats inverifast-proofs/alloc/rcs/arc.rs/README.md.library/alloc/src/rcs/arc.rs, +92/-0 lines, 100%#[cfg(kani)]/#[cfg_attr(kani, ...)]):Arc<dyn Any + Send + Sync, A>::downcast_unchecked(#[cfg_attr(kani, requires((*self).is::<T>()))],#[cfg_attr(kani, ensures(|result| ub_checks::can_dereference(&**result as *const T)))], matchinglibrary/alloc/src/boxed/convert.rs).mod verify: 3#[kani::proof_for_contract]harnesses (i32with symbolic value + refcount 1 & 2,bool, ZST()), each passing a symbolic match/mismatch (if kani::any() { ... } else { Arc::new(0u16) }) sorequiresactively excludes invalid types whilekani::coverwitnesses non-vacuity, plus 1#[kani::proof]harnesscheck_downcastverifying bothOkandErrbranches (2/2kani::cover). Zero runtime code changes outsidecfg(kani).Trust Base & Audit Transparency
Full details are documented in
verifast-proofs/alloc/rcs/arc.rs/README.mdandverifast-proofs/alloc/rcs/arc.rs/atomic_model/TRUSTED-MODEL.md:atomic_model/TRUSTED-MODEL.md): Justified under C++20/Rust weak memory via RustBelt Relaxed (Dang et al., POPL 2020), enforcinghas_release/has_acquire/pending_acquire+ dual syntactic audit rules, backed by 6 negative soundness tests.assumeinventory: Zeroassume(false)in any executable function body and zero vacuous preconditions. Only 3 localized runtimeassumes, strictly inside aborting> MAX_REFCOUNToverflow branches (Arc::clone,Weak::clone,UniqueArc::downgrade) matching Rust's documented< isize::MAX - 1concurrent-thread assumption. Ghost lemmaassumes are limited to VeriFast 26.10 prelude/?Sized/issue-Update Kani Metrics #610/alloc_id.lft == 'staticgaps.assume_correct__VeriFast_wrapperstdlib/intrinsic shims inverified/arc.rs(including Rust-trait-gatedTrivialClone_slice_identity__VeriFast_wrapper<T: TrivialClone>and unforgeableValidValueMetadata<T>), 2 inverified/lib.rs, and 2 inverified/arc_pin.rsspec(intrinsics::abort,Pin::new_unchecked— pinning-invariant caveat documented inREADME.md).compat.patch: Minimal 6-line nightly-2026-09-25 shim (checked againstoriginal/arc.rson every run).Local Verification & Mutation Stress Testing
bash verifast-proofs/check-verifast-proofs.sh: exit 0 (linked_list.rs+raw_vec/mod.rs+rcs/arc.rs/atomic_model1,170 stmts +rcs/arc.rs3,634 stmts +refinement-checker+ all 3 diffs).bash verifast-proofs/check-verifast-proofs-negative.sh: exit 0../scripts/run-kani.shon all 4rcs::arc::verify::*harnesses: exit 0 (4/4verified,0failures, allkani::coverproperties satisfied).Arc::dropRelease->Relaxed, missingfence(Acquire),Arc::is_uniquestrong.loadAcquire->Relaxed&weak.storeRelease->Relaxed,Weak::innerskippingis_dangling,Arc::get_mutskippingis_unique,Weak::upgradeallowingn == 0) and 3/3 Kani contract/vacuity mutations caught (mismatched concrete type ->0/1 cover, removedrequires-> verification failure, negatedensures-> verification failure).