KaPilot: LLM-Assisted Generation of Kani Specifications for Unsafe Rust Verification
Minghua Wang, Yuxi Ling, Mingzhi Gao, Yuwei Liu, Huang Lj
Ant Group (China) · National University of Singapore
Key points
From the paper's conclusion- We evaluated KaPilot on 54 unsafe Rust functions with ground truth and 44 without.
Abstract
Rust’s ownership and type system provide strong memory safety guarantees, but unsafe code still presents memory safety risks. Formal verification is crucial for ensuring memory safety, but writing precise specifications for unsafe Rust is challenging and largely manual. Large language models (LLMs) have shown promise in generating formal specifications but are often code-centric, prone to inheriting implementation flaws, and lack systematic quality assessment. In this paper, we present KaPilot, a multi-agent framework for automatically generating specifications to verify unsafe Rust memory safety using Kani. The process begins with lightweight program analysis and proof harness generation. The SafetyReq agent extracts a concise, refined list of safety requirements from the target Rust function’s documentation, which guides the SpecGen agent in producing initial specifications that specify memory safety concerns. Then, the specifications are iteratively refined through a generate–precheck–verify loop involving SpecGenerate, SpecPrecheck, and SpecVerify agents, which assess quality and feed errors back. By executing this loop multiple times, KaPilot generates a set of candidate specifications. Finally, the shuffle-and-implication strategy is applied to systematically determine the best specification from these candidates. We evaluated KaPilot on 54 unsafe Rust functions with ground truth and 44 without. KaPilot achieved 88.9% and 69.2% specification generation success, respectively, with 57.4% of generated specifications equivalent to or stronger than the ground truth. Compared with AutoSpec, KaPilot produces 14.8% more verifiable specifications and 25.9% more equivalent-or-better specifications.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Bringing Foundational Verification to Real-World Rust CodeProceedings of the ACM on Programming Languages · 2026
- Miri: Practical Undefined Behavior Detection for RustProceedings of the ACM on Programming Languages · 2026
- MAGS: Multi-agent Auto-formalization Guarantees Safety for Agentic OutputsarXiv · 2026
- Agentic Discovery of Soundness Bugs in Safe Rust BindingsarXiv · 2026
- Beyond Source Code: Evaluating Natural Language Specifications for LLM-Based C-to-Rust TranslationarXiv · 2026
- Path2Spec: Path-Aware Specification Generation via Large Language ModelsarXiv · 2026