VeriStruct: AI-assisted Automated Verification of Data-Structure Modules in Verus

Chuyue Sun, Yican Sun, Daneshvar Amrollahi, Ethan Zhang, Shuvendu K. Lahiri, Shan Lu, David L. Dill, Clark W. Barrett

Formal verification is the "gold standard" of software reliability—it uses mathematical proofs to guarantee that code is free of bugs and vulnerabilities. However, it has historically been a niche field because writing the necessary "annotations" (the mathematical blueprints and proofs) requires immense expertise and effort. While Large Language Models (LLMs) have shown promise in assisting this process, they often stumble when moving from simple functions to complex, real-world data structures.

Enter VeriStruct, a new framework designed to automate the verification of data-structure modules in Rust using the Verus verification tool.

TL;DR

VeriStruct is an AI-assisted framework that automates the formal verification of complex Rust data structures. By using a specialized multi-stage pipeline—including a planner, abstraction refinement, and an iterative repair loop—it successfully verified 99.2% of functions across 11 diverse benchmarks, significantly outperforming general-purpose coding agents.

What Problem Does This Paper Address?

The authors identify two primary hurdles in AI-assisted verification:

  1. Structural Complexity: Verifying a data structure (like a Ring Buffer or a Treemap) is much harder than verifying a standalone sorting algorithm. It requires creating a mathematical "View" (an abstraction of the data) and "Type Invariants" (rules that must always be true, like "the head index must be less than the buffer size").
  2. Syntax and Semantic Gaps: LLMs often hallucinate or misuse the specialized syntax of verification languages like Verus. For example, an LLM might try to call a standard Rust function inside a proof block, which is strictly forbidden.

Methods

VeriStruct doesn't just ask an LLM to "write the proof." It uses a structured, multi-module workflow:

  • The Planner: An initial agent analyzes the Rust code and decides which components are needed (e.g., "Does this need a mathematical sequence abstraction? Does it need range constraints?").
  • Specialized Generation Modules: Dedicated modules generate the View (the abstraction), the Type Invariants, the Specifications (pre/post-conditions), and the Proof Blocks.
  • View Refinement: This is a standout feature. LLMs often produce "trivial" abstractions that just mirror the code. VeriStruct includes a refinement step that pushes the LLM to create simpler, more mathematical abstractions, which makes the underlying SMT (Satisfiability Modulo Theories) solvers much more efficient.
  • Iterative Repair Loop: If the Verus verifier fails, VeriStruct doesn't just give up. It uses a suite of specialized repair modules that categorize the error (e.g., "Arithmetic Overflow" or "Syntax Error") and provide targeted instructions to the LLM to fix the specific issue.

Datasets

The researchers evaluated VeriStruct on 11 Rust data structure benchmarks sourced from the Verus GitHub repository and other open-source projects. These include:

  • Concurrency primitives: Atomics, Read/Write locks.
  • Standard structures: Ring Buffers, Bitmaps, Treemaps, and Vectors.
  • Logic frameworks: Invariant frameworks for shared state.

The benchmark set included a total of 129 functions to be verified.

Key Insights and Ideas

  • Abstraction is Everything: The "Aha!" moment in the paper is the realization that LLMs are too literal. By forcing the model to "refine" its view into something more abstract, the researchers made the verification task significantly easier for the automated reasoning tools.
  • Modular beats Monolithic: Instead of one giant prompt, breaking the task into specialized stages (Plan -> Generate -> Refine -> Repair) allows for much higher accuracy and lower token costs.
  • Syntax Guidance: Embedding specific "rules of the road" from the Verus tutorial directly into the prompts helps mitigate the scarcity of Verus code in the LLM's original training data.

Key Results

VeriStruct demonstrated impressive performance:

  • Success Rate: It successfully verified 10 out of 11 benchmarks.
  • Function Coverage: It verified 128 out of 129 functions (99.2%).
  • Comparison: It far surpassed a "single-shot" baseline (which only verified 52 functions) and outperformed Claude Code, a state-of-the-art agentic coding tool, which verified 102 functions.
  • Efficiency: Interestingly, VeriStruct achieved these results using fewer tokens on average than Claude Code, proving that a structured workflow is more efficient than raw model power.

Limitations and Future Work

While VeriStruct is a major step forward, it still has limitations:

  • Human-in-the-loop for Intent: The system currently requires a human-written unit test suite to define what the code is supposed to do. Without these tests, the AI might verify "vacuous" specifications that don't actually prove anything useful.
  • Complex Lemmas: Some highly complex proofs require specific mathematical lemmas that the system might not find on its own.

Future Directions: The authors plan to integrate Retrieval-Augmented Generation (RAG) to help the AI find useful lemmas in standard libraries and explore Automatic Unit Test Generation to remove the need for manual testing. They also suggest that Reinforcement Learning (RL) could be used to train models specifically for the "reward" of a successful verification.

Summary updated

BibTeX
@inproceedings{sun2026veristruct,
  author = {Chuyue Sun and Yican Sun and Daneshvar Amrollahi and Ethan Zhang and Shuvendu K. Lahiri and Shan Lu and David L. Dill and Clark W. Barrett},
  title = {{VeriStruct: AI-assisted Automated Verification of Data-Structure Modules in Verus}},
  booktitle = {TACAS},
  year = {2026},
  doi = {10.1007/978-3-032-22749-2\_6},
}
Figure