From Natural Language to Verified Code: Toward AI Assisted Problem-to-Code Generation with Dafny-Based Formal Verification
This paper introduces the NL2VC-60 dataset and evaluates various prompting strategies to enable open-weight Large Language Models to transform natural language problems into formally verified code using the Dafny verifier and uDebug platform.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are trying to teach a very talented, but sometimes "hallucinating" apprentice how to build high-security vaults.
This apprentice (the AI/Large Language Model) is incredibly fast and has read almost every book in the world, but they have a bad habit: sometimes they build a vault that looks perfect on the outside, but when you actually try to turn the key, the door just falls off. In the world of software, we call this "hallucination"—code that looks right but is actually broken.
This paper describes a new way to train and supervise these apprentices using a "Mathematical Inspector" to ensure they aren't just faking it.
The Problem: The "Vibe Coding" Trap
Most people use AI to write code by giving it a "vibe"—a loose, natural language description like, "Hey, write me a program that sorts numbers."
The problem is that for critical systems (like airplane software or medical devices), "mostly right" isn't good enough. You need Formal Verification. This is like having a mathematical proof that says, "It is physically impossible for this door to open unless the correct code is entered." Writing these proofs is incredibly hard and tedious for humans.
The Solution: The Three-Step Training Program
The researchers created a new test called NL2VC-60 (a collection of 60 complex logic puzzles) and tested seven different AI models using three different "teaching styles":
1. The "Blindfold" Test (Contextless Prompting)
- The Analogy: You tell the apprentice, "Build a vault," and walk out of the room.
- The Result: Almost total failure. The AI gets overwhelmed. It doesn't know where to start, what the dimensions should be, or how to structure the blueprints. It’s like trying to build a house without knowing if it’s a cottage or a skyscraper.
2. The "Blueprint" Test (Signature Prompting)
- The Analogy: You give the apprentice the blueprints and the exact dimensions of the door, but you don't tell them how to build the internal gears.
- The Result: A massive breakthrough! By giving the AI a "skeleton" (a formal structure to follow), the AI stopped struggling with the basics and could focus on the hard part: the logic. Even the "smaller" AI models suddenly became much more capable.
3. The "Master & Critic" Loop (Self-Healing Prompting)
- The Analogy: This is the secret sauce. The apprentice builds a gear, and a "Mathematical Inspector" (a tool called Dafny) immediately checks it. If the gear is 0.001mm off, the Inspector hands a note back to the apprentice saying, "This part won't turn; try again." The apprentice reads the note, fixes the gear, and tries again.
- The Result: This was the most successful method. The AI learned to "self-heal." Instead of giving up when they made a mistake, they used the error messages as a guide to fix themselves.
The "Truth Oracle" (uDebug)
The researchers were worried about something called "Vacuous Verification."
- The Analogy: Imagine an apprentice builds a vault that is so simple it has no lock at all. The Inspector says, "Well, technically, no one can break in because there's no way to even try!" The vault is "verified," but it's useless.
- The Fix: The researchers used a platform called uDebug, which acts like a professional thief trying every possible way to break into the vault. This ensures the code isn't just "mathematically consistent," but actually works in the real world.
The Big Takeaway
The star of the show was a model called Gemma 4-31B, which proved to be an incredible "apprentice." When allowed to learn from its mistakes through the "Master & Critic" loop, it reached a 90.91% success rate.
The bottom line: We don't need to wait for "perfect" AI to build perfect software. If we pair "smart but messy" AI with "strict and mathematical" inspectors, we can create software that is not just "plausible," but provably correct.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.