-
Notifications
You must be signed in to change notification settings - Fork 31
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
Challenge 3: Verifying Raw Pointer Arithmetic Operations #76
Comments
Here’s Kai from CMU III. We’re taking on this challenge and will keep you updated on our progress along the way. |
Problem 1: Defining Valid Input Space for Pointer Parameters (solved)Challenge:Our main challenge in writing function contracts is precisely defining the valid input space for pointer parameters. Specifically, we are struggling to express accurate kani::requires attributes for pointer parameters in the functions we need to verify. For non-pointer inputs like So far, we haven’t found a feasible solution or a Kani API that directly addresses this problem. Could you provide guidance on how we can define preconditions for pointer parameters in our function contracts? Answer:There’s an API called can_dereference that can be used for this purpose: can_dereference API Problem 2: Handling Undefined Behavior in Function Verification (solved)Challenge:We are also encountering an issue related to undefined behavior (UB) in the verification of pointer arithmetic functions, such as Answer:Kani automatically checks for certain types of UB (e.g. a dereference operation is valid), and verification will fail if one of those types of UB were found in a function. For other properties, such as this one mentioned in the documentation of offset: the entire memory range between self and the result must be in bounds of that allocated object. One needs to express this property as a requires clause that the function is annotated with. |
Problem 3: Determining the valid value range for To write a function contract for this function, we need to add a precondition that defines the valid input range for the let nums = vec![0i32, 1, 2, 3];
let n = 42;
let ptr1: *const i32 = nums.as_ptr();
let ptr2: *const i32 = ptr1.wrapping_offset(1);
let ptr3: *const i32 = &n; All of these pointers are of type Is there a way to resolve this issue? Problem 4: determing whether two raw pointers point to the same object during runtime To implement function contracts for |
@feliperodri , the other two people working on this issue are @stogaru and @MayureshJoshi25. |
Mayuresh here! Would be working on this challenge and would report any problems/doubts on the way. |
Problem 5: Calling Pointer Arithmetic Methods on
|
Problem 6: Precondition
|
Hi @feliperodri, after contacting with Team 4, we have a few updates on the issues we've been discussing in today's (Oct. 11) meeting:
|
It is not possible to verify
Function signatures:Observe that the add:pub const unsafe fn add(self, count: usize) -> Self
where
T: Sized The same applies for Invoking above methods:SlicesCode: fn main() {
let arr = [1, 2, 3, 4, 5];
let slice = &arr[..];
let slice_ptr: *const [u32] = slice.as_ptr() as *const [u32];
let new_slice_ptr: *const [u32] = unsafe { slice_ptr.offset(1) };
} Error as expected:
dyn TraitsCode: trait Greet {
fn greet(&self);
}
struct Person {
name: &'static str,
}
impl Greet for Person {
fn greet(&self) {
println!("Hello, my name is {}!", self.name);
}
}
fn main() {
let person = Person { name: "Alice" };
let greet_ptr: *const dyn Greet = &person as *const dyn Greet;
unsafe {
greet_ptr.offset(1);
}
} Error as expected:
|
Towards #76 ### Changes * Adds contracts for `<*const T>::offset_from`. * Adds harnesses for the function verifying: * All integer types * Tuples (composite types) * Unit Type * Accomplishes this using a macro. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Carolyn Zech <[email protected]>
Towards #76 ### Changes * Adds contracts for `<*mut T>::add`, `<*mut T>::sub` and `<*mut T>::offset` * Adds proofs for contracts of the above functions verifying the pointee types: * All integer types * Tuples (composite type) * Unit Type * Defines a macro for add and sub and another for offset. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Yifei Wang <[email protected]> Co-authored-by: MayureshJoshi25 <[email protected]> Co-authored-by: Yifei Wang <[email protected]>
Towards #76 **Summary** * Adds contracts for <*const T>::add, sub and offset. * Adds proof for contracts for above methods, verifying following pointee types: * All integer types * Tuples (representing composite types) * Slices * Unit type
…169) Towards #76 ### Changes * Adds contracts for `<*mut T>::byte_add`, `<*mut T>::byte_sub` and `<*mut T>::byte_offset`. * Adds harnesses for the function verifying the following pointee types: * All integer types * Tuples (composite types) * Unit Type * Slices * Accomplishes this using a few macros. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Yifei Wang <[email protected]> Co-authored-by: Yifei Wang <[email protected]>
- Added contracts for offset_from (mut type); - Accomplished using a macro which generates harnesses; - Verifies: int types, unit, tuples (composite types). Towards #76 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: stogaru <[email protected]> Co-authored-by: Carolyn Zech <[email protected]> Co-authored-by: Felipe R. Monteiro <[email protected]>
…nd `byte_offset` (#188) Towards #76 This pull request impelments proof for contracts for `byte_add`, `byte_sub` and `byte_offset` for `<dyn Trait>`. Both `const` and `mut` versions are included. It serves as an addition to an existing [PR](#169) but is submitted separately to avoid disrupting the ongoing review process for that PR. --------- Co-authored-by: Surya Togaru <[email protected]> Co-authored-by: stogaru <[email protected]> Co-authored-by: Felipe R. Monteiro <[email protected]>
Towards #76 ## Changes ### Contracts Added: - Added contracts for <*mut T>::add, <*mut T>::sub, and <*mut T>::offset operations for raw pointers to slices. ### Proofs Implemented: - Added proofs for the above contracts, verifying safety for the following slice pointee types using arrays: - All integer types (i8, i16, i32, etc.). - Tuples (composite types) (e.g., (i8, i8), (i32, f64, bool)). - Unit type (()). ### Macro Definitions: - Introduced macros to simplify and automate harness generation: - One macro for add and sub operations on slices. - Another macro for offset operations on slices. ### Array-Based Implementation for Slice Verification: - Arrays are used as a proxy for slices (as slices do not have a known length at compile time) to enable proper bounds checking and assumptions during verification.
Tracking issue for Challenge 3: Verifying Raw Pointer Arithmetic Operations.
The text was updated successfully, but these errors were encountered: