Skip to content

stub_verified panics the compiler when a modifies target's type does not implement kani::Arbitrary #5005

Open

Description

@Talha-Dmr

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)] on S, both harnesses verify (VERIFICATION:- SUCCESSFUL).
  • With --harness check_set, the proof_for_contract harness alone verifies; the panic comes from the stub_verified harness.
  • Without -Z stubbing, the same panic happens before Kani reports that stub_verified needs the stubbing feature (with the derive, that error is reported normally).
  • I did not find the Arbitrary requirement for modifies targets in docs/src/reference/experimental/contracts.md or stubbing.md.
  • From reading the code (not traced): AnyModifiesPass::replace_any_modifies (kani-compiler/src/kani_middle/transform/contracts.rs, around line 123) replaces kani::any_modifies::<T> with kani::any::<T>. The same pass has a check meant for this case (any_body, line 182), which reports that T doesn't implement kani::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 unresolvable Arbitrary::any call reaches the unwrap() in reachability.rs instead. 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

  1. self-assigned this
    on Oct 14, 2026
  2. added this to the Contracts milestone on Nov 6, 2026
  3. added theissue type on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Z-ContractsIssue related to code contracts[C] BugThis is a bug. Something isn't working.[F] CrashKani crashed

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions