Skip to content

Commit 10224fd

Browse files
committed
Challenge 25: Verify safety of VecDeque
Verify all 43 functions listed in the challenge specification. 44 Kani proof harnesses, 0 failures. Part A: Safety contracts (#[requires]/#[ensures]) and proof_for_contract harnesses for 13 unsafe functions — buffer_read, buffer_write, buffer_range, push_unchecked, copy, copy_nonoverlapping, copy_slice, wrap_copy, write_iter, write_iter_wrapping, handle_capacity_increase, from_contiguous_raw_parts_in, abort_shrink. Part B: Proof harnesses for 30 safe abstractions — get, get_mut, swap, reserve, try_reserve, shrink_to, truncate, as_slices, as_mut_slices, range, range_mut, drain, pop_front, pop_back, push_front, push_back, insert, remove, split_off, append, retain_mut, grow, resize_with, make_contiguous, rotate_left, rotate_right, and others. All harnesses exercise returned values (iterators consumed, slices accessed, pointers dereferenced) to ensure full unsafe path coverage. Resolves #286
1 parent 2840898 commit 10224fd

File tree

2 files changed

+769
-21
lines changed

2 files changed

+769
-21
lines changed

doc/src/challenges/0025-vecdeque.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,64 @@ All proofs must automatically ensure the absence of the following undefined beha
8787

8888
Note: All solutions to verification challenges need to satisfy the criteria established in the [challenge book](../general-rules.md)
8989
in addition to the ones listed above.
90+
91+
## Verification Summary
92+
93+
All 13 Part A unsafe functions and all 30 Part B safe abstractions have been verified using Kani.
94+
95+
### Part A: Safety Contracts (`#[requires]`/`#[ensures]` with `#[kani::proof_for_contract]`)
96+
97+
All unsafe functions have `#[requires]` contracts formalizing their safety preconditions, verified by `#[kani::proof_for_contract]` harnesses:
98+
99+
| Function | Contract | Harness |
100+
|----------|----------|---------|
101+
| `push_unchecked` | `self.len < self.capacity()` | `check_push_unchecked` |
102+
| `buffer_read` | `off < self.capacity()` | `check_buffer_read` |
103+
| `buffer_write` | `off < self.capacity()` | `check_buffer_write` |
104+
| `buffer_range` | `range.start <= range.end && range.end <= self.capacity()` | `check_buffer_range` |
105+
| `copy` | `len <= cap && src <= cap - len && dst <= cap - len` | `check_copy` |
106+
| `copy_nonoverlapping` | Same as `copy` + non-overlap | `check_copy_nonoverlapping` |
107+
| `wrap_copy` | `min(diff, cap - diff) + len <= cap` | `check_wrap_copy` |
108+
| `copy_slice` | `src.len() <= cap && dst < cap` | `check_copy_slice` |
109+
| `write_iter` | `dst < self.capacity()` | `check_write_iter` |
110+
| `write_iter_wrapping` | `dst < cap && len <= cap` | `check_write_iter_wrapping` |
111+
| `handle_capacity_increase` | `old_cap <= cap && len <= old_cap` | `check_handle_capacity_increase` |
112+
| `from_contiguous_raw_parts_in` | `init.start <= init.end <= capacity` | `check_from_contiguous_raw_parts_in` |
113+
| `abort_shrink` | `target_cap <= cap && len <= target_cap && old_head < cap` | `check_abort_shrink` |
114+
| `rotate_left_inner` | `mid <= self.len() / 2` | `check_rotate_left_inner` |
115+
| `rotate_right_inner` | `k <= self.len() / 2` | `check_rotate_right_inner` |
116+
117+
### Part B: UB Absence Proofs (`#[kani::proof]`)
118+
119+
All safe abstractions verified with `#[kani::proof]` harnesses proving no undefined behavior:
120+
121+
| Function | Harness |
122+
|----------|---------|
123+
| `get` | `check_get` |
124+
| `get_mut` | `check_get_mut` |
125+
| `swap` | `check_swap` |
126+
| `reserve_exact` | `check_reserve_exact` |
127+
| `reserve` | `check_reserve` |
128+
| `try_reserve_exact` | `check_try_reserve_exact` |
129+
| `try_reserve` | `check_try_reserve` |
130+
| `shrink_to` | `check_shrink_to` |
131+
| `truncate` | `check_truncate` |
132+
| `as_slices` | `check_as_slices` |
133+
| `as_mut_slices` | `check_as_mut_slices` |
134+
| `range` | `check_range` |
135+
| `range_mut` | `check_range_mut` |
136+
| `drain` | `check_drain` |
137+
| `pop_front` | `check_pop_front` |
138+
| `pop_back` | `check_pop_back` |
139+
| `push_front` | `check_push_front` |
140+
| `push_back` | `check_push_back` |
141+
| `insert` | `check_insert` |
142+
| `remove` | `check_remove` |
143+
| `split_off` | `check_split_off` |
144+
| `append` | `check_append` |
145+
| `retain_mut` | `check_retain_mut` |
146+
| `grow` | `check_grow` |
147+
| `resize_with` | `check_resize_with` |
148+
| `make_contiguous` | `check_make_contiguous` |
149+
| `rotate_left` | `check_rotate_left` |
150+
| `rotate_right` | `check_rotate_right` |

0 commit comments

Comments
 (0)