[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KM0G321XQ5F6F98P2YH51G":3,"skill-same:01M6KM0G321XQ5F6F98P2YH51G":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":42,"linkOnly":43,"markdownContent":44,"markdownBody":45,"frontMatter":46,"refName":48,"commitSha":49,"skillDirectory":50,"forksCount":51,"repositoryHtmlUrl":52,"repositoryHomepageUrl":6,"ownerHtmlUrl":53,"ownerBlogUrl":54,"ownerDescription":6,"updatedAt":55,"install":56,"resources":69},"01M6KM0G321XQ5F6F98P2YH51G","tools-verify-kani",null,"Verify a Rust component using Kani model checking — stub unsafe\u002FFFI dependencies, write harnesses targeting arithmetic and state invariants, audit kani::assume calls against production guards, fix gaps, and re-verify.","AI-native-Systems-Research\u002Fai-native-storage-certus","AI-native-Systems-Research","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F270755458?v=4","01M6KKQWSJX0D4X33E0KKSR4WM","AI-native Systems Research","01M6KKQWXTKR6MYVQMPKVJ5WD5",3,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002F.claude\u002Fskills\u002Ftools-verify-kani\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],"tools verify kani","Tools","verify","model checking","gaps","stub","unsafe","path","harnesses","targeting","invariants","calls","re","interface","rust","dependencies","fix","write","model","audit","ffi","state","component","2026-11-10 10:12:30",false,"---\nname: tools-verify-kani\ndescription: Verify a Rust component using Kani model checking — stub unsafe\u002FFFI dependencies, write harnesses targeting arithmetic and state invariants, audit kani::assume calls against production guards, fix gaps, and re-verify.\nargument-hint: \"[component-path] [interface-path]\"\n---\n\n## Goal\n\nFormally verify a Rust component using Kani. Kani proves absence of panics,\narithmetic overflows, and invariant violations for **all possible inputs** —\nnot just sampled ones. The output is either a passing proof or a concrete\ncounterexample pointing to a real bug.\n\nWork on a dedicated branch (e.g. `kani_harnesses`) so harnesses and fixes can\nbe reviewed separately from feature work.\n\n---\n\n## The core rule — verify at function granularity, against a spec-derived contract\n\nBefore anything else: **the unit of verification is a whole function plus a property\nfrom the spec — never a cherry-picked statement.** Lifting a suspect line and checking\nit for overflow\u002Fout-of-bounds is *bug-hunting*: it proves a fragment that has no\ncontract, so a green result only says \"this one line does not panic.\" Instead, for each\ntarget produce three things and label the global `Pn`:\n\n1. **precondition** — `kani::assume(...)` the spec's precondition (mirror the production guard);\n2. **function** — **call the real function** (preferred: the proof then tracks shipped\n   code). A faithful *whole-function* copy carrying the same contract is acceptable only\n   where the crate cannot be built under Kani, and must carry a drift\u002Fequality check;\n3. **postcondition** — `assert!(...)` the spec's postcondition.\n\nThen **validate the harness by fault injection**: make a change to the function that\nviolates the contract and confirm the harness *fails*. If it still passes, the harness is\nnot bound to the real code — fix it. (`--harness` substring-matches; use `--exact` with the\nfully-qualified `module::name` to run one harness in isolation.)\n\nThe statement scan in Phase 1 is only for *finding candidate functions and their\nproperties* — not for lifting statements into harnesses.\n\n---\n\n## Phase 1 — Reconnaissance\n\nBefore writing a single line of Kani code, read:\n\n1. All source files: `src\u002Flib.rs`, `src\u002Fstate.rs`, `src\u002Fentry.rs`, and any\n   submodules.\n2. The component's interface file (`components\u002Finterfaces\u002Fsrc\u002Fixxx.rs`).\n3. `Cargo.toml` — note feature flags, optional deps, and workspace deps.\n\n**Build a target list** — scan for every arithmetic expression that can panic\nor wrap:\n\n| Pattern | Risk | Example |\n|---|---|---|\n| `x += 1` on integer field | Overflow if field reaches MAX | `read_ref += 1` |\n| `x -= 1` on integer field | Underflow if field is 0 | `read_ref -= 1` |\n| `a * b` before a bounds check | Overflow before guard runs | `block_id * BLOCK_SIZE` |\n| `a + b` | Overflow | `offset + BLOCK_SIZE` |\n| `x as usize` widening cast | Safe on 64-bit, not on 32-bit | `size as usize * 4096` |\n| `buf[i]` inside a loop | Out-of-bounds if bound is wrong | `buf[i] = 1` |\n\nAlso note:\n- Types with raw pointers or FFI calls → need stubs (Phase 2)\n- Component framework macros (`define_component!`) → bypass in harnesses (Phase 3)\n- `Mutex` \u002F `Condvar` \u002F `Arc` → test the inner state directly, not through locks\n\n---\n\n## Phase 2 — Stub Unsafe \u002F FFI Dependencies\n\nKani cannot model raw pointers or calls into C\u002FSPDK FFI. Any type that\ncontains these must be replaced with a safe equivalent under `#[cfg(kani)]`.\n\n**Rule:** Gate the real implementation with `#[cfg(not(kani))]` and provide a\n`#[cfg(kani)]` stub with the **identical public API** but backed by safe Rust.\n\n```rust\n\u002F\u002F Production struct — raw pointer, FFI deallocator\n#[cfg(not(kani))]\npub struct DmaBuffer {\n    ptr: *mut std::ffi::c_void,\n    len: usize,\n    free_fn: unsafe extern \"C\" fn(*mut std::ffi::c_void),\n}\n\n\u002F\u002F Kani stub — Vec\u003Cu8>, no raw pointers, Drop is a no-op\n#[cfg(kani)]\npub struct DmaBuffer {\n    data: Vec\u003Cu8>,\n}\n```\n\nApply `#[cfg(not(kani))]` \u002F `#[cfg(kani)]` to **every** `impl` block for the\ntype (`Drop`, `Deref`, `DerefMut`, `Debug`, `Send`, `Sync`, method impls).\n\nStub rules:\n- `new(size, ...)` → `vec![0u8; size]`, no FFI calls\n- `from_raw(ptr, len, ...)` → `vec![0u8; len]`, ignore the raw pointer\n- `as_ptr()` → `self.data.as_ptr() as *mut _` (safe to return, just not deref'd)\n- `Drop` → empty body; `Vec` handles deallocation\n- Keep `unsafe impl Send` \u002F `unsafe impl Sync` — still needed for `Arc\u003CT>`\n\n**Suppress the lint** in every affected `Cargo.toml`:\n\n```toml\n[lints.rust]\nunexpected_cfgs = { level = \"warn\", check-cfg = ['cfg(kani)'] }\n```\n\n---\n\n## Phase 3 — Write Harnesses\n\nPlace all harnesses in a single `#[cfg(kani)] mod verification` block inside\n`src\u002Flib.rs`. This keeps them invisible to `cargo build` and `cargo test`.\n\n```rust\n#[cfg(kani)]\nmod verification {\n    use super::*;\n    \u002F\u002F access pub(crate) state types directly from here\n\n    #[kani::proof]\n    #[kani::unwind(N)]   \u002F\u002F N = deepest loop bound + 1\n    fn verify_something() { ... }\n}\n```\n\n### Harness rules\n\n**Use `kani::any()` for every input** — this tells Kani to consider all\npossible values, not just a sample.\n\n```rust\nlet count: u32 = kani::any();\nlet key: u64 = kani::any();\n```\n\n**Use `kani::assume()` only for pre-conditions that production code enforces.**\nEvery `assume` is a hypothesis — it must be audited in Phase 4.\n\n```rust\nkani::assume(count > 0); \u002F\u002F only if production code checks count > 0 first\n```\n\n**Bypass the component framework.** Do not try to drive `IFoo` through\n`define_component!`. Construct the inner state structs (`Inner`, `State`,\n`Entry`) directly — they are `pub(crate)` and visible inside `mod verification`.\n\n```rust\nlet entry = DispatchEntry { read_ref: kani::any(), write_ref: 0, ... };\n```\n\n**Avoid heap allocation in harnesses.** `HashMap::new()`, `Vec::new()`,\n`String::new()` pull in `__rust_alloc_error_handler` which Kani does not\nsupport. Instead, test invariants directly on struct fields.\n\n```rust\n\u002F\u002F Bad — HashMap triggers unsupported alloc error handler\nlet mut map = HashMap::new();\nmap.insert(key, entry);\n\n\u002F\u002F Good — test the guard logic on the struct directly\nlet active = entry.read_ref > 0 || entry.write_ref > 0;\nkani::assert(!active || ..., \"...\");\n```\n\n**Set `#[kani::unwind(N)]` correctly.**\n- For a loop with bound `B`: use `N = B + 1`\n- For harnesses with no loops: use `N = 1`\n- Kani will fail with an unwind error if N is too small\n\n### Standard harnesses to write for any component\n\n| Harness | What to verify |\n|---|---|\n| `verify_increment_no_overflow` | Every `field += 1` site: `checked_add` returns correct value below MAX, `None` at MAX |\n| `verify_decrement_underflow_guarded` | Every `field -= 1` site: safe because production guard `field > 0` exists |\n| `verify_multiplication_no_overflow` | Every `a * b` before a bounds check |\n| `verify_cast_no_overflow` | Every `x as usize * N` on a 32\u002F64-bit sensitive target |\n| `verify_state_invariant` | After a state transition, assert the resulting field values are consistent |\n| `verify_removal_requires_zero_refs` | Entry is only removed when all reference counts are zero |\n| `verify_symmetric_operation` | e.g. acquire then release leaves state identical to before |\n\n---\n\n## Phase 4 — The Assume Audit (Critical Step)\n\n**After all harnesses pass**, audit every `kani::assume` against the\nproduction code. This is the most important step — a passing harness with\nan unmatched assume only proves safety in a restricted universe.\n\nFor each `kani::assume(X)` in a harness:\n\n1. Find the corresponding guard in the production code.\n2. If the guard exists → the assume is justified. Leave it.\n3. If **no guard exists** → the assume is hiding a bug. The production code\n   depends on X being true but never checks it. **This is a defect.**\n\nExample of a matched assume (safe):\n```rust\n\u002F\u002F Harness\nkani::assume(entry.read_ref > 0);\n\u002F\u002F Production code — guard IS present\nif entry.read_ref == 0 {\n    return Err(DispatchMapError::RefCountUnderflow(key));\n}\nentry.read_ref -= 1;\n```\n\nExample of an unmatched assume (bug):\n```rust\n\u002F\u002F Harness\nkani::assume(read_ref \u003C u32::MAX);  \u002F\u002F assumed, but...\n\u002F\u002F Production code — NO guard\nentry.read_ref += 1;                \u002F\u002F bare increment, can overflow at u32::MAX\n```\n\n**Symmetric pairs are a strong signal.** If an error enum has `Underflow` but\nno `Overflow`, look for increment sites that lack the matching guard.\n\n---\n\n## Phase 5 — Fix and Re-Verify\n\n### Fix pattern for arithmetic overflow\n\nReplace bare arithmetic with `checked_*` operations and propagate via `?`:\n\n```rust\n\u002F\u002F Before\nentry.read_ref += 1;\n\n\u002F\u002F After\nentry.read_ref = entry\n    .read_ref\n    .checked_add(1)\n    .ok_or(ComponentError::RefCountOverflow(key))?;\n```\n\nApply the same pattern for:\n- `checked_mul` — for multiplications before bounds checks\n- `checked_add` — for additions (offset + size, etc.)\n- `checked_sub` — only if the existing guard can be removed\n\n### Add symmetric error variants\n\nWhen adding an overflow error, add it to the interface error enum\n(e.g. `components\u002Finterfaces\u002Fsrc\u002Fixxx.rs`) with a symmetric name:\n\n```rust\n\u002F\u002F\u002F Reference count underflow (release when already zero).\nRefCountUnderflow(CacheKey),\n\u002F\u002F\u002F Reference count overflow (acquire when already at u32::MAX).\nRefCountOverflow(CacheKey),   \u002F\u002F ← add this\n```\n\nAdd the matching `Display` arm.\n\n### Tighten the harnesses after fixing\n\nRemove `kani::assume` calls that were masking the bug. The harness should\nnow verify the full range including the previously-hidden edge case:\n\n```rust\n\u002F\u002F Before fix — assume hid the overflow\nkani::assume(read_ref \u003C u32::MAX);\nentry.read_ref += 1;\n\n\u002F\u002F After fix — no assume needed; checked_add handles all u32 values\nlet result = entry.read_ref.checked_add(1);\nif let Some(r) = result {\n    kani::assert(r == entry.read_ref + 1, \"...\");\n} else {\n    kani::assert(entry.read_ref == u32::MAX, \"overflow only at MAX\");\n}\n```\n\n### Re-run and confirm\n\n```sh\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml\n```\n\nTarget: `0 of N failed`, all harnesses in `Manual Harness Summary` show success.\n\n---\n\n## Phase 6 — Document and Commit\n\nCreate `VERIFICATION.md` in the component directory covering:\n- Component overview and what was verified\n- The stub approach (if FFI types were involved)\n- Each harness and what it proves\n- Bugs found (file, line, expression)\n- Fixes applied\n- Final verification output\n\nCommit on the `kani_harnesses` branch:\n\n```\ngit add components\u002F\u003Cname>\u002F... components\u002Finterfaces\u002F...\ngit commit -m \"Add Kani harnesses for \u003Ccomponent>; fix \u003CN> arithmetic gaps\"\n```\n\n---\n\n## Common Pitfalls\n\n| Pitfall | Symptom | Fix |\n|---|---|---|\n| `HashMap` \u002F `Vec` in harness | `__rust_alloc_error_handler not supported` | Test struct fields directly |\n| `define_component!` wrapper | Complex macro expansion confuses Kani | Construct inner state structs directly |\n| `#[cfg(feature = \"X\")]` gate | Kani sees wrong version of a type | Check `Cargo.toml` features; pass `--features X` to `cargo kani` |\n| Unwind too low | `unwinding assertion failure` | Increase `#[kani::unwind(N)]` by 1 and retry |\n| `kani::assume` not audited | Harness passes but bug still present | Do Phase 4 audit before declaring success |\n| Stub missing an `impl` block | Compile error under `cargo kani` | Add `#[cfg(kani)]` version of every `impl` for the stubbed type |\n| `write_ref` vs `read_ref` risk | `write_ref` is assign (0\u002F1), not increment — lower risk | Focus overflow checks on fields that are genuinely incremented |\n\n---\n\n## Quick Reference\n\n```sh\n# Run all harnesses in a component\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml\n\n# Run a single harness\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml \\\n  --harness verification::\u003Charness_name>\n\n# Run with a specific feature enabled\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml \\\n  --features spdk\n```\n","## Goal\n\nFormally verify a Rust component using Kani. Kani proves absence of panics,\narithmetic overflows, and invariant violations for **all possible inputs** —\nnot just sampled ones. The output is either a passing proof or a concrete\ncounterexample pointing to a real bug.\n\nWork on a dedicated branch (e.g. `kani_harnesses`) so harnesses and fixes can\nbe reviewed separately from feature work.\n\n---\n\n## The core rule — verify at function granularity, against a spec-derived contract\n\nBefore anything else: **the unit of verification is a whole function plus a property\nfrom the spec — never a cherry-picked statement.** Lifting a suspect line and checking\nit for overflow\u002Fout-of-bounds is *bug-hunting*: it proves a fragment that has no\ncontract, so a green result only says \"this one line does not panic.\" Instead, for each\ntarget produce three things and label the global `Pn`:\n\n1. **precondition** — `kani::assume(...)` the spec's precondition (mirror the production guard);\n2. **function** — **call the real function** (preferred: the proof then tracks shipped\n   code). A faithful *whole-function* copy carrying the same contract is acceptable only\n   where the crate cannot be built under Kani, and must carry a drift\u002Fequality check;\n3. **postcondition** — `assert!(...)` the spec's postcondition.\n\nThen **validate the harness by fault injection**: make a change to the function that\nviolates the contract and confirm the harness *fails*. If it still passes, the harness is\nnot bound to the real code — fix it. (`--harness` substring-matches; use `--exact` with the\nfully-qualified `module::name` to run one harness in isolation.)\n\nThe statement scan in Phase 1 is only for *finding candidate functions and their\nproperties* — not for lifting statements into harnesses.\n\n---\n\n## Phase 1 — Reconnaissance\n\nBefore writing a single line of Kani code, read:\n\n1. All source files: `src\u002Flib.rs`, `src\u002Fstate.rs`, `src\u002Fentry.rs`, and any\n   submodules.\n2. The component's interface file (`components\u002Finterfaces\u002Fsrc\u002Fixxx.rs`).\n3. `Cargo.toml` — note feature flags, optional deps, and workspace deps.\n\n**Build a target list** — scan for every arithmetic expression that can panic\nor wrap:\n\n| Pattern | Risk | Example |\n|---|---|---|\n| `x += 1` on integer field | Overflow if field reaches MAX | `read_ref += 1` |\n| `x -= 1` on integer field | Underflow if field is 0 | `read_ref -= 1` |\n| `a * b` before a bounds check | Overflow before guard runs | `block_id * BLOCK_SIZE` |\n| `a + b` | Overflow | `offset + BLOCK_SIZE` |\n| `x as usize` widening cast | Safe on 64-bit, not on 32-bit | `size as usize * 4096` |\n| `buf[i]` inside a loop | Out-of-bounds if bound is wrong | `buf[i] = 1` |\n\nAlso note:\n- Types with raw pointers or FFI calls → need stubs (Phase 2)\n- Component framework macros (`define_component!`) → bypass in harnesses (Phase 3)\n- `Mutex` \u002F `Condvar` \u002F `Arc` → test the inner state directly, not through locks\n\n---\n\n## Phase 2 — Stub Unsafe \u002F FFI Dependencies\n\nKani cannot model raw pointers or calls into C\u002FSPDK FFI. Any type that\ncontains these must be replaced with a safe equivalent under `#[cfg(kani)]`.\n\n**Rule:** Gate the real implementation with `#[cfg(not(kani))]` and provide a\n`#[cfg(kani)]` stub with the **identical public API** but backed by safe Rust.\n\n```rust\n\u002F\u002F Production struct — raw pointer, FFI deallocator\n#[cfg(not(kani))]\npub struct DmaBuffer {\n    ptr: *mut std::ffi::c_void,\n    len: usize,\n    free_fn: unsafe extern \"C\" fn(*mut std::ffi::c_void),\n}\n\n\u002F\u002F Kani stub — Vec\u003Cu8>, no raw pointers, Drop is a no-op\n#[cfg(kani)]\npub struct DmaBuffer {\n    data: Vec\u003Cu8>,\n}\n```\n\nApply `#[cfg(not(kani))]` \u002F `#[cfg(kani)]` to **every** `impl` block for the\ntype (`Drop`, `Deref`, `DerefMut`, `Debug`, `Send`, `Sync`, method impls).\n\nStub rules:\n- `new(size, ...)` → `vec![0u8; size]`, no FFI calls\n- `from_raw(ptr, len, ...)` → `vec![0u8; len]`, ignore the raw pointer\n- `as_ptr()` → `self.data.as_ptr() as *mut _` (safe to return, just not deref'd)\n- `Drop` → empty body; `Vec` handles deallocation\n- Keep `unsafe impl Send` \u002F `unsafe impl Sync` — still needed for `Arc\u003CT>`\n\n**Suppress the lint** in every affected `Cargo.toml`:\n\n```toml\n[lints.rust]\nunexpected_cfgs = { level = \"warn\", check-cfg = ['cfg(kani)'] }\n```\n\n---\n\n## Phase 3 — Write Harnesses\n\nPlace all harnesses in a single `#[cfg(kani)] mod verification` block inside\n`src\u002Flib.rs`. This keeps them invisible to `cargo build` and `cargo test`.\n\n```rust\n#[cfg(kani)]\nmod verification {\n    use super::*;\n    \u002F\u002F access pub(crate) state types directly from here\n\n    #[kani::proof]\n    #[kani::unwind(N)]   \u002F\u002F N = deepest loop bound + 1\n    fn verify_something() { ... }\n}\n```\n\n### Harness rules\n\n**Use `kani::any()` for every input** — this tells Kani to consider all\npossible values, not just a sample.\n\n```rust\nlet count: u32 = kani::any();\nlet key: u64 = kani::any();\n```\n\n**Use `kani::assume()` only for pre-conditions that production code enforces.**\nEvery `assume` is a hypothesis — it must be audited in Phase 4.\n\n```rust\nkani::assume(count > 0); \u002F\u002F only if production code checks count > 0 first\n```\n\n**Bypass the component framework.** Do not try to drive `IFoo` through\n`define_component!`. Construct the inner state structs (`Inner`, `State`,\n`Entry`) directly — they are `pub(crate)` and visible inside `mod verification`.\n\n```rust\nlet entry = DispatchEntry { read_ref: kani::any(), write_ref: 0, ... };\n```\n\n**Avoid heap allocation in harnesses.** `HashMap::new()`, `Vec::new()`,\n`String::new()` pull in `__rust_alloc_error_handler` which Kani does not\nsupport. Instead, test invariants directly on struct fields.\n\n```rust\n\u002F\u002F Bad — HashMap triggers unsupported alloc error handler\nlet mut map = HashMap::new();\nmap.insert(key, entry);\n\n\u002F\u002F Good — test the guard logic on the struct directly\nlet active = entry.read_ref > 0 || entry.write_ref > 0;\nkani::assert(!active || ..., \"...\");\n```\n\n**Set `#[kani::unwind(N)]` correctly.**\n- For a loop with bound `B`: use `N = B + 1`\n- For harnesses with no loops: use `N = 1`\n- Kani will fail with an unwind error if N is too small\n\n### Standard harnesses to write for any component\n\n| Harness | What to verify |\n|---|---|\n| `verify_increment_no_overflow` | Every `field += 1` site: `checked_add` returns correct value below MAX, `None` at MAX |\n| `verify_decrement_underflow_guarded` | Every `field -= 1` site: safe because production guard `field > 0` exists |\n| `verify_multiplication_no_overflow` | Every `a * b` before a bounds check |\n| `verify_cast_no_overflow` | Every `x as usize * N` on a 32\u002F64-bit sensitive target |\n| `verify_state_invariant` | After a state transition, assert the resulting field values are consistent |\n| `verify_removal_requires_zero_refs` | Entry is only removed when all reference counts are zero |\n| `verify_symmetric_operation` | e.g. acquire then release leaves state identical to before |\n\n---\n\n## Phase 4 — The Assume Audit (Critical Step)\n\n**After all harnesses pass**, audit every `kani::assume` against the\nproduction code. This is the most important step — a passing harness with\nan unmatched assume only proves safety in a restricted universe.\n\nFor each `kani::assume(X)` in a harness:\n\n1. Find the corresponding guard in the production code.\n2. If the guard exists → the assume is justified. Leave it.\n3. If **no guard exists** → the assume is hiding a bug. The production code\n   depends on X being true but never checks it. **This is a defect.**\n\nExample of a matched assume (safe):\n```rust\n\u002F\u002F Harness\nkani::assume(entry.read_ref > 0);\n\u002F\u002F Production code — guard IS present\nif entry.read_ref == 0 {\n    return Err(DispatchMapError::RefCountUnderflow(key));\n}\nentry.read_ref -= 1;\n```\n\nExample of an unmatched assume (bug):\n```rust\n\u002F\u002F Harness\nkani::assume(read_ref \u003C u32::MAX);  \u002F\u002F assumed, but...\n\u002F\u002F Production code — NO guard\nentry.read_ref += 1;                \u002F\u002F bare increment, can overflow at u32::MAX\n```\n\n**Symmetric pairs are a strong signal.** If an error enum has `Underflow` but\nno `Overflow`, look for increment sites that lack the matching guard.\n\n---\n\n## Phase 5 — Fix and Re-Verify\n\n### Fix pattern for arithmetic overflow\n\nReplace bare arithmetic with `checked_*` operations and propagate via `?`:\n\n```rust\n\u002F\u002F Before\nentry.read_ref += 1;\n\n\u002F\u002F After\nentry.read_ref = entry\n    .read_ref\n    .checked_add(1)\n    .ok_or(ComponentError::RefCountOverflow(key))?;\n```\n\nApply the same pattern for:\n- `checked_mul` — for multiplications before bounds checks\n- `checked_add` — for additions (offset + size, etc.)\n- `checked_sub` — only if the existing guard can be removed\n\n### Add symmetric error variants\n\nWhen adding an overflow error, add it to the interface error enum\n(e.g. `components\u002Finterfaces\u002Fsrc\u002Fixxx.rs`) with a symmetric name:\n\n```rust\n\u002F\u002F\u002F Reference count underflow (release when already zero).\nRefCountUnderflow(CacheKey),\n\u002F\u002F\u002F Reference count overflow (acquire when already at u32::MAX).\nRefCountOverflow(CacheKey),   \u002F\u002F ← add this\n```\n\nAdd the matching `Display` arm.\n\n### Tighten the harnesses after fixing\n\nRemove `kani::assume` calls that were masking the bug. The harness should\nnow verify the full range including the previously-hidden edge case:\n\n```rust\n\u002F\u002F Before fix — assume hid the overflow\nkani::assume(read_ref \u003C u32::MAX);\nentry.read_ref += 1;\n\n\u002F\u002F After fix — no assume needed; checked_add handles all u32 values\nlet result = entry.read_ref.checked_add(1);\nif let Some(r) = result {\n    kani::assert(r == entry.read_ref + 1, \"...\");\n} else {\n    kani::assert(entry.read_ref == u32::MAX, \"overflow only at MAX\");\n}\n```\n\n### Re-run and confirm\n\n```sh\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml\n```\n\nTarget: `0 of N failed`, all harnesses in `Manual Harness Summary` show success.\n\n---\n\n## Phase 6 — Document and Commit\n\nCreate `VERIFICATION.md` in the component directory covering:\n- Component overview and what was verified\n- The stub approach (if FFI types were involved)\n- Each harness and what it proves\n- Bugs found (file, line, expression)\n- Fixes applied\n- Final verification output\n\nCommit on the `kani_harnesses` branch:\n\n```\ngit add components\u002F\u003Cname>\u002F... components\u002Finterfaces\u002F...\ngit commit -m \"Add Kani harnesses for \u003Ccomponent>; fix \u003CN> arithmetic gaps\"\n```\n\n---\n\n## Common Pitfalls\n\n| Pitfall | Symptom | Fix |\n|---|---|---|\n| `HashMap` \u002F `Vec` in harness | `__rust_alloc_error_handler not supported` | Test struct fields directly |\n| `define_component!` wrapper | Complex macro expansion confuses Kani | Construct inner state structs directly |\n| `#[cfg(feature = \"X\")]` gate | Kani sees wrong version of a type | Check `Cargo.toml` features; pass `--features X` to `cargo kani` |\n| Unwind too low | `unwinding assertion failure` | Increase `#[kani::unwind(N)]` by 1 and retry |\n| `kani::assume` not audited | Harness passes but bug still present | Do Phase 4 audit before declaring success |\n| Stub missing an `impl` block | Compile error under `cargo kani` | Add `#[cfg(kani)]` version of every `impl` for the stubbed type |\n| `write_ref` vs `read_ref` risk | `write_ref` is assign (0\u002F1), not increment — lower risk | Focus overflow checks on fields that are genuinely incremented |\n\n---\n\n## Quick Reference\n\n```sh\n# Run all harnesses in a component\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml\n\n# Run a single harness\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml \\\n  --harness verification::\u003Charness_name>\n\n# Run with a specific feature enabled\ncargo kani --manifest-path components\u002F\u003Cname>\u002FvN\u002FCargo.toml \\\n  --features spdk\n```\n",{"name":5,"description":7,"argument-hint":47},"[component-path] [interface-path]","unstable","dc564aa356769b7754391c9fa4fdaa0f179f476c",".claude\u002Fskills\u002Ftools-verify-kani",4,"https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research","https:\u002F\u002Fai-native-systems-research.github.io\u002Fai-native-systems-research\u002F","2026-11-12 06:08:32",{"source":8,"skillName":5,"commands":57,"prompt":67,"zipAvailable":68},[58,61,64],{"tool":59,"command":60},"npx","npx skills add AI-native-Systems-Research\u002Fai-native-storage-certus --skill tools-verify-kani",{"tool":62,"command":63},"bunx","bunx skills add AI-native-Systems-Research\u002Fai-native-storage-certus --skill tools-verify-kani",{"tool":65,"command":66},"pnpm","pnpm dlx skills add AI-native-Systems-Research\u002Fai-native-storage-certus --skill tools-verify-kani","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002F.claude\u002Fskills\u002Ftools-verify-kani\u002FSKILL.md",true,[],[71,86,102,112,129,141],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":42},"01M6KP29TWSNGADF3AJ47BR7TY","tools-spin-sync","Synchronize Spin\u002FPromela models with current source code and re-verify","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002Fcomponents\u002Fzyre\u002F.claude\u002Fskills\u002Ftools-spin-sync\u002FSKILL.md",[],[78,20,79,80,21,37,81,82,83,31,84,85],"tools spin sync","sync","code","models","name","with","source","source code",{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":42},"01M6KP277TDY3ZAJEBP5P6MDT8","tools-spin-model","Create a new Spin\u002FPromela formal verification model for a system property","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002Fcomponents\u002Fzyre\u002F.claude\u002Fskills\u002Ftools-spin-model\u002FSKILL.md",[],[93,37,20,94,95,96,97,98,99,100,101],"tools spin model","system","formal verification","number","for","prove","new","create","verification",{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":42},"01M6KP250W406CEDSF02BRXT9D","tools-creusot-install","Install the Creusot Rust verification tool","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002Fcomponents\u002Fzyre\u002F.claude\u002Fskills\u002Ftools-creusot-install\u002FSKILL.md",[],[109,110,20,33,101,111],"tools creusot install","install","tool",{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":42},"01M6KP22H28FQ1X0V7VJHEFWXD","tools-creusot-init","Prepare an existing Cargo project to use Creusot formal verification","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002Fcomponents\u002Fzyre\u002F.claude\u002Fskills\u002Ftools-creusot-init\u002FSKILL.md",[],[119,20,120,121,122,123,124,101,125,95,126,127,128],"tools creusot init","init","project","directory","components","prepare","use","cargo","manager","Existing",{"skillNo":130,"name":131,"nameZh":6,"description":132,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":133,"categories":134,"keywords":135,"publishedAt":42},"01M6KP1V506J9YM8DKKVDG1NRE","tools-creusot-coq-install","Add Coq 8.20 as an additional prover to an existing Creusot installation, for verification conditions that SMT solvers cannot discharge","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002Fcomponents\u002Fzyre\u002F.claude\u002Fskills\u002Ftools-creusot-coq-install\u002FSKILL.md",[],[136,137,110,20,97,128,138,139,101,140],"tools creusot coq install","Coq","as","installation","add",{"skillNo":142,"name":143,"nameZh":6,"description":144,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":145,"categories":146,"keywords":147,"publishedAt":42},"01M6KP1PQJF3H765TYZAZ7P3EF","tools-creusot-annotate-interfaces","Formally verify a component's properties with Creusot and annotate its interface definitions","https:\u002F\u002Fgithub.com\u002FAI-native-Systems-Research\u002Fai-native-storage-certus\u002Fblob\u002Funstable\u002Fcomponents\u002Fzyre\u002F.claude\u002Fskills\u002Ftools-creusot-annotate-interfaces\u002FSKILL.md",[],[20,148,149,83,82,150,21,41,32],"tools creusot annotate interfaces","annotate","properties"]