Repository navigation
Conversation
feliperodri
left a comment
There was a problem hiding this comment.
Approving — leading solution for Challenge 7
Thanks @v3risec. Reviewed both open Challenge 7 solutions with our vacuity tooling and local Kani (pinned 0.67.0 / CBMC 6.8.0). This is complete and sound, and directly fixes the failure mode of the other solution (#578, whose contracts were decorative). Prioritizing it.
Coverage:
- Part 1: 12/12
from_ptrwith real#[requires](align + valid-for-read + valid-for-write) /#[ensures(ptr::eq)]and matching#[kani::proof_for_contract]— including AtomicI128/U128 (the exact gap that sank #578; the harnesses exist in source and compile on targets with 128-bit atomic support). AtomicPtr covered over pointee sizes 0/1/2/3/4 as the doc requires. - Part 2: all 14 unsafe atomic ops (store/load/swap/add/sub/compare_exchange(_weak)/and/nand/or/xor/max/umax/umin + atomic_min) with requires +
kani::modifies+ ensures + proof_for_contract across every width + isize/usize + *mut u8, plus ordering#[requires]on the safe methods and 6#[kani::should_panic]illegal-ordering proofs. - Part 3: intrinsic wrappers (const-generic intrinsics can't carry contracts directly — kani#3345) with proof_for_contract enumerating orderings/type matrix.
Soundness (all clean):
- T1: no cfg body swaps — fn bodies unchanged, only attributes +
useadded. - T2: n/a (no loops/invariants).
- T7: every contract has an explicit
proof_for_contract;.github/workflows/kani.ymlhas no atomic autoharness entries, so — unlike #578 — the contracts are genuinely checked, not decorative. - Not assume-the-conclusion; genuinely symbolic (
kani::any()values,any_ordering()families covering all legal variants, arbitrary pointer addresses). - No runtime std logic changed.
Local Kani (CBMC 6.8.0): 3/3 runnable-sample harnesses VERIFICATION SUCCESSFUL — harness_atomic_add_i32 (proof_for_contract), harness_safe_compare_exchange_panics_on_release (should_panic), harness_atomic_bool_from_ptr (proof_for_contract). harness_atomic_i128_from_ptr didn't register locally because 128-bit atomics are cfg-gated off on x86_64 — a target limitation, not an omission (the harness is present in source).
Note for the record: T-generic data-race / mixed-size overlapping-access UB is explicitly out of scope (Kani single-threaded model — consistent with the challenge, which points to concurrency being separate). Complete, sound, and the decisive improvement over #578.
|
@feliperodri Thanks for the thorough review and approval! I really appreciate the detailed validation. |
|
I added an explicit The explicit bound does not change the implementation being verified; it only controls loop unwinding in the proof harness. This is sound for these harnesses because Kani keeps unwinding assertions enabled: if two unwindings were insufficient to cover a feasible execution under the current model, the corresponding unwinding assertion would fail instead of silently truncating the proof. With This bound should be understood as a bound for these single-threaded verification harnesses under Kani's current atomic model, rather than as a general semantic bound on |
|
@v3risec, a consistency note after re-reviewing #587 (Ch27, Arc). Challenge 7's UB list requires the absence of data races, and this PR states that its harnesses are single-threaded and don't discharge that obligation. #587 is in the same position for Ch27. Both are approved as sound proofs toward their challenges, but neither solves its challenge on its own. Separately, CI doesn't pass You can address these in follow-up PRs. Whether solutions must cover data races, which Kani can't check, is being discussed in #733. |
feliperodri
left a comment
There was a problem hiding this comment.
@v3risec, changing my review to request changes so this isn't merged as a solution to Challenge 7.
Challenge 7's UB list requires the absence of data races, and this PR states that its harnesses are single-threaded and don't discharge that obligation. Kani can't check data races, so this is a gap in the tool rather than in the proofs. #733 asks the committee how solutions should be judged on it. Until that's decided, a PR that leaves out a listed UB item doesn't complete the challenge.
The proofs themselves remain sound and useful. Separately, this has merge conflicts with main after the recent subtree syncs; could you rebase it?
|
Thanks! I'm working on rebasing the PR. |
|
@feliperodri I have synchronized this branch with current CI passed for commit The changes are:
Regarding your note about
All 338 passed, and all 374 cover properties were satisfied. The 128-bit cases were not registered on this target because of its atomic capability configuration. The CI configuration does not enable No standard-library runtime function bodies were changed, and no Kani modifications were used for these verification results. The verification remains single-threaded and does not discharge the data-race obligation discussed in #733. |
Complete Challenge 7 (Atomic types and intrinsics) verification:
- Keep Kani contracts/harnesses in library/core with zero production body changes.
- Add zero-Python VeriFast companion proof and negative suite under
verifast-proofs/core/sync/atomic.rs{,-negative} wired into the existing
check-verifast-proofs{,-negative}.sh entrypoints (no workflow or shared Kani script edits).
- Cover all 12 Part 1 constructors, 14 Part 2 helpers + optional panics,
91 Part 3 intrinsic/ordering entries (810 x86-64 / 972 AArch64 integer
permissions, 25 pointer RMW edges), writable and read-only fractional
atomic borrows, 5 linked/executed POSIX two-worker clients, and 362
expected negative rejections.
- Document upstream EMULATE_ATOMIC_BOOL data-race bug rust-lang#166918
with standalone Miri reproducer.
|
@feliperodri I have updated the Challenge 7 submission with a complete, self-contained VeriFast concurrency & data-race companion proof alongside the Kani contracts:
Ready for another look whenever you have time! |
Summary
Resolves Challenge 7 (Safety of Methods for Atomic Types & Atomic Intrinsics) by combining Kani safety contracts/harnesses in
library/corewith a self-contained VeriFast concurrency and data-race companion proof inverifast-proofs/core/sync/atomic.rs/andverifast-proofs/core/sync/atomic.rs-negative/.Highlights
library/core/src/sync/atomic.rsandlibrary/core/src/intrinsics/mod.rscontain only Kani contract attributes and#[cfg(kani)]harnesses, with zerostub_verified, zeroassume(false), and zeroloop_invariant(true)added in Challenge 7 / this PR's changes..github/workflows/and sharedscripts/run-kani.share left untouched.from_ptrconstructors): Verified acrossx86_64-unknown-linux-gnu(10 integer widths +AtomicBool+AtomicPtr<T>) andaarch64-unknown-linux-gnu(addingAtomicI128/AtomicU128).atomic_store,atomic_load,atomic_swap,atomic_add,atomic_sub,atomic_compare_exchange,atomic_compare_exchange_weak,atomic_and,atomic_nand,atomic_or,atomic_xor,atomic_max,atomic_umax,atomic_umin(plusatomic_minvia Part 3), including continuing-unwind lifetime preservation on illegal orderings.doc/src/challenges/0007-atomic-types.mdvia MIR route and edge checks: 810 integer permissions onx86_64, 972 onaarch64, and 25 pointer RMW edges (fetch_byte_{add,sub},fetch_{and,or,xor}× 5 orderings, plusfetch_ptr_{add,sub}element scaling).coverproperties) onx86_64(200 / 198 onaarch64), binding 186 (216onaarch64) contracts insync/atomic.rsand 41 inintrinsics/mod.rstoproof_for_contractharnesses; direct callsite ordering checks confirm 4/4 legal controls accepted and 8/8 illegal orderings rejected.access,rmw,pointer-access,pointer-rmw,u32,readonly) overlaid on untouched copies oflibrary/core/srcwith Rust token-identity (source_tokens.rs), native MIR refinement, and compiled witness/production MIR bridge checks across bothx86_64andaarch64.frac == 1) and read-only fractional atomic borrows (0 < af < 1) split from full writable backing ownership[1](*p |-> val)(ruling out read-only.rodata/&'staticfractional shares without writable backing), permitting concurrent ordinary non-atomic reads alongside atomicloadand guaranteed-failingcompare_exchange(_weak)onAtomicBoolandAtomicU32, while rejecting potentially-writing CAS (including same-valuecurrent == new),store, RMWs, and concurrent ordinary writes.u32,boolean,pointer,width,readonly) are verified against witness-derived specifications, LLVM IR boundary-checked, linked against repositorycore, and executed on Linuxx86_64.verifast-core.patch(15 upstream files, 124 hunks, zeroRustConstPtrTypewidening) is audited 1-to-1 againstTRUSTED-BASE.mdwith positive and negative regressions acrossx86_64/aarch64andnormal/scopedexport modes.EMULATE_ATOMIC_BOOLtargets (riscv32/riscv64/loongarch32/loongarch64), failingAtomicBool::compare_exchange(_weak)performs an unconditional atomic RMW write (fetch_or(false)/swap), triggering Data Race UB with concurrent non-atomic reads under Miri (checks/upstream_bug_166918_miri.rs). Per General Rules, verification targets native 8-bit CAS platforms (x86_64-unknown-linux-gnuandaarch64-unknown-linux-gnu).Verification Results
bash verifast-proofs/check-verifast-proofs.sh: PASS (all existing proofs + Challenge 7 all 6 profiles and witness/production MIR checks onx86_64andaarch64, 5 two-worker POSIX clients verified, linked, and executed).bash verifast-proofs/check-verifast-proofs-negative.sh: PASS (362 expected rejections across tool regressions, MIR/checker soundness controls, update rollback faults, fractional-only backing rejection, and single/two-thread negative controls).verifast-proofs/core/sync/atomic.rs/README.md) on pinned Kani87c87010eda7797d7fa14033ca68bcbe17184a63(Kani 0.68.0,CBMC 6.11.0) in both default and-Z uninit-checksmodes: 176/176 harnesses PASS, 174/174 post-call covers satisfied, T7 metadata 186/41 complete,kani-negative-ordering.sh4/4 legal accepted and 8/8 illegal rejected.x86_64).Known Limitations & Remaining Committee Scope Notes
README.mdandTRUSTED-BASE.md: (1) operation-level overlapping mixed-width views (Gate 3-B), and (2) ordinary accesses after joining workers prior to ending the zero-runtime ghost borrow.ub_checks::can_dereference/can_write) nor VeriFast models OS page-tablePROT_READprotections; VeriFast requires full[1]writable ownership before constructing either writable or read-only fractional atomic borrows, and OS page-permission details are documented inREADME.mdandTRUSTED-BASE.md.Resolves #83
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.