Issue #2554: CI: Kani proves the unsafe crates whose reasoning is arithmetic or a bit layout

Open and answer this issue on GitHub.

ready · opened 2026-11-21 · updated 2026-11-21 · 0 comments

Part of #784

What it is

Bounded proofs with Kani for the unsafe crates under crates/unsafe/ whose unsafe rests on arithmetic or a bit layout that a bounded check covers completely, run in CI by a job unsafe_kani beside unsafe_crates in .github/workflows/nikaia.yml, under the same condition (needs.changes.outputs.unsafe) and gating promote. Decided in #784 (Decision): one workflow; not on the crates resting on the kernel or C (c-boundary, child-usage, polled, file-ring), not on SIMD paths. This is step 3 of #784.

To build

  1. The frame and the first crate: --kani in scripts/check-unsafe-crates.sh; the job unsafe_kani in nikaia.yml with the Kani version pinned (cargo install --locked kani-verifier@<v>, cargo kani setup), added to promote’s needs; cfg(kani) declared in each crate’s [lints.rust] unexpected_cfgs so clippy stays clean; and proven-index’s harnesses as #[cfg(kani)] mod proofs: under the stated precondition, the unchecked index or arithmetic gives the same result as the checked one and is never UB, one harness per operation and integer width.
  2. low-bits: the bzhi path equals x & ((1 << n) - 1) for every x and every n (if Kani does not model bzhi, check the portable path and keep the equality as a fuzz target); ref-or-box: building one and reading it back returns the same variant and the same address, for both sides, and Option<RefOrBox<A, B>> is one word.
  3. checked-text: for every byte string up to a bound (e.g. 8 bytes), it accepts exactly when std::str::from_utf8 does, and the text read back equals the input; text-key: the bytes read back are the key’s own, for each key type the crate knows.

Each item states the bound of each harness in the crate’s README, next to the argument it checks. Test for each: the harnesses pass; weaken one precondition in a scratch change and see Kani produce a counterexample (not committed).

Done when

sh scripts/check-unsafe-crates.sh --kani passes on proven-index, low-bits, ref-or-box, checked-text and text-key, the job unsafe_kani runs them in nikaia.yml and gates promote, and each README names its harnesses’ bounds; the commit of item 3 says Fixes #N.

Files

scripts/check-unsafe-crates.sh, .github/workflows/nikaia.yml, crates/unsafe/{proven-index,low-bits,ref-or-box,checked-text,text-key}/ (sources, Cargo.toml, README).

Split from #784 by Claude Code

Back to Open Issues