You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem Description
When attempting to stub a function with a verified function contract using kani::stub_verified, a compilation error occurs if the function's return value is a pointer.
Example
The following code is executed using kani 0.56.0 and command kani -Zfunction-contracts <filename>
// This function contract performs no meaningful checks.// Its sole purpose is to enable stubbing of the `get_same_ptr` function.#[kani::requires(true)]#[kani::ensures(|result| true)]fnget_same_ptr(ptr:*constu8) -> *constu8{
ptr
}fntest_func(){let s:&str = "123";let ptr:*constu8 = s.as_ptr();get_same_ptr(ptr);}#[kani::proof]#[kani::stub_verified(get_same_ptr)]fncheck_test_func(){test_func();}
Running this code generates the following error:
error: `*const u8` doesn't implement `kani::Arbitrary`.
--> /Users/xsxsz/github_repos/kani/library/kani/src/lib.rs:52:1
|
52 | kani_core::kani_lib!(kani);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: All objects in the modifies clause must implement the Arbitrary. The return type must also implement the Arbitrary trait if you are checking recursion or using verified stub.
= note: this error originates in the macro `kani_core::kani_intrinsics` which comes from the expansion of the macro `kani_core::kani_lib` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error
Possible Cause of the Issue
According to Kani's blog post, the issue can be explained as follows: When stubbing a function with its contracts, Kani performs these steps:
Convert preconditions into an assert!() clause.
Define a kani::any() variable to represent the output.
Constrain the output range using kani::assume() based on the postconditions.
In this case, the Arbitrary trait (required by kani::any) is not implemented for pointers, this makes sense as generating a random pointer without memory allocation context is pointless. As a result, Step 2 causes compilation errors. Is there any workaround for stubbing function with pointer return values?
The text was updated successfully, but these errors were encountered:
@feliperodri Hi Felipe, this is the issue we discussed in today's meeting. It's currently blocking our efforts to verify functions using function contracts for pointer arithmetic operations.
Problem Description
When attempting to stub a function with a verified function contract using
kani::stub_verified
, a compilation error occurs if the function's return value is a pointer.Example
The following code is executed using kani 0.56.0 and command
kani -Zfunction-contracts <filename>
Running this code generates the following error:
Possible Cause of the Issue
According to Kani's blog post, the issue can be explained as follows: When stubbing a function with its contracts, Kani performs these steps:
assert!()
clause.kani::any()
variable to represent the output.kani::assume()
based on the postconditions.In this case, the Arbitrary trait (required by
kani::any
) is not implemented for pointers, this makes sense as generating a random pointer without memory allocation context is pointless. As a result, Step 2 causes compilation errors. Is there any workaround for stubbing function with pointer return values?The text was updated successfully, but these errors were encountered: