Automated Proof Generation for Rust Code via Self-Evolution

Tianyu Chen, Shuai Lu, Shan Lu, Yeyun Gong, Chenyuan Yang, Xuheng Li, Md Rakib Hossain Misu, Hao Yu, Nan Duan, Peng Cheng, Fan Yang, Shuvendu K Lahiri, Tao Xie, Lidong Zhou

Introduction

Formal verification guarantees that code is mathematically bug-free, but writing the necessary proofs is incredibly labor-intensive. Because there is virtually no training data for AI to learn how to write these proofs, researchers introduce SAFE, a self-evolving framework that synthesizes its own training data to teach open-source Large Language Models (LLMs) how to verify Rust code. By learning from both its successes and its verifier-rejected failures, SAFE boosts automated proof generation accuracy from ~14% (using GPT-4o) to over 52%.

The Data Wall in Formal Verification

LLMs are highly capable at writing code, but they cannot inherently guarantee that the code is correct. Formal verification solves this by mathematically proving a program satisfies desired properties under all possible inputs.

To achieve this, developers use specialized tools—like Verus for the Rust programming language. However, using Verus requires writing formal specifications (pre- and post-conditions) and complex proof annotations (like loop invariants). Automating this with LLMs hits a massive data wall: there are fewer than 500 Verus-verified Rust files on GitHub. Without millions of tokens of human-written proofs to train on, teaching an LLM to formally verify code is nearly impossible using standard supervised learning.

The SAFE Framework

To overcome this data scarcity, the authors propose SAFE (Self-evolving Automated prooF gEneration). This framework bootstraps a highly capable proof-generating model from scratch using a self-evolving loop.

The SAFE framework pipeline illustrating code translation, specification synthesis, and proof synthesis.
  1. Code Translation: The system uses GPT-4o to translate thousands of standard Python and Rust snippets into Verus-compatible Rust code.
  2. Self-Evolving Specification Synthesis: Before proving code, a specification (what the code should do) is required. SAFE prompts an LLM to guess specifications, then uses the Verus verifier to symbolically check if those specs accept passing test cases and reject failing ones. High-quality specs are kept and used to fine-tune the model to generate even better specs in the next round.
  3. Self-Evolving Proof Synthesis: The system then attempts to write the actual proofs. It generates proof annotations and feeds them to Verus. Because Verus acts as an absolute, mathematically rigorous judge, SAFE can automatically filter out bad proofs and keep the good ones without human intervention. Successful proofs are used to fine-tune an open-source model (like DeepSeekCoder).
  4. Self-Debugging: LLMs frequently fail at writing proofs initially. Instead of discarding incorrect proofs, SAFE saves them. It creates training triplets: [Incorrect Proof] + [Verus Error Message] -> [Eventual Correct Proof]. This teaches the model how to read compiler errors and fix its own mistakes.

Key Insights

  • The Verifier is the Ultimate Oracle: In standard code generation, tests can be flaky or incomplete. In formal verification, the SMT solver (the engine behind Verus) provides an absolute "yes" or "no." This allows the self-evolving loop to run safely without human labeling.
  • Trash into Treasure: The self-debugging mechanism is arguably the most powerful insight. By re-purposing thousands of failed proof attempts into debugging training data, the authors turn the LLM's initial incompetence into a learning feature.
  • "Goldilocks" Specifications: To train a proof generator, specifications do not need to be perfect. They just need to be "reasonably well"—correct enough to be provable, but not so trivially simple that the proof requires no complex logic. SAFE's automated filtering targets this middle ground perfectly.

Results

The authors evaluated SAFE on VerusBench (a human-curated benchmark of 139 Rust files) and CodeNet-Test (a massive synthetic benchmark of 1,435 diverse tasks).

Performance comparison of SAFE against baseline models on VerusBench and CodeNet-Test.
  • Massive Accuracy Leap: On VerusBench, SAFE (fine-tuning DeepSeekCoder-33B) achieved 52.52% accuracy (@2 with self-debugging). In contrast, a heavily prompted GPT-4o only managed 14.39%.
  • High Ceiling with Sampling: When allowed to sample 10 initial proofs and attempt 100 debugs (Accuracy@100), SAFE's accuracy on VerusBench climbed to an impressive 70.50%.
  • Superior Generalization: On the larger CodeNet-Test benchmark, GPT-4o's prompt-based approach completely collapsed (0.70% accuracy). SAFE maintained a robust 48.43%, proving it learned the mechanics of formal verification rather than just memorizing prompt instructions.

Limitations and Future Work

While SAFE represents a major leap forward, challenges remain. The framework currently focuses on small, single-function programs; scaling to real-world Rust projects with complex cross-file dependencies will require expanding the LLM's context window and reasoning capabilities. Additionally, the self-debugging model currently learns to replace the entire proof based on an error, whereas future iterations could benefit from fine-grained, line-specific edits. Finally, if a specific, advanced Verus feature is never successfully synthesized during the initial bootstrapping phase, the final fine-tuned model will remain unaware of it.

Summary updated

BibTeX
@inproceedings{chen2025automated,
  author = {Tianyu Chen and Shuai Lu and Shan Lu and Yeyun Gong and Chenyuan Yang and Xuheng Li and Md Rakib Hossain Misu and Hao Yu and Nan Duan and Peng CHENG and Fan Yang and Shuvendu K Lahiri and Tao Xie and Lidong Zhou},
  title = {{Automated Proof Generation for Rust Code via Self-Evolution}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=2NqssmiXLu},
}
Figure