Repository navigation
Challenge 17: Verify the safety of core::slice functions with VeriFast #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paulocsanz
wants to merge
15
commits into
model-checking:main
Choose a base branch
from
paulocsanz:challenge17-verifast-slice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+36,725
−0
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
796361a
VeriFast proof of core::slice (Challenge 17): contracts for the 10 un…
0096870
verifast-proofs/core/slice: build the noslice core sysroot from VeriF…
paulocsanz 1dd4857
verifast-proofs/core/slice: close the open-ended axioms
paulocsanz eb18363
verifast-proofs/core/slice: README: list the sysroot core edits made …
paulocsanz 8221187
verifast-proofs/core/slice: add a negative test (mod.rs-negative)
paulocsanz c20cc9a
core::slice: Kani contracts and harnesses for the const-generic funct…
paulocsanz c629891
verifast-proofs/core/slice: link every axiom and assume_correct wrapp…
paulocsanz 0df2463
core::slice: rustfmt the Kani harnesses; re-sync the VeriFast proof c…
paulocsanz 528a907
verifast-proofs/core/slice: extern specs for ptr::swap/swap_nonoverla…
paulocsanz c6c5e06
verifast-proofs/core/slice: README: link the upstream proposals (veri…
paulocsanz aa802d7
verifast-proofs/core/slice: prove carve_regions / uncarve_regions (28…
paulocsanz a192087
verifast-proofs/core/slice: fixes from the second adversarial review …
paulocsanz c540719
verifast-proofs/core/slice: drop the 36 inert ignore_ref_creation dir…
paulocsanz f679b2b
verifast-proofs/core/slice: drop -allow_dead_code and two indexing wr…
paulocsanz 00b2237
ci: retrigger (macOS Kani Metrics runner lost communication with the …
paulocsanz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,10 @@ cd alloc | |
| cd .. | ||
| cd .. | ||
| cd .. | ||
| cd core | ||
| cd slice | ||
| cd mod.rs-negative | ||
| bash verify.sh | ||
| cd .. | ||
| cd .. | ||
| cd .. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,10 @@ cd alloc | |
| cd .. | ||
| cd .. | ||
| cd .. | ||
| cd core | ||
| cd slice | ||
| cd mod.rs | ||
| bash verify.sh | ||
| cd .. | ||
| cd .. | ||
| cd .. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| mod num { | ||
| impl usize { | ||
| fn is_multiple_of(self: usize, rhs: usize) -> bool; | ||
| //@ req true; | ||
| //@ ens result == if rhs == 0 { self == 0 } else { self % rhs == 0 }; | ||
| //@ on_unwind_ens false; | ||
| } | ||
| } | ||
|
|
||
| mod hint { | ||
| fn select_unpredictable<T>(b: bool, true_val: T, false_val: T) -> T; | ||
| //@ req true; | ||
| //@ ens result == if b { true_val } else { false_val }; | ||
| //@ on_unwind_ens false; | ||
| } | ||
|
|
||
| mod cmp { | ||
| mod PartialEq { | ||
| fn eq<T, U, 'a, 'b>(self: &'a T, other: &'b U) -> bool; | ||
| //@ req <&'b U>.own(?_t, other); | ||
| //@ ens true; | ||
| //@ on_unwind_ens false; | ||
| } | ||
| } | ||
|
|
||
| mod mem { | ||
| fn swap<T, 'a, 'b>(x: &'a mut T, y: &'b mut T); | ||
| //@ req *x |-> ?vx &*& *y |-> ?vy; | ||
| //@ ens *x |-> vy &*& *y |-> vx; | ||
| //@ on_unwind_ens false; | ||
| } | ||
|
|
||
| mod ptr { | ||
| fn metadata<T: ?Sized>(p: *const T) -> usize; | ||
| //@ req true; | ||
| //@ ens result == ptr_len(p) &*& 0 <= result &*& result <= usize::MAX; | ||
| //@ on_unwind_ens false; | ||
|
|
||
| /*@ | ||
| // `ptr::swap` allows `x == y` (and, more generally, overlap); this models the `x == y` case | ||
| // as the only aliasing case, which is all `core::slice` needs. | ||
| pred opt_pointsto<T>(same: bool, x: *T, y: *T, vx: T, vy: T) = | ||
| if same { x == y &*& vy == vx } else { *y |-> vy }; | ||
| @*/ | ||
|
|
||
| unsafe fn swap<T>(x: *mut T, y: *mut T); | ||
| //@ req *x |-> ?vx &*& opt_pointsto::<T>(?same, x, y, vx, ?vy); | ||
| //@ ens *x |-> vy &*& if same { true } else { *y |-> vx }; | ||
| //@ on_unwind_ens false; | ||
|
|
||
| unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize); | ||
| //@ req x[..count] |-> ?vs1 &*& y[..count] |-> ?vs2; | ||
| //@ ens x[..count] |-> vs2 &*& y[..count] |-> vs1; | ||
| //@ on_unwind_ens false; | ||
| } | ||
|
|
||
| mod slice { | ||
|
|
||
| /*@ | ||
| pred SliceIndex_in_bounds<I, T>(idx: I, slice: *T); | ||
|
|
||
| lem usize_SliceIndex_in_bounds<T>(i: usize, slice: *[T]); | ||
| req i < slice.len(); | ||
| ens SliceIndex_in_bounds::<usize, [T]>(i, slice); | ||
|
|
||
| fix GetDisjointMutIndex_in_bounds<I>(idx: I, len: usize) -> bool; | ||
| fix GetDisjointMutIndex_overlapping<I>(idx1: I, idx2: I) -> bool; | ||
| @*/ | ||
|
|
||
| enum GetDisjointMutError { | ||
| IndexOutOfBounds, | ||
| OverlappingIndices, | ||
| } | ||
|
|
||
| trait SliceIndex<T> { | ||
| type Output; | ||
| } | ||
|
|
||
| mod SliceIndex { | ||
|
|
||
| unsafe fn get_unchecked<I: ?Sized, T: ?Sized>(self: I, slice: *const T) -> *const <I as std::slice::SliceIndex<T>>::Output; | ||
| //@ req thread_token(?t) &*& [_](<T>.share(?k, t, slice)) &*& std::slice::SliceIndex_in_bounds::<I, T>(self, slice); | ||
| //@ ens thread_token(t) &*& [_](< <I as std::slice::SliceIndex<T>>::Output>.share(k, t, result)); | ||
| //@ on_unwind_ens false; | ||
|
|
||
| unsafe fn get_unchecked_mut<I: ?Sized, T: ?Sized>(self: I, slice: *mut T) -> *mut <I as std::slice::SliceIndex<T>>::Output; | ||
| //@ req thread_token(?t) &*& full_borrow(?k, <T>.full_borrow_content(t, slice)) &*& std::slice::SliceIndex_in_bounds::<I, T>(self, slice); | ||
| //@ ens thread_token(t) &*& full_borrow(k, < <I as std::slice::SliceIndex<T>>::Output>.full_borrow_content(t, result)); | ||
| //@ on_unwind_ens false; | ||
|
|
||
| } | ||
|
|
||
| mod GetDisjointMutIndex { | ||
|
|
||
| fn is_in_bounds<I, 'a>(self: &'a I, len: usize) -> bool; | ||
| //@ req thread_token(?t) &*& [?f](*self |-> ?v); | ||
| //@ ens thread_token(t) &*& [f](*self |-> v) &*& result == std::slice::GetDisjointMutIndex_in_bounds::<I>(v, len); | ||
| //@ on_unwind_ens false; | ||
|
|
||
| fn is_overlapping<I, 'a, 'b>(self: &'a I, other: &'b I) -> bool; | ||
| //@ req thread_token(?t) &*& [?f1](*self |-> ?v1) &*& [?f2](*other |-> ?v2); | ||
| //@ ens thread_token(t) &*& [f1](*self |-> v1) &*& [f2](*other |-> v2) &*& result == std::slice::GetDisjointMutIndex_overlapping::<I>(v1, v2); | ||
| //@ on_unwind_ens false; | ||
|
|
||
| } | ||
|
|
||
| fn copy_from_slice_impl::len_mismatch_fail(dst_len: usize, src_len: usize) -> !; | ||
| //@ req true; | ||
| //@ ens false; | ||
| //@ on_unwind_ens false; | ||
|
|
||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: these harnesses are bounded (length at most 12) and monomorphized over
u8/u32/(), so for the 20 const-generic functions they're the only check of the real bodies. That's the part the generic-Truling (#734) would have to accept.