Repository navigation
Conversation
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @v3risec. Reviewed against Challenge 4. This is much stronger than the other Ch4 attempts — 26/26 listed base fns each with a dedicated harness, all 8 recursion/balancing fns present, symbolic occupancy (len = kani::any_where(|l| *l <= CAPACITY) with symbolic keys/values built through the real push path), and #[kani::unwind(13)] fully unwinds the ≤12-edge relink loops — so for the CAPACITY-bounded loops a full-occupancy symbolic harness is genuinely complete. Clean soundness: no cfg body swaps, no trivial invariants, the one contract (LeafNode::init) has a matching proof_for_contract, no assume-the-conclusion.
Requesting changes on two real coverage gaps versus the criteria:
insert_recursingrecursion is never exercised.harness_insert_recursinginserts into an empty leaf root with spare capacity, soself.insertreturns(None, handle)and returns before theloop(node.rs:1068) — your own comment says "completed without splitting." The recursive/splitting path (the whole point of listing it as an unbounded fn) is dead. Please drive a full node that forces a split and ascends.- Balancing fns cover the leaf arm only.
do_merge,merge_tracking_child_edge,steal_left/right,bulk_steal_left/rightbuildnew_leafchildren, so the internal-node edge-array-copy + parent-relink arm is never taken. (#666's full-occupancy internaldo_mergeharness is worth borrowing for this.)
This is the prioritized Ch4 solution — close those two gaps (recursion + internal-node balancing arms) and it's approvable. Nice work on the symbolic-occupancy fixtures.
|
@feliperodri Thanks for the detailed review and suggestions. I’m currently working on the requested changes, in particular exercising the recursive/splitting path in @ivmat Thanks for the guidance! I’ll take a closer look at the |
Use unit K/V structural fixtures and narrower symbolic inputs for internal balancing paths while preserving edge movement, identity, and backlink checks.
|
I pushed the follow-up changes for the two coverage gaps from the review. The main changes are:
1.
|
feliperodri
left a comment
There was a problem hiding this comment.
Challenge 4 requires: "Verification must be unbounded for functions that use recursion or contain loops" That requirement is final. A Kani solution will only be accepted if it is unbounded in the input size for every required function. This PR still verifies at least part of the challenge with bounded harnesses (kani::unwind bounds and/or fixed-size inputs), so I'm requesting changes until every required function is verified without a bound on the input size.
|
@feliperodri The updated proof addresses the unbounded-verification requirement and the production-coverage gaps identified in the earlier reviews. 1. Unbounded verification Challenge 4 names 26 functions in its first success-criteria list and eight additional unbounded targets. This PR covers all 26 listed functions with Kani and all eight unbounded targets with VeriFast. The 48 Kani harnesses also include contract and supporting-operation checks; they are not a count of distinct production functions. VeriFast establishes the eight unbounded results over the production node layout, with generic No fixed bound on tree height or ancestor-chain length is used to establish these results. 2. VeriFast toolchain patches The production B-tree proof requires several Rust MIR and ownership features that are not fully supported by the current upstream VeriFast 26.10 frontend and refinement checker. I therefore currently build the pinned VeriFast version with 14 local patches. These patches add missing translation support, correct refinement behavior, and preserve Rust pointer, borrow, and unwind semantics required by the proof. They are grouped by purpose:
The patch README documents each individual patch, its necessity, the affected upstream code, and the corresponding rollback or regression evidence: These patches are part of the trusted toolchain, and I do not claim that the modified verifier itself has been formally verified. The correctness argument is based on preserving the relevant Rust MIR and ownership semantics, strengthening the refinement checks where necessary, removing inconsistent assumptions, and providing targeted regression and negative tests. 3. Upstream plan The patches are not intended to remain as a permanent local fork. Some changes overlap with existing upstream work, including #1062, #994, #1001, #1015, and #1023. The remaining changes are organized into seven focused upstream submissions covering Box projection, fixed-array MIR support, array-to-slice projections, scoped mutable borrowing, address scanning, Rust field provenance, and Rust MIR Drop unwind handling. I plan to submit these changes incrementally to upstream VeriFast, coordinating with existing PRs and prioritizing the provenance and Drop fixes. The separate 4. Verification results A fresh serial audit produced:
The audit rebuilt the pinned VeriFast tool from source and reproduced the proofs, comparisons, and mutation results. The B-tree positive proofs and mutation suite are integrated into the repository's existing VeriFast CI entry. |
Summary
This PR verifies the memory safety of
alloc::collections::btree::nodeusing complementary Kani and VeriFast proofs.Challenge 4 names 26 functions in its first success-criteria list and eight additional functions that require unbounded verification. This PR covers all 34 explicitly listed targets:
The verification also covers supporting production paths required by these proofs, including node initialization, parent-link repair, suffix movement, destruction, and root replacement.
The library changes add verification contracts and
cfg(kani)harnesses only. Normal runtime behavior is unchanged.Challenge 4 coverage
1. The 26 functions in the first success-criteria list
LeafNode(1)LeafNode::newNodeRef(14)as_internal_mut,len,ascend,first_edge,last_edge,first_kv,last_kv,into_leaf,keys,as_leaf_mut,into_leaf_mut,as_leaf_dying,pop_internal_level,pushHandle(11)left_edge,right_edge,left_kv,right_kv,descend,into_kv,key_mut,into_val_mut,into_kv_mut,into_kv_valmut,kv_mutAll 26 have dedicated Kani harness coverage.
2. The eight unbounded targets
NodeRef::new_internalHandle::insert_recursingBalancingContext::do_mergeBalancingContext::merge_tracking_child_edgeBalancingContext::steal_leftBalancingContext::steal_rightBalancingContext::bulk_steal_leftBalancingContext::bulk_steal_rightThe first list is not an exhaustive inventory of every relevant function in the module. The proof additionally covers supporting operations such as
LeafNode::init,InternalNode::new, handle constructors, sibling navigation, leaf removal,into_key_val,deallocate_and_ascend,consider_for_balancing,choose_parent_kv, marker transitions, parent-link repair,Handle::move_suffix, andNodeRef::drop_kvs.Approach
1. Kani: production methods and local contracts
The Kani verification module contains 48 proof harnesses.
proof_for_contractharnesses cover all six Kani contracts.RangeInclusiveiterator step used by the relinking proof and theNonZeroheight conversion used byNodeRef::new_internal.kani::coverproperties check initialization, pointer relationships, metadata, returned handles, and parent backlinks.Kani uses the pinned repository version and default verification settings. The B-tree harness group contains zero explicit
kani::assumecalls, stubs, or#[kani::unwind]annotations.The fixed node capacity bounds the storage of an individual node. It does not impose a bound on the tree height or ancestor chain in the VeriFast proofs.
2. VeriFast: unbounded insertion and balancing
The VeriFast proofs are generic over
KandVand use the productionCAPACITYand node layout.Insertion and root propagation
The insertion proof models the ancestor chain as an inductive list. Its loop invariant carries:
It covers insertion into a leaf, propagation through ancestors with available capacity, splitting a full internal parent, and installing a new root through all three production callbacks.
In particular, the proof checks the path:
No fixed bound on tree height or ancestor-chain length is used to establish this result.
Balancing
The balancing proofs cover both leaf and internal children. They use symbolic child heights, occupancies, donation counts, and tracked edge indices.
do_mergetransfers the separator and initialized entries, moves internal edges, repairs parent backlinks, and deallocates the right child using its actual layout.merge_tracking_child_edgechecks the tracked edge and its resulting location after merging.steal_leftandsteal_rightuse the verified bulk-steal operations with a donation count of one.bulk_steal_leftandbulk_steal_rightverify entry and edge transfers, shifts, and the affected parent-link repairs.Relinking and destruction
Additional loop proofs cover half-open and inclusive child relinking, suffix movement, and destruction of initialized key-value slots.
The destruction proof preserves the unwind behavior of generic key and value destructors. It checks the value guard after a panicking key destructor, the remaining initialized suffix, and the cleanup path when another destructor unwinds during an existing unwind.
3. Production correspondence
Following the accepted LinkedList and RawVec VeriFast solutions, the runner separates source identity, verification, and production correspondence.
It:
original/snapshots ofnode.rs,borrow.rs, andmem.rsagainst the repository'slibrary/sources.There are four MIR comparisons:
do_merge, destruction guards, accessors, navigation, and local operationsThe whole-function comparison follows both normal and unwind cleanup paths without inlining calls. It retains the owned allocator and
FnOncecall scopes.In particular, both MIR comparisons involving
do_mergeare assembled from the annotated proof. The runner checks the complete production scope, including unwind behavior, rather than relying on a disconnected hand-written merge transcription.The
wrong-layoutmutation changes the deallocation layout in the annotated merge proof. VeriFast and both production comparisons reject this mutation.4. Undefined-behavior obligations
The proofs address all four UB categories specified by Challenge 4.
MaybeUninitpayloads. Shared views derive initialization from the occupied prefix.VeriFast toolchain extensions and upstream plan
1. Why local VeriFast patches are currently required
The B-tree proof uses VeriFast 26.10. The current Rust frontend and refinement checker do not yet support several MIR shapes and Rust memory-model operations required by the production B-tree implementation.
To make these proofs possible without weakening their memory-safety obligations, this PR currently builds the pinned VeriFast version with 14 local tool patches.
The patches are applied by
verifast-proofs/alloc/collections/btree/node.rs/verifast-patches/build.sh. Their exact scope, rationale, rollback evidence, regression tests, and upstream status are documented in:verifast-patches/README.mdThe patches are grouped below by their purpose.
2. Patch inventory and correctness rationale
0001Raw pointer refinement;0010Address scanning aftermerge_fractions;0011Rust field provenance;0012Rust MIR Drop unwindDrop, calls, and assertions. These are necessary for checking production pointer operations, moved values, and destructor cleanup.0002Rust Box dereference unwind;0009Borrowed Box projection0003Fixed-array MIR index;0004Preserve initialized array values;0005Shared array-to-slice projection;0006Mutable array-to-slice projection;0008Array prefix indexing;0013Shared initialized slice;0014Raw slice accessRangeToindexing, initialized slice views, and raw slot projections. These operations are required for key/value storage, edge-array movement, andValMutaccess.0007Scoped mutable reference creationtrack_ref_creationdirective to invoke the existing fresh-mutable-reference rule for selected production places. This is required to model the scoped mutable projections used by the B-tree proof.3. Relationship with upstream VeriFast
These 14 patches are currently local changes; they have not all been merged into upstream VeriFast.
Some changes overlap with existing upstream work:
The remaining changes are organized into seven focused upstream submissions in the patch README:
merge_fractions.Dropunwind handling.I plan to submit these changes incrementally to upstream VeriFast, coordinating with existing PRs to avoid duplicating ongoing work. The Rust field-provenance and Drop fixes are prioritized because they address important refinement and soundness concerns independently of the B-tree proof.
4. Trusted boundary and regression evidence
These patches extend or correct VeriFast's Rust frontend, checker, and library support. They are therefore part of the trusted toolchain for this proof.
This PR does not claim that the modified verifier itself has been formally verified. Instead, the changes are accompanied by:
In particular, the patches do not replace the B-tree ownership proofs with additional unchecked permissions. They make the verifier preserve the pointer, initialization, borrow, lifetime, and unwind semantics required to express those proofs.
5. Separate library specification changes
In addition to the 14 tool patches, the runner applies
library-specs.patchto the pinned VeriFast library specifications.This is separate from the VeriFast frontend and checker patches. It supplies the proof-facing models needed for:
AllocatorCloneand allocator identity.RangeInclusiveiterator construction and advancement.NonZeroconversions.MaybeUninitinitialization and borrow permissions.ptr::copyanddrop_in_placebehavior, including unwind specifications.Optionand conversion operations.These specifications encode the preconditions, memory permissions, initialization state, and documented library guarantees used by the B-tree proofs. Their role and assumptions are documented separately in the B-tree proof README.
Verification results
Kani 0.68.0 / CBMC 6.11.0
VeriFast 26.10
The repository's VeriFast CI entry builds the pinned verifier and runs both the positive B-tree proofs and the B-tree-specific negative mutation suite.
Reproducing the checks
Run Kani:
./scripts/run-kani.sh --path . --kani-args --harness-timeout 1800 --jobs 1 \ --harness collections::btree::node::verify::Run the repository VeriFast entry, including the B-tree mutation suite:
The VeriFast patch rationale, rollback evidence, and upstream follow-up plan are documented in
verifast-patches/README.md.Resolves #77
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.