Skip to content

Commit 4f4d032

Browse files
authored
Add a challenge for btree::node module (#26)
This challenge is concerned with verifying the memory safety of BTreeMap's `btree::node` module. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent b0cc943 commit 4f4d032

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

doc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
- [Core Transmutation](./challenges/0001-core-transmutation.md)
1717
- [Memory safety of core intrinsics](./challenges/0002-intrinsics-memory.md)
1818
- [Pointer Arithmetic](./challenges/0003-pointer-arithmentic.md)
19+
- [Memory safety of BTreeMap's `btree::node` module](./challenges/0004-btree-node.md)
1920
- [Inductive data type](./challenges/0005-linked-list.md)

doc/src/challenges/0004-btree-node.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Challenge 4: Memory safety of BTreeMap's `btree::node` module
2+
3+
- **Status:** Open
4+
- **Tracking Issue:** [Link to issue](https://github.com/model-checking/verify-rust-std/issues/25)
5+
- **Start date:** *2024-07-01*
6+
- **End date:** *2024-12-10*
7+
8+
-------------------
9+
10+
11+
## Goal
12+
13+
Verify the memory safety of the [`alloc::collections::btree::node` module](https://github.com/rust-lang/rust/blob/c290e9de32e8ba6a673ef125fde40eadd395d170/library/alloc/src/collections/btree/node.rs).
14+
This is one of the main modules used for implementing the `BTreeMap` collection, and it includes a lot of unsafe code.
15+
16+
### Success Criteria
17+
18+
The memory safety of all public functions (especially safe ones) containing unsafe code must be verified, e.g.:
19+
20+
1. `LeafNode::new`
21+
1. `NodeRef::as_internal_mut`
22+
1. `NodeRef::len`
23+
1. `NodeRef::ascend`
24+
1. `NodeRef::first_edge`
25+
1. `NodeRef::last_edge`
26+
1. `NodeRef::first_kv`
27+
1. `NodeRef::last_kv`
28+
1. `NodeRef::into_leaf`
29+
1. `NodeRef::keys`
30+
1. `NodeRef::as_leaf_mut`
31+
1. `NodeRef::into_leaf_mut`
32+
1. `NodeRef::as_leaf_dying`
33+
1. `NodeRef::pop_internal_level`
34+
1. `NodeRef::push`
35+
1. `Handle::left_edge`
36+
1. `Handle::right_edge`
37+
1. `Handle::left_kv`
38+
1. `Handle::right_kv`
39+
1. `Handle::descend`
40+
1. `Handle::into_kv`
41+
1. `Handle::key_mut`
42+
1. `Handle::into_val_mut`
43+
1. `Handle::into_kv_mut`
44+
1. `Handle::into_kv_valmut`
45+
1. `Handle::kv_mut`
46+
47+
Verification must be unbounded for functions that use recursion or contain loops, e.g.
48+
49+
1. `NodeRef::new_internal`
50+
1. `Handle::insert_recursing`
51+
1. `BalancingContext::do_merge`
52+
1. `BalancingContext::merge_tracking_child_edge`
53+
1. `BalancingContext::steal_left`
54+
1. `BalancingContext::steal_right`
55+
1. `BalancingContext::bulk_steal_left`
56+
1. `BalancingContext::bulk_steal_right`
57+
58+
### List of UBs
59+
60+
All proofs must automatically ensure the absence of the following [undefined behaviors](https://github.com/rust-lang/reference/blob/142b2ed77d33f37a9973772bd95e6144ed9dce43/src/behavior-considered-undefined.md):
61+
62+
* Accessing (loading from or storing to) a place that is dangling or based on a misaligned pointer.
63+
* Reading from uninitialized memory.
64+
* Mutating immutable bytes.
65+
* Producing an invalid value
66+
67+
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
68+
in addition to the ones listed above.

0 commit comments

Comments
 (0)