Repository navigation
Description
On current main (328e6b8), using #[kani::stub_verified(f)] where f has a #[kani::modifies] target whose type does not implement kani::Arbitrary makes kani-compiler panic instead of reporting an error.
I tried this code:
pub struct S {
pub x: u8,
}
#[kani::modifies(s)]
#[kani::ensures(|_| s.x == 1)]
fn set(s: &mut S) {
s.x = 1;
}
#[kani::proof_for_contract(set)]
fn check_set() {
let mut s = S { x: kani::any() };
set(&mut s);
}
#[kani::proof]
#[kani::stub_verified(set)]
fn use_set() {
let mut s = S { x: 0 };
set(&mut s);
assert!(s.x == 1);
}using the following command line invocation:
kani stub_verified_arbitrary.rs -Z function-contracts -Z stubbing
with Kani version: main at 328e6b8, built from source (kani --version: 0.68.0), CBMC 6.11.0, x86_64 Linux.
I expected to see this happen: both harnesses verify, or a compile error saying that S must implement kani::Arbitrary because set is used with stub_verified and modifies s.
Instead, this happened:
thread 'rustc' (163908) panicked at kani-compiler/src/kani_middle/reachability.rs:435:69:
called `Result::unwrap()` on an `Err` value: Error("Failed to resolve `FnDef(DefId { id: 104, name: \"kani::Arbitrary::any\" })` with `GenericArgs([Type(Ty { id: 5, kind: RigidTy(Adt(AdtDef(DefId { id: 422, name: \"stub_verified_arbitrary::S\" }), GenericArgs([]))) })])`")
Kani unexpectedly panicked during compilation.
Notes:
- With
#[derive(kani::Arbitrary)]onS, both harnesses verify (VERIFICATION:- SUCCESSFUL). - With
--harness check_set, theproof_for_contractharness alone verifies; the panic comes from thestub_verifiedharness. - Without
-Z stubbing, the same panic happens before Kani reports thatstub_verifiedneeds thestubbingfeature (with the derive, that error is reported normally). - I did not find the
Arbitraryrequirement formodifiestargets indocs/src/reference/experimental/contracts.mdorstubbing.md. - From reading the code (not traced):
AnyModifiesPass::replace_any_modifies(kani-compiler/src/kani_middle/transform/contracts.rs, around line 123) replaceskani::any_modifies::<T>withkani::any::<T>. The same pass has a check meant for this case (any_body, line 182), which reports thatTdoesn't implementkani::Arbitrary, with the help "All objects in the modifies clause must implement the Arbitrary. [...] if you are checking recursion or using verified stub." Here that error is not reported; the unresolvableArbitrary::anycall reaches theunwrap()inreachability.rsinstead. panic: uninit checks: Failed to resolve kani::Arbitrary::any #4851 hits the same panic message from a different path (uninit checks in autoharness).
I ran into this while trying to replace an allocating call inside a contracted loop with its verified contract (stub_verified), where the modifies target is a struct holding a Vec. Vec implements kani::BoundedArbitrary but not kani::Arbitrary, so a clear error would at least say what is missing.
Activity