Abstract
Formal program verification ensures software correctness but remains labor-intensive. While Large Language Models (LLMs) show promise, they often fail in repository-scale projects due to a lack of global context. We present RagVerus, a framework that utilizes Retrieval-Augmented Generation (RAG) to provide LLMs with cross-module dependencies and relevant code-proof examples. RagVerus achieves a 27% relative improvement on repository-level benchmarks and triples proof pass rates on function-level tasks under constrained budgets.
Introduction
Formal verification is the gold standard for high-assurance software, yet writing proofs is difficult even for experts. Current LLM-based automation is largely "function-centric," ignoring the "global context"—the helper functions, types, and invariants defined across a repository. Without this context, models frequently hallucinate or fail to identify the logical premises required for a proof. RAG-Verus addresses this gap by mining repository-wide properties to ground LLM generation in the project's specific logical structure.
The RAG-Verus Framework
The RAG-Verus pipeline automates the verification process for Verus (a Rust-based verification tool) through three primary stages: property mining, context retrieval, and iterative refinement.
- Mining Code Properties: The system pre-processes the entire repository using static analysis to extract metadata, such as function signatures, module hierarchies, and control-flow relationships.
- Context Retrieval: This stage identifies relevant few-shot examples and logical dependencies. It combines semantic vector embeddings with deterministic dependency graphs to ensure the LLM receives both the "vibe" of the codebase and the hard logical requirements needed to close a proof.
- Proof Generation & Refinement: GPT-4o generates proofs which are then checked by the Verus compiler. If the proof fails, error messages are fed back to the model for iterative self-correction.
Context Retrieval and Informalization
A key innovation in RAG-Verus is the use of "informalization"—translating code into natural language summaries—to improve retrieval accuracy. Matching the intent of a function (e.g., "checks if the object obtains the mutex lock") often yields better results than matching raw syntax, as it captures the semantic purpose of the code more effectively.
Experimental Evaluation
The authors evaluated RAG-Verus on two benchmarks:
- VerusBench: 150 function-level verification tasks.
- RepoVBench: A new repository-level benchmark derived from VeriSMo, a real-world verified security module for confidential virtual machines. It contains 383 tasks across 52 modules, categorized into "Simple" and "Complex" (requiring cross-module reasoning).
Key Results
- Repository-Level Success: RAG-Verus achieved a 27% relative improvement over non-RAG baselines on RepoVBench.
- Efficiency under Budget: On VerusBench, RAG-Verus reached a 60.4% success rate compared to the baseline's 18.0% when limited to only 5 samples. This demonstrates that providing the right context upfront is significantly more effective than massive sampling.
- Stylistic Alignment: BLEU score analysis indicates that RAG-augmented models produce proofs that closely mirror human-written code, suggesting they successfully learn project-specific verification patterns.
Discussion and Future Work
While RAG-Verus significantly improves verification performance, "Complex" tasks requiring deep cross-module reasoning remain challenging, with only a 16% success rate in the hardest cases. Future work will focus on handling long proofs (>80 lines) and expanding the system to larger, more diverse repositories. The authors also plan to explore "self-evolved" methods where models iteratively improve their own retrieval and verification strategies.
Summary updated