Skip to content
Open access

KaPilot: LLM-Assisted Generation of Kani Specifications for Unsafe Rust Verification

Jul 2026 · Proceedings of the ACM on Software Engineering · Vol 3, pp. 3389 - 3410 · 0 citations · 35 references
Computer Science

TL;DR

KaPilot is presented, a multi-agent framework for automatically generating specifications to verify unsafe Rust memory safety using Kani, and the shuffle-and-implication strategy is applied to systematically determine the best specification from these candidates.

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 PDF

Similar papers

#software testing Book Open access Sep 2026

All Your Assembly Belongs to Rust: Automated Lifting for Uniform Testing and Verification

This paper translates Rust code containing RISC-V inline assembly into pure Rust code by emulating each instruction using a machine model extracted from the official RISC-V Sail ISA specification, and demonstrates how each category is handled by the translation.

Charly Castes, Gurvan Debaussart, Thomas Bourgeat · 0 citations
Conference Open access Sep 2026

QiMeng-VPID: Verification-Grounded Port-Level Iterative Decomposition for Complex Verilog Generation

This work proposes VPID, a multi-agent framework for generating complex Verilog that achieves monotonic functional improvement and introduces an experience-guided refinement strategy that distills historical waveform mismatches into constraints, guiding the targeted debugging for the unverified ports.

Hong-Guang Wang, Jiaming Guo, Rui Zhang et al. · 0 citations
Book Open access Oct 2026

SafeDep: Detecting State Mutation Unsoundness in Rust via Dependency Slicing and LLM Reasoning

Rust's type system protects safe code, but many low-level abstractions depend on internal unsafe operations whose correctness rests on memory and logical invariants. In struct-based abstractions, a sibling method may legally modify internal fields while invalidating a precondition required by another method's unsafe op...

Zi-Hao Rao, Yi-Lin Chen, Cheng-Jun Chen et al. · 0 citations
#artificial intelligence Preprint Oct 2026

Beyond Type-checking: Towards Holistic Evaluation of Formal Specification Generation

When generating verifiable code, natural language requirements are mapped to machine checked code using LLMs and agentic workflows. A crucial component of this pipeline is specification generation (SpecGen), which produces a formal contract against which an agent can prove implementation correctness. Proof generation c...

Srijith Nair, Aditya Vempaty, Jia Liu et al. · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.