TL;DR
BRIDGE is a structured prompting and training framework that treats formal program verification as an "artifact alignment" problem. By decomposing the task into three interconnected domains—Code, Specification, and Theorem/Proof—and using functional programming "scaffolds," it improves Lean 4 executable correctness by 1.5× and doubles sample efficiency compared to direct code generation.
What Problem Does This Paper Address?
Large Language Models (LLMs) have become remarkably good at writing Python or Java, but they struggle with formal verification systems like Lean 4. In Lean, it isn't enough for code to just "look right" or pass a few tests; it must be mathematically proven to be correct.
The challenge is that formal verification requires a collection of perfectly synchronized artifacts: the executable code, a formal specification of what the code should do, a theorem statement connecting the two, and a proof script that the Lean kernel can check. Current LLMs often suffer from "semantic drift," where the generated code might pass tests, but the theorem statement is vacuous, or the proof is for a different version of the logic. BRIDGE addresses this by forcing the model to build these artifacts through a unified, domain-guided pipeline.
Methods
The core of the paper is the BRIDGE framework, which breaks the synthesis process into three domains:
- Code Domain: Generates the implementation. Crucially, it uses "scaffolds"—intermediate reasoning steps in functional languages like OCaml or Haskell—to guide the model. Because Lean is a functional language, thinking in terms of recursion and immutable data (functional scaffolding) works much better than thinking in loops (imperative scaffolding).
- Specification Domain: Defines formal constraints, preconditions, and postconditions. This acts as a "semantic anchor" for the other domains.
- Theorem/Proof Domain: Connects the code to the specification and attempts to discharge the proof.
BRIDGE uses an artifact consistency loop. Instead of a one-shot generation, the system checks if the code elaborates (compiles) and passes tests. If it does, it uses that code as an anchor to generate specs and theorems. If a check fails, the system can localize the error to a specific artifact and attempt a repair.
Datasets
The researchers evaluated BRIDGE across several benchmarks:
- BRIDGE Lean Suite: A new benchmark of 178 algorithmic problems derived from programming tasks, each with 100 oracle tests.
- Public Transfer Benchmarks: To prove the method generalizes, they tested it on VERINA (Lean implementation/spec tasks), CLEVER (Lean code synthesis), and DAFNYBENCH (a solver-backed verification pilot).
- Python Evaluation: They also tested the framework on standard Python generation to see if formal specification reasoning helps "normal" coding.
Key Insights and Ideas
- Functional Logic as an Inductive Bias: One of the biggest "aha moments" is that the style of intermediate reasoning matters. Scaffolding the problem in a functional style (OCaml/Haskell) significantly outperformed imperative styles (Python/C++). This is because Lean’s internal logic—specifically its requirements for termination and totality—aligns naturally with functional programming idioms.
- Specifications as Planning Tools: Even when the goal is just to write Python code, asking the model to generate a formal "Design by Contract" specification first improved pass rates by up to 17.5 percentage points. This suggests that formal specs force the model to handle edge cases and invariants it might otherwise ignore.
- Learnability: The authors found that BRIDGE isn't just a prompting trick. By fine-tuning a model (Goedel-Code-Prover-8B) on BRIDGE-style reasoning traces, they achieved a 1.5× higher success rate than code-only fine-tuning. The model actually "learns" the habit of decomposing tasks into proof-friendly structures.
Key Results
- Lean Correctness: BRIDGE improved Lean executable correctness by nearly 1.5× over direct baselines.
- Sample Efficiency: BRIDGE is roughly 2× more sample-efficient, meaning it requires half as many attempts to find a verified solution compared to standard methods.
- SFT Gains: Supervised Fine-Tuning (SFT) on BRIDGE traces improved the VERINA benchmark pass rate from 20.3% to 29.4%.
- Proof Completion: In a proof-only pilot, functional code led to a 41.1% proof completion rate, compared to only 17.5% for code generated via direct prompting.
Limitations and Future Work
While BRIDGE significantly improves the "front end" of verification (getting code that compiles and matches a theorem), it does not solve full formal verification. Many generated proofs still contain "sorry" (placeholders for unproven steps) or prove properties that are weaker than the full natural-language requirement.
The authors note that automatically generating "broad and faithful" semantic specifications remains a major bottleneck—models are still prone to writing specs that are too weak or too narrow. Future work involves closing the loop with automated proof search and testing BRIDGE on larger, multi-module software systems where "artifact drift" is even more common.
Summary updated