FVEL: Interactive Formal Verification Environment with Large Language Models via Theorem Proving

Xiaohan Lin, Qingxing Cao, Yinya Huang, Haiming Wang, Jianqiao Lu, Zhengying Liu, Linqi Song, Xiaodan Liang · DOI

Introduction

As Large Language Models (LLMs) increasingly dominate program synthesis, ensuring the correctness and security of generated code has become a critical challenge. Traditional Formal Verification (FV) methods often rely on rigid symbolic verifiers or labor-intensive hand-crafted rules, which struggle to scale with the complexity of modern software. Conversely, Automated Theorem Proving (ATP) systems like Isabelle and Lean offer rigorous mathematical logic but have historically been disconnected from the practicalities of verifying C code.

This paper introduces FVEL (Formal Verification Environment with LLMs), a framework that bridges this gap by treating code verification as an interactive theorem-proving task. By enabling LLMs to interact with a formal logic engine, FVEL allows models to reason about code correctness within a mathematically sound environment.

The FVEL Environment

The FVEL workflow facilitates a dialogue between the LLM and the Isabelle theorem prover. The process begins with Translation, where C programs are converted into a formal mathematical representation using tools like C-Parser and AutoCorres.

The FVEL Environment workflow, illustrating the translation from C code to Isabelle and the interactive proof loop between the LLM and the prover.

Following translation, the system performs Lemma Generation, where the LLM proposes a mathematical statement (lemma) defining the expected behavior of the code. The core of the framework is the Interactive Proving phase. Using the PISA tool, the LLM attempts to prove the lemma step-by-step. After each proof tactic, the environment provides immediate feedback. If a step fails, the LLM receives error messages from Isabelle, allowing for iterative self-correction—a crucial feature for navigating complex logical proofs where "one-shot" attempts often fail.

The FVELER Dataset

To train and evaluate models within this environment, the authors developed FVELER, a large-scale dataset derived from the seL4 microkernel, a benchmark for high-assurance software. FVELER comprises 758 theories, over 29,000 lemmas, and more than 200,000 proof steps.

A defining characteristic of FVELER is its Deep Dependency structure. Unlike simplified verification benchmarks, FVELER reflects the complexity of real-world systems software. Many lemmas require an understanding of over 150 layers of prior definitions and proofs, presenting a significant challenge for long-range logical consistency in LLMs.

Distribution of dependency depth for theories and lemmas in the FVELER dataset, highlighting the extreme complexity of the verification tasks.

Experimental Results

The researchers fine-tuned models such as Llama-3 and Mistral using Low-Rank Adaptation (LoRA) on the FVELER dataset. Evaluation on industry-standard benchmarks like SV-COMP and Code2Inv demonstrated significant performance improvements:

  • Increased Success Rates: A fine-tuned Llama3-8B solved 17.39% more problems in the SV-COMP benchmark, increasing its success count from 69 to 81 cases. Mistral-7B showed a similar 12% improvement.
  • Reduced Logical Errors: Fine-tuning significantly decreased the frequency of "proof errors," indicating that the models became more adept at following the formal logic required by the Isabelle environment.
  • Competitive Performance: In specific categories, the fine-tuned LLMs matched or outperformed specialized symbolic solvers, suggesting that LLM-based reasoning can effectively augment traditional verification tools.

Conclusion and Future Directions

FVEL demonstrates that treating code verification as a translation into formal logic is a viable path for scaling software assurance. While currently focused on C, future work aims to expand support to languages like Rust or Java. Key challenges remain, particularly the "Specification Gap"—ensuring that the generated lemmas accurately reflect human intent—and the scarcity of high-quality formal verification data compared to general-purpose code. Nonetheless, FVEL represents a major step toward autonomous, mathematically-verified software development.

Summary updated

BibTeX
@inproceedings{lin2024fvel,
  author = {Xiaohan Lin and Qingxing Cao and Yinya Huang and Haiming Wang and Jianqiao Lu and Zhengying Liu and Linqi Song and Xiaodan Liang},
  title = {{FVEL: Interactive Formal Verification Environment with Large Language Models via Theorem Proving}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
}
Figure