formal-verification
БесплатноБез исполняемых скриптовНе проверенFormal verification skill for systems code in Rust and C. Use when proving absence of panics, overflow or out-of-bounds access, writing Kani proof harnesses…
от mohitmishra786★ 307 звёзд на GitHubОб этом скилле
Formal Verification for Systems Code
Purpose
Guide agents through practical formal verification of Rust and C (checked with Kani 0.68, CBMC 6.6 and Frama-C 33.0): choosing a tool, writing harnesses and contracts, reading counterexamples, and fixing the common failures.
Triggers
- "How do I prove this Rust function can't panic or overflow?"
- "How do I write a Kani proof harness?"
- "How do I model check C code with CBMC?"
- "What does 'unwinding assertion' mean?"
- "How do I prove an ACSL contract with Frama-C?"
- "Should I use fuzzing, Miri or a model checker?"
Workflow
1. Choosing a tool
| Tool | Language | Technique | Proves |
|---|---|---|---|
| Kani | Rust | Bounded model checking (CBMC backend) | No panics, overflow, UB in unsafe; user assert!s; function contracts |
| CBMC | C/C++ | Bounded model checking | Bounds, pointer, overflow checks; user asserts, up to a loop bound |
| ESBMC | C/C++ | Bounded model checking (SMT) | Similar to CBMC |
| Frama-C WP | C | Deductive (ACSL contracts → provers) | Full contracts for all inputs, loops via invariants |
| Frama-C EVA | C | Abstract interpretation | Absence of runtime errors, sound but may raise false alarms |
| Verus, Creusot | Rust | Deductive | Full functional correctness, needs specs and invariants |
What do you need?
├── Find bugs fast, any input → fuzzing (skills/runtimes/fuzzing)
├── Check one execution for UB in unsafe Rust → Miri
├── Prove a property for ALL inputs, bounded loops → Kani (Rust) / CBMC (C)
├── Prove a C contract for all inputs, unbounded loops → Frama-C WP
└── Prove a whole C program free of runtime errors → Frama-C EVA
Bounded model checkers are exhaustive up to the loop bound you give them. Code with unbounded loops needs a bound plus an unwinding assertion, or contracts and invariants.
2. Kani: proof harnesses
cargo install --locked kani-verifier
cargo kani setup # downloads the pinned toolchain and CBMC (needs rustup, curl)
cargo kani # run every #[kani::proof] in the crate
cargo kani --harness ring_fifo_order
// src/lib.rs
pub struct Ring<const N: usize> {
head: usize,
len: usize,
buf: [u8; N],
}
impl<const N: usize> Ring<N> {
pub fn new() -> Self { Ring { head: 0, len: 0, buf: [0; N] } }
pub fn push(&mut self, v: u8) -> bool {
if self.len == N { return false; }
let tail = (self.head + self.len) % N;
self.buf[tail] = v;
self.len += 1;
true
}
pub fn pop(&mut self) -> Option<u8> {
if self.len == 0 { return None; }
let v = self.buf[self.head];
self.head = (self.head + 1) % N;
self.len -= 1;
Some(v)
}
}
/// Midpoint with a classic overflow bug.
pub fn midpoint(a: u32, b: u32) -> u32 { (a + b) / 2 }
/// Fixed version.
pub fn midpoint_fixed(a: u32, b: u32) -> u32 { a / 2 + b / 2 + (a % 2 + b % 2) / 2 }
#[cfg(kani)]
mod proofs {
use super::*;
#[kani::proof]
fn midpoint_no_overflow() {
let a: u32 = kani::any(); // every possible u32
let b: u32 = kani::any();
let _ = midpoint(a, b); // Kani reports the overflow
}
#[kani::proof]
fn midpoint_fixed_correct() {
let a: u32 = kani::any();
let b: u32 = kani::any();
let m = midpoint_fixed(a, b);
assert!(m >= a.min(b) && m <= a.max(b));
assert_eq!(m as u64, (a as u64 + b as u64) / 2);
}
#[kani::proof]
#[kani::unwind(5)] // loops run at most 4 times
fn ring_fifo_order() {
let mut r: Ring<4> = Ring::new();
let n: usize = kani::any();
kani::assume(n <= 4); // restrict the input space
for i in 0..n { assert!(r.push(i as u8)); }
for i in 0..n { assert_eq!(r.pop(), Some(i as u8)); }
assert_eq!(r.pop(), None);
}
}
# Cargo.toml: silence the unknown-cfg warning for `cfg(kani)`
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] }
Checking harness proofs::midpoint_no_overflow...
Failed Checks: attempt to add with overflow
VERIFICATION:- FAILED
...
Complete - 3 successfully verified harnesses, 1 failures, 4 total.
cargo kani -Z concrete-playback --harness midpoint_no_overflow --concrete-playback=print prints a
#[test] that reproduces the failing inputs.
3. Kani: function contracts
Contracts let Kani check a function once and reuse its specification at call sites:
#[cfg_attr(kani, kani::requires(divisor != 0))]
#[cfg_attr(kani, kani::ensures(|r: &u32| *r <= dividend))]
pub fn safe_div(dividend: u32, divisor: u32) -> u32 { dividend / divisor }
#[cfg(kani)]
#[kani::proof_for_contract(safe_div)]
fn safe_div_contract() {
let _ = safe_div(kani::any(), kani::any()); // inputs constrained by `requires`
}
# Contracts are unstable: without the flag the crate fails to compile
cargo kani
Установить formal-verification в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл formal-verification?
Formal verification skill for systems code in Rust and C. Use when proving absence of panics, overflow or out-of-bounds access, writing Kani proof harnesses or function contracts, bounded model checking C with CBMC, proving ACSL contracts with Frama-C WP, or choosing between model checking, deductive verification, fuzzing and Miri. Activates on queries about Kani, cargo kani, kani::any, CBMC, nondet, unwinding assertion, Frama-C, ACSL, WP, EVA, Verus, Creusot, ESBMC, or formal verification.
Как установить скилл formal-verification?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл formal-verification запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic