Replies: 3 comments
-
As per the meeting, the |
Beta Was this translation helpful? Give feedback.
-
As we discussed offline, we might need new memory predicates to extract some extra information from raw pointers in this case. Let's take a look at this example for instance, use std::mem;
#[kani::proof]
fn main() {
// Create a boxed value (heap allocated)
let boxed_value = Box::new([10, 20, 30, 40, 50]);
// Get a raw pointer to the boxed value
let ptr: *const i32 = &*boxed_value as *const i32;
// Use `size_of_val` to get the size of the allocated object
let size = mem::size_of_val(&*boxed_value);
// Get the size in bytes of the type that `ptr` points to.
let type_size = mem::size_of::<i32>();
// Output the size of the allocated object
assert_eq!(size, 20); // [i32; 5] is 5 elements * 4 bytes each = 20 bytes
// Non-deterministic `count`
let count: isize = kani::any();
// Preconditions for `count`
kani::assume(count > 0 && count < ((size/type_size) as isize));
unsafe {
// Use `offset` to move the pointer
let _new_ptr = ptr.offset(count);
}
} Here we are using My recommendation is to write the contracts for this challenge to all functions we can write it today. That way, we will have a list of all functions that we may not be able to verify because we need specific information from the pointer. Let's document everything that we have tried using standard Rust in these contracts (e.g., |
Beta Was this translation helpful? Give feedback.
-
I believe this can be accomplished now with the new Note that if |
Beta Was this translation helpful? Give feedback.
-
To write a function contract for this function, we need to add a precondition that defines a range for the count parameter. As per the documentation, the
*const T::offset
function guarantees the safety of the resulting pointer only when theself
and theresult
are in bounds of that allocated object. Therefore, count should be bounded such thatself.addr() +/- count
is within the start and end addresses of the allocated object.Is there a way to infer the start and end addresses of the allocated object solely based on the input pointer? Or can we check if
self
andresult
are pointing to the same allocation object?Beta Was this translation helpful? Give feedback.
All reactions