TL;DR
VeriStruct is a novel AI-assisted framework that automates the formal verification of complex Rust data structure modules using Verus. By combining a strategic planner module with an iterative, syntax-aware repair loop, VeriStruct successfully verified 99.2% of functions across 11 real-world benchmarks. This marks a significant leap forward from prior AI verification efforts, which were largely limited to simple, single functions.
What Problem Does This Paper Address?
Formal program verification mathematically proves that code is free of bugs and vulnerabilities. However, it relies heavily on developers writing complex logical annotations—such as preconditions, postconditions, and invariants—which requires immense time and specialized expertise.
While Large Language Models (LLMs) have recently shown promise in generating these annotations, prior work has focused almost exclusively on simple, standalone textbook algorithms. Verifying entire data structure modules (like ring buffers or tree maps) introduces two major hurdles:
- Structural Complexity: Data structures require a mathematical abstraction (a "view") to bridge concrete code with logic, alongside "type invariants" that must hold true across multiple interacting methods.
- Syntax and Semantic Ignorance: Specialized verification languages like Verus (a verification extension for Rust) are scarce in LLM training data. As a result, LLMs frequently hallucinate invalid syntax or violate verification-specific rules (e.g., trying to call a regular executable function inside a logical specification block).
Methods
VeriStruct tackles these challenges using a structured, two-stage pipeline orchestrated by an LLM agent architecture.
- Stage 1: Planned Generation: Instead of asking the LLM to generate all annotations at once, a Planner Module analyzes the code to determine exactly what is needed. It then sequentially invokes specialized sub-modules: View Generation (to create mathematical abstractions), Type Invariant Generation, Specification Generation, and Proof Block Generation. Crucially, a "view refinement" step forces the LLM to simplify over-complicated abstractions into clean, minimal representations.
- Stage 2: Iterative Repair Loop: When the Verus verifier fails and throws an error, VeriStruct doesn't give up. It uses lightweight regex pattern matching to categorize the error message and routes it to one of several specialized Repair Modules (e.g., for type mismatches, arithmetic overflows, or specification misuses). The repair module injects targeted syntax guidelines and the error context back into the prompt, asking the LLM to fix the mistake.
Datasets
The authors evaluated VeriStruct on a benchmark set of 11 Rust data structure modules compiled from the Verus GitHub repository and other open-source projects. The benchmarks include:
- Common structures:
RingBuffer,Vectors,Bitmap,Treemap,Option, andNode(for binary search trees). - Concurrent/advanced structures:
Atomics,Invariants,RwLockVstd,SetFromVec, andTransfer.
To ensure a rigorous evaluation, the authors heavily modified these benchmarks with additional methods and unit tests, verifying that they did not appear verbatim in the LLM's (OpenAI o1) training data snapshot. In total, the benchmark suite comprised 129 functions to be verified.
Key Insights and Ideas
- The Power of "View Refinement": Left to their own devices, LLMs often generate trivial "Cartesian-product" views that simply map every single concrete data field directly to the specification. VeriStruct’s refinement step prompts the LLM to reconsider its approach, leading to cleaner, more abstract mathematical representations that make subsequent proofs drastically simpler.
- Embracing Temporary Regressions: During specification generation, the framework occasionally adopts a candidate contract that temporarily breaks previously verified functions. The authors found that deliberately retaining these imperfect specifications allows the downstream repair modules to diagnose deeper, multi-method logical inconsistencies and ultimately achieve full verification.
- Domain-Specific Guardrails Trump Model Scale: Even when compared against state-of-the-art autonomous coding agents like Claude Code (running Claude Sonnet 4.5), VeriStruct's structured workflow achieved superior verification rates with lower token consumption, proving that domain-specific scaffolding is more effective than raw model capability alone.
Key Results
- High Success Rate: VeriStruct successfully solved 10 out of the 11 benchmarks, fully verifying 128 out of 129 functions (99.2%). For the single unsolved benchmark (
Node), it still verified 11 out of 12 functions. - Baseline Comparison: It vastly outperformed a standard iterative LLM baseline, which only solved 4 benchmarks (52 functions).
- Agent Comparison: It beat Claude Code, which solved 8 benchmarks (102 functions), while consuming fewer tokens on average (~22k tokens per benchmark vs. Claude Code's ~24k).
Limitations and Future Work
- Dependency on Unit Tests: VeriStruct currently requires users to provide a high-coverage unit test suite to capture developer intent and prevent the LLM from generating vacuous specifications. The authors plan to explore LLM-assisted automatic unit test generation to alleviate this burden.
- Complex Proof Libraries: For highly intricate concurrent data structures, the framework can struggle with complex mathematical proofs. Future iterations aim to integrate Retrieval-Augmented Generation (RAG) to help the system look up and apply relevant lemmas from the Verus standard library, as well as incorporate constrained decoding techniques to eliminate syntax errors entirely.
Summary updated