Challenge 4: Verify memory safety of BTreeMap node module with Kani - #684
Open
v3risec wants to merge 1 commit into
Open
Challenge 4: Verify memory safety of BTreeMap node module with Kani#684v3risec wants to merge 1 commit into
v3risec wants to merge 1 commit into
Conversation
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.
Summary
This PR adds Kani-based verification artifacts for operations in
library/alloc/src/collections/btree/node.rsfor Challenge 4.The change introduces:
LeafNode::init, including writable-memory preconditions andinitialization postconditions;
NodeRef,Handle, andBalancingContextoperations;and insertion paths used by the implementation;
their legal capacity ranges;
kani::coverproperties for the verified operation paths;No non-verification runtime behavior is changed in normal builds.
Verification Coverage Report
Initialization and basic node operations
The verification module includes harnesses for:
LeafNode::initLeafNode::newInternalNode::newNodeRef::as_internal_mutNodeRef::lenNodeRef::first_edgeNodeRef::last_edgeNodeRef::first_kvNodeRef::last_kvNodeRef::into_leafNodeRef::keysNodeRef::as_leaf_mutNodeRef::into_leaf_mutNodeRef::as_leaf_dyingNodeRef::pop_internal_levelNodeRef::pushRecursive and balancing operations
The following Challenge 4 operations have bounded harnesses:
NodeRef::new_internalHandle::insert_recursingBalancingContext::do_mergeBalancingContext::merge_tracking_child_edgeBalancingContext::steal_leftBalancingContext::steal_rightBalancingContext::bulk_steal_leftBalancingContext::bulk_steal_rightThe balancing harnesses use a shared fixture containing an internal parent
with two leaf children. Child lengths are symbolic over the node capacity
range, and each operation constrains its inputs according to the operation's
preconditions:
left_len + 1 + right_len <= CAPACITY;steal_leftrequires a non-empty left child and room in the right child;steal_rightrequires a non-empty right child and room in the left child;and destination capacity;
Approach
The verification strategy combines contracts with executable bounded harnesses.
Contracts for unsafe initialization
LeafNode::initis verified throughproof_for_contract, checking thatwrites target valid memory and establish the required metadata.
Shared symbolic fixtures
Nodes are constructed through
new_leaf,new_internal, andpush.This preserves the implementation's initialization and parent-linking
behavior instead of fabricating arbitrary raw pointers.
Behavioral postconditions
Harnesses check metadata, pointer relationships, node lengths, returned
handles, and parent links.
kani::coveris placed after the assertions toshow that the target path is reachable.
Bounded verification of recursive operations
Recursive and loop-heavy operations use bounded unwinding. The harnesses
cover symbolic legal node occupancies and operation parameters, while
keeping the fixed node capacity explicit.
Verification
All added Challenge 4 harnesses pass locally with Kani.
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.