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

VeriStruct is a novel framework that extends AI-assisted automated verification to complex data structure modules in Verus by employing a planner for systematic code generation and a repair stage to correct syntax errors, achieving a 99.2% success rate in verifying functions across eleven Rust modules.

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

Published 2026-03-04
📖 5 min read🧠 Deep dive

Imagine you are building a massive, complex city out of LEGO bricks. You want to be 100% sure that every bridge, tunnel, and skyscraper is structurally sound before anyone lives there. In the world of software, this "structural soundness" is called formal verification. It's a mathematical way of proving code is bug-free.

However, doing this manually is like hiring a team of architects to check every single brick by hand. It takes forever, is incredibly expensive, and requires a PhD in math.

Recently, we gave the architects an AI assistant (a Large Language Model or LLM) to help. The AI is great at writing code, but when it comes to checking the math, it often gets confused. It's like giving a brilliant but inexperienced intern a set of blueprints written in a secret language they've never seen before. They might write a beautiful building, but they might forget to check if the foundation can actually hold the weight.

Enter VeriStruct.

VeriStruct is a new "super-intern manager" designed to help AI assistants verify complex software modules (like data structures) using a tool called Verus (which speaks the language of Rust, a popular programming language).

Here is how VeriStruct works, using some everyday analogies:

1. The Problem: The "Translation" Gap

Imagine you ask an AI to verify a Ring Buffer (a type of data storage that works like a circular conveyor belt).

  • The AI's Mistake: The AI might try to describe the conveyor belt by listing every single brick's position. This is technically true, but it's so messy that the math checker gets overwhelmed and gives up.
  • The Syntax Trap: Verus has very strict rules (like "you can't touch the global state while writing a proof"). The AI, having read a lot of general code but little Verus code, often breaks these rules, like trying to use a hammer to drive a screw.

2. The Solution: The "Project Manager" (The Planner)

Instead of just asking the AI, "Fix this code," VeriStruct acts like a Project Manager.

  • The Planner Module: Before the AI writes a single line, the Planner looks at the code and asks: "What do we actually need here?"
    • Do we need a View? (Think of this as a "simplified map" of the data. Instead of showing every brick, the map just says, "Here is the list of items on the belt.")
    • Do we need a Type Invariant? (This is a "safety rule" that must always be true, like "The belt must always have at least one empty spot.")
    • Do we need Proof Blocks? (These are little hints to the math checker on how to solve a tricky puzzle.)
  • The Planner decides which tools to use and in what order, so the AI doesn't waste time trying to build a bridge when it only needs to lay a sidewalk.

3. The "Drafting" Phase (Generation)

Once the plan is set, VeriStruct asks the AI to write the annotations (the safety rules and maps).

  • The Prompt: The AI isn't just told to "do it." It's given a cheat sheet (syntax guidelines) and examples of how other experts solved similar problems. This stops the AI from using the "secret language" incorrectly.
  • The Refinement: Sometimes the AI draws a map that is too detailed (too many bricks). VeriStruct has a "Refinement Step" that tells the AI: "Hey, simplify this. We don't need to see the individual bricks; just show us the flow of traffic." This makes the math much easier to check.

4. The "Inspector" Phase (Repair)

Even with a great plan, the AI will make mistakes. The code might fail the math check.

  • The Repair Loop: Instead of giving up, VeriStruct acts like a Quality Control Inspector.
    • The math checker says, "Error: You tried to use a hammer on a screw!"
    • VeriStruct catches this specific error, routes it to a specialized "Repair Module" (a mini-AI trained just to fix that specific type of mistake), and asks the main AI to try again.
    • It does this over and over, like a game of "Hot and Cold," until the code passes every check.

The Results: A Supercharged Team

The researchers tested VeriStruct on 11 different complex data structures (like ring buffers, trees, and locks).

  • Without VeriStruct: A standard AI could only verify about 4 out of 11 modules.
  • With VeriStruct: The system successfully verified 10 out of 11 modules, and checked 99.2% of all the individual functions inside them.

The Big Picture

Think of VeriStruct as the difference between throwing a raw, untrained intern into a construction site and giving them a Project Manager, a Safety Manual, a specialized Tool Kit, and a Quality Control Team.

It doesn't replace the human or the AI; it orchestrates them. It takes the raw creativity of AI and channels it through a rigorous, step-by-step process that understands the strict rules of formal verification. This brings us one giant step closer to a future where our critical software (like self-driving cars or banking systems) can be automatically proven safe, without needing a team of human mathematicians to check every single line of code.

Get papers like this in your inbox

Personalized daily or weekly digests matching your interests. Gists or technical summaries, in your language.

Try Digest →