Issue #2725: Kani mode: function contracts and frames from the prover

Open and answer this issue on GitHub.

blocked, safety · opened 2026-11-22 · updated 2026-11-22 · 0 comments

Records ADR-proof-kani-v1 (Kani checks the prover’s proofs on the emitted Rust, in a mode of its own); the fourth of its six issues. Needs #2724

Goal

In the Kani mode the emitter writes a function’s preconditions, its callers’ facts it relies on and its frame as Kani function contracts, so Kani checks each function on its own and stubs a checked callee by its contract.

Governing decision

ADR-proof-kani-v1 D3 (requires, ensures, modifies, loop_modifies, stub_verified), D4 (only the axioms and a function’s own requires are assumed; every other fact is an obligation). ADR-269 D5 (a parameter is bounded only by a precondition). ADR-306 D11, D12 (callers’ facts).

Today (read in the code)

To build

  1. requires and ensures. With the Kani mode, each Nikaia requires / ensures the prover used is also written as #[cfg_attr(kani, kani::requires(…))] / kani::ensures(|result| …). A clause with no Rust spelling is reported (no contract: f: requires <text>) and the function is harnessed without it. Test: tests/compiler/tests/kani_mode_writes_requires_and_ensures.nika.
  2. Frames. A mut / ref mut parameter’s frame becomes kani::modifies(…); a loop changing it gets kani::loop_modifies(…). Test: a function pushing into a ref mut Vec[i64] inside a counted loop.
  3. Callees by contract. A harness of a function calling another checked function gets #[kani::stub_verified(callee)]; Kani then checks the call site’s facts against the callee’s requires (an obligation, D4). Test: a caller and a callee with a precondition, the caller’s fact proving it.
  4. A wrong fact fails. The test hook of the third issue, extended to drop one requires of a callee: Kani must refuse the caller’s harness. Test: the refusal line as .stderr.

Done when, with the Kani mode on, cargo kani -Z function-contracts -Z loop-contracts proves the contracts of every harnessed function of the four tests above, refuses item 4’s weakened one, and reports each clause it could not write; without the switch the lowering is byte-identical (lower-std diff empty, quoted). Item 4’s commit carries Fixes #N. Each surprise is a Found: line in the report, never a new issue number.

Files and limits

Ruled out

Back to Open Issues