-
Notifications
You must be signed in to change notification settings - Fork 121
RFC: Partitioned proofs #4228
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
base: main
Are you sure you want to change the base?
RFC: Partitioned proofs #4228
Conversation
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.
Thanks! First round of comments. Remember to update SUMMARY.md
!
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.
The various comments need to be driven to a conclusion, but I'm certainly supportive of the overall idea.
} | ||
``` | ||
|
||
And Kani would automatically handle checking the partition conditions for soundess and generating the partitioned proofs. Overlaps would be allowed as they don't affect soundess and may be useful in certain cases (see [below](#2-checking-for-overlapping-partitions) for more discussion). |
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.
Just curious: how do you actually accomplish the soundness check?
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.
The thought (and implementation in the previous prototype) is that you would generate a new proof harness that declares input
as a kani::any::<i32>()
and asserts that at least one of the partition conditions evaluates to true. This, conceptually, should ensure that any i32
value will fall into at least one partition.
Carolyn and I just had a talk about the syntax thoughts discussed above and echoed by Sammy here, and we started to converge on an idea that seems compelling. (Just dumping our thoughts here now until I have time to edit the RFC at a later date) The initial syntax of However, this syntax also brings up some questions, such as how a condition like To fix this, we discussed a new API where pub fn partition<T: Arbitrary, R, const N: usize>(
variable: T,
conditions: [fn(&T) -> bool; N],
and_run: fn(T) -> R,
) -> R {
// This inner code will likely be a compiler intrinsic,
// but is just included to get a sense of the logical shape for now
let partition_num = /* DEPENDS ON PARTITION */;
kani::assume(conditions[partition_num](&variable));
and_run(variable)
} Which could be called along the lines of #[kani::proof]
pub fn partitioned_harness2() {
let input = kani::any();
let r = kani::partition(input, [|a| *a > 10, ...], |input| target_fn(input));
} Some key notes:
(Will add these to the RFC's open questions when I have time) |
When working on a second draft of this RFC, I encountered a potential issue with the above syntax. Consider the following proof harness: #[kani::proof]
pub fn strange_partitioned_harness() {
let input: i32 = kani::any();
let f: fn(&i32) -> bool = if input > 10 {
|a: &i32| *a < 0
} else {
|a: &i32| *a < -2
};
kani::partition(input, [f, |a| *a >= 0], |i| target_fn(i));
} Since one of the partition conditions depends on the non-deterministic partition variable, it seems almost non-sensical, as partition conditions should just be pre-defined filters to split that variable, rather than a function determined by runtime values. To fix this, I tried forcing the conditions array to be compile-time evaluable by making it a pub fn partition<T: kani::Arbitrary, R, const N: usize, const C: [fn(&T) -> bool; N]>(
variable: T,
conditions: C,
and_run: fn(T) -> R,
) -> R Is there a better way to ensure that the value of the function pointers we get can't be impacted by non-det values? |
Second draft of this RFC! Note that in discussion w/ @carolynzech and @camelid, the issue raised in my comment above should be fixed in this newly proposed API if we also check the validity of partition conditions. |
This discusses a prototype implementation of the feature suggested in #3006 that would allow users to soundly partition proofs into harnesses that could be verified separately and in parallel.
Rendered
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.