Baldur: Whole-Proof Generation and Repair with Large Language Models

Emily First, Markus N. Rabe, Talia Ringer, Yuriy Brun · DOI

Introduction

Formally verifying software—mathematically proving that code adheres to its specifications—represents the "gold standard" for system reliability. However, this process is notoriously labor-intensive. For instance, the proof for the verified C compiler CompCert is approximately three times the length of the compiler's source code. To alleviate this burden, researchers have developed automated formal verification tools, which typically fall into two categories: "hammers" (brute-force heuristics) and "neural theorem provers."

Most neural provers operate through a step-by-step interaction: predicting a single proof step, verifying it with a proof assistant (like Isabelle/HOL), and searching through a vast tree of potential proof paths. This approach is computationally expensive and requires complex engineering to synchronize the model with the proof assistant. Baldur introduces a paradigm shift by treating proof generation as a sequence-to-sequence translation task, generating entire proofs in a single pass.

The Baldur Approach

Baldur leverages Large Language Models (LLMs) to bypass the need for expensive tree searches. The system is built on three primary methodological pillars:

  1. Whole-Proof Generation: Instead of incremental steps, Baldur generates an entire proof block at once. This utilizes the declarative nature of the Isabelle language, which is designed to be human-readable and structured.
  2. Proof Repair: When an initial proof attempt fails, Baldur employs a specialized repair model. This model takes the theorem statement, the failed proof, and the specific error message from the Isabelle proof assistant to generate a corrected version.
  3. In-Context Learning: To mimic how human engineers work, the model is provided with "theory file context"—the definitions and lemmas immediately preceding the theorem in the source file. This allows the model to identify and adapt existing proof patterns.

The underlying architecture utilizes Minerva (8B and 62B parameter versions), transformer-based LLMs pretrained on extensive mathematical and technical corpora.

Experimental Setup

The researchers evaluated Baldur using the PISA dataset, a comprehensive collection of theorems and proofs from the Isabelle/HOL standard library and the Archive of Formal Proofs (AFP). The models were fine-tuned on approximately 183,000 theorems and tested on a benchmark of 6,336 theorems spanning computer science, logic, and mathematics.

Key Insights and Results

State-of-the-Art Performance

Baldur achieved a new state-of-the-art in automated formal verification. When combined with Thor (a leading search-based tool), the ensemble successfully proved 65.7% of the theorems in the benchmark.

The Power of Error Feedback

A critical finding was the high signal value of error messages. The repair model showed a significant performance boost only when provided with the actual error output from the proof assistant. Without this feedback, the model was unable to effectively "fix" its mistakes, indicating that the model is genuinely learning from the compiler's feedback rather than just generating random alternatives.

Efficiency and Scaling

Baldur is significantly more efficient than traditional search-based methods. Generating 64 proof samples with Baldur took approximately 35 seconds on 8 TPUv3 cores, whereas a single search-based attempt by prior tools required 216 seconds—a 6x improvement in computational efficiency. Furthermore, scaling from the 8B to the 62B parameter model yielded consistent improvements, suggesting that the ceiling for LLM-based verification has not yet been reached.

Contextual Awareness

Providing the model with the 50 lines of code preceding a theorem increased the success rate from 40.7% to 47.5%. Qualitative analysis confirmed that the model frequently "copies and adapts" nearby proof structures, effectively leveraging local information to solve new problems.

Discussion and Limitations

While Baldur excels at logical and tool-based proofs, it still faces challenges with complex mathematical proofs that require deep, domain-specific premises. In these areas, traditional "hammers" like Sledgehammer remain superior. This suggests a complementary relationship: Baldur provides rapid, high-level proof generation, while search-based tools handle deep mathematical dependencies.

Future work will focus on integrating generation and repair into more sophisticated iterative search strategies, improving the quality of repair training data, and porting these "whole-proof" techniques to other proof assistants like Coq or Lean, which utilize more procedural proof styles.

Summary updated

BibTeX
@inproceedings{first2023baldur,
  author = {Emily First and Markus N. Rabe and Talia Ringer and Yuriy Brun},
  title = {{Baldur: Whole-Proof Generation and Repair with Large Language Models}},
  booktitle = {ESEC/SIGSOFT FSE},
  year = {2023},
  url = {https://openreview.net/forum?id=sbTHn1nquA},
}
Figure