Skip to content

Autoharness: Fn-bound closure models have no side effects, so callbacks that modify shared state are not covered #4994

Open

Description

@CYJ904

Autoharness instantiates Fn/FnMut/FnOnce-bounded type parameters with the nondet_fn* models (#4726). Each call returns a fresh nondeterministic value, which covers every value a real closure could return. The models have no side effects, though, so if a function's correctness depends on its callback not modifying state the function can also observe, autoharness reports Success even when a real callback breaks it.

Reproducer:

use std::cell::Cell;

/// Assumes the callback never changes `c`.
pub fn call_and_check_cell<F: Fn()>(c: &Cell<u8>, g: F) {
    let before = c.get();
    g();
    assert_eq!(before, c.get(), "callback changed the cell");
}

#[cfg(kani)]
mod proofs {
    use super::*;

    #[kani::proof]
    fn real_closure_breaks_cell() {
        let c = Cell::new(0u8);
        call_and_check_cell(&c, || c.set(c.get().wrapping_add(1)));
    }
}
  1. The manual harness real_closure_breaks_cell fails with "callback changed the cell".
  2. cargo kani autoharness -Z autoharness --include-pattern call_and_check_cell verifies call_and_check_cell::<fn() {kani::arbitrary::nondet_fn0::<()>}> and reports Success.

The same happens when the shared state is a static (e.g. a callback that increments a global AtomicU8 the function reads before and after the call).

This is related to #4750: the state is shared between an argument and the closure's captures, a kind of caller-controlled aliasing that the argument-aliasing work does not cover.

The doc comment on the models in library/kani/src/arbitrary.rs says they cover the function-under-test's own code "for any closure behavior". That holds for return values, but not for side effects.

Until this is modeled, the autoharness reference page will list it among the soundness caveats (#4991).

Tested with Kani 0.68.0 and CBMC 6.11.0.

Activity

  1. added
    [C] Bug
    on Oct 8, 2026
  2. added
    T-High Priority
    on Nov 6, 2026
  3. added this to the Autoharness milestone on Nov 6, 2026
  4. self-assigned this
    on Nov 6, 2026
  5. added
    Z-Autoharness
    on Nov 6, 2026
  6. added theissue type on Nov 6, 2026
  7. added
    [F] Soundness
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

T-High PriorityZ-Autoharness[C] Bug[F] Soundness

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions