arXiv:2611.01743cs.SENov 2026

Manuscript Offprint

arXiv:2611.01743

VeriBase: Automated Construction of Theorem Libraries for Software Verification

Zihao Zhang, Zenan Li, Taolue Chen, Zhe Zhou, Tao Xie, Yuan Yao

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ZIHAO ZHANG, Nanjing University, China

ZENAN LI, Nanjing University, China

TAOLUE CHEN, Birkbeck, University of London, United Kingdom

ZHE ZHOU, Peking University, China

TAO XIE, Peking University, China and Fudan University, China

YUAN YAO, Nanjing University, China

Software verification is typically more challenging than coding. Software developers routinely build on mature libraries and APIs, but turning successful verification solutions into reusable libraries still requires substantial expert effort. In this paper, we propose VERiBASE, a framework for automatically constructing software-verification libraries by jointly generalizing code and its associated theorems from successful verification solutions. The key challenge is to generalize implementations together with the theorem statements and proofs that depend on these implementations, and reconcile overlapping components across verification tasks. To this end, VERiBASE treats code and its associated theorems as declaration families, and designs a three-phase pipeline, which proves seed tasks, generalizes code and associated theorems, and harvests the resulting families into shared interfaces. VERiBASE updates dependent declarations as interface change and uses Lean to check the resulting code and proofs. We evaluate VERiBASE across four benchmarks with three backend LLMs. The results show that the general-purpose library built from independent 4,191 programs increases the average task success rate by up to 17.0% and meanwhile reduces the proof completion time by up to 21.4%. When VERiBASE constructs a benchmark-specific library, further improvement can be observed.

CCS Concepts: • Software and its engineering → Formal software verification.

Additional Key Words and Phrases: formal verification, theorem libraries, large language models, Lean

1 Introduction

As coding tools and development practices based on a large language model (LLM)—such as vibe coding—gain widespread adoption, more software is being generated or modified by LLMs. While this trend can substantially increase software development productivity, it also amplifies a longstanding challenge of assuring that increasingly large volumes of software behave correctly. LLM-generated code may appear plausible and pass available tests while still containing subtle bugs. Testing remains essential, but it alone generally cannot establish correctness across all possible inputs and execution paths.

Formal verification offers a complementary approach to software quality assurance, providing rigorous guarantees about program behavior by expressing program specifications in formal languages and using machine-checked proofs to establish that programs satisfy the specifications. Interactive theorem provers (ITPs) such as Lean, Rocq (formerly Coq), and Isabelle provide environments for constructing and checking proofs of program correctness. Long before the recent rise of LLM-based code generation, ITPs had been successfully applied to high-assurance software, including seL4 [16], an operating-system kernel formally verified in Isabelle, and CompCert [20], a C compiler formally verified in Rocq.

Authors' Contact Information: Zihao Zhang, zihaozhang@smail.nju.edu.cn, Nanjing University, Nanjing, China; Zenan Li, lizn@smail.nju.edu.cn, Nanjing University, Nanjing, China; Taolue Chen, t.chen@bbk.ac.uk, Birkbeck, University of London, London, United Kingdom; Zhe Zhou, zhouzhe956@pku.edu.cn, Peking University, Beijing, China; Tao Xie, taoxie@pku.edu.cn, Peking University, Beijing, China and Fudan University, Shanghai, China; Yuan Yao, y.yao@nju.edu.cn, Nanjing University, Nanjing, China.

// -- Merge two sorted lists into one sorted List. --
def mergeSorted {a : Type} [LinearOrder a] :
    List a → List a → List a
    | [], 1 => 1
    | 1, [] => 1
    | (h1 :: t1), (h2 :: t2) =>
        if h1 ≤ h2 then
            h1 :: mergeSorted t1 (h2 :: t2)
        else
            h2 :: mergeSorted (h1 :: t1) t2
theorem mem_mergeSorted
    (h : x ∈ mergeSorted 11 12) :
    x ∈ 11 ∨ x ∈ 12

theorem mergeSorted_all_ge
    (h1 : ∀ x ∈ 11, a ≤ x)
    (h2 : ∀ x ∈ 12, a ≤ x) :
    ∀ x ∈ mergeSorted 11 12, a ≤ x

theorem mergeSorted_sorted
    (h1 : List.Sorted (· ≤ ·) 11)
    (h2 : List.Sorted (· ≤ ·) 12) :
    List.Sorted (· ≤ ·) (mergeSorted 11 12)

Fig. 1. An example of a code snippet and its surrounding theorems. The three theorems (i.e., mem_mergeSorted, mergeSorted_all_ge, and mergeSorted_sorted) are all stated over mergeSorted.

However, proof development is often substantially more expensive than software development for two main reasons: the complexity of verification tasks and the limited infrastructure for proof reuse. First, verification tasks are intrinsically demanding: implementing a program requires specifying how to perform a computation, whereas verifying the program additionally requires establishing that the implementation satisfies its specification across all relevant executions. Consequently, the proof artifact can be considerably larger than the code that the proof artifact verifies. For instance, the seL4 microkernel verification required over 200,000 lines of Isabelle proof scripts to verify about 7,500 lines of C code [16]. Recent advances in LLM-based formal reasoning, including neuro-symbolic proof search [14], proof planning [38], and hierarchical proof search [21], among others [29, 33, 36], have improved the automation of proof development, making software verification increasingly practical. Nevertheless, generating proofs remains substantially more costly than generating code.

Second, proof reuse has limited infrastructure, with library construction and maintenance relying heavily on expert effort. Modern code development benefits from a mature ecosystem of reusable libraries and APIs, such as the C++ Standard Library and Python's standard library, reducing the need to implement common functionality from scratch. In contrast, theorem libraries for software verification remain comparatively scarce [3, 17]. Successful verification efforts do not automatically translate into reusable libraries: experts must identify reusable functionality, design general code interfaces and associated theorems, and integrate these declarations with existing libraries. This work requires expertise beyond completing an individual verification task and must be repeated as new library functionality is needed.

These limitations motivate a question: can we automatically turn successful software verification solutions into reusable theorem libraries, reducing the manual effort of library construction and allowing future tasks to benefit from previous verification work? Automating this process presents two main challenges. First, code and theorems must be generalized together. Successful solutions often contain task-specific implementations; generalizing these implementations requires adapting dependent theorem statements and proofs. For example, the theorems in Fig. 1 refer to mergeSorted; changing its interface requires updating the theorems and their uses. Second, overlapping components must be integrated across tasks. Declarations from different solutions must be reconciled into shared interfaces with consistent dependencies, rather than merely collected into a library.

Our work. To address these challenges, we propose VERIBASE, a framework for automatically constructing theorem libraries from verification tasks expressed in Lean. It treats code and its associated theorems as a declaration family. Its code-first, theorems-second principle makes interface changes explicit: each operation first handles the code and then adapts the dependent theorem statements and proofs. The theorem prover (e.g., Lean) checks the resulting code and proofs. VERiBASE constructs libraries in three phases. Proving produces successful solutions through multiple rounds of task solving. Generalization extracts computational components and intermediate proof facts, generalizes their interfaces, and updates dependent declarations. Harvesting integrates candidates across tasks by adding new functionality and properties, skipping covered candidates, and merging overlapping interfaces while updating affected declarations and imports.

We evaluate the effectiveness of the libraries constructed by VERiBASE in improving task success rates and reducing completion time in Lean [23], with four benchmarks and three backend LLMs. On Verina [37], FVAPPS [9], and VeriContest [32], the general library, constructed from tasks outside these benchmarks, improves the average task success rate from 63.0% to 73.0% and reduces average completion time by 13.2%. These results demonstrate that the constructed library serves as a general-purpose library for software verification across benchmarks. When additional tasks from the target benchmark's domain are available, VERiBASE can construct a benchmark-specific library from these tasks. Combining the general and benchmark-specific libraries further increases the average task success rate to 78.5% and reduces average completion time by 27.9% relative to the no-library baseline. On the repository-scale benchmark VeriSoftBench [34], after removing human-developed supporting theorems (which serve a role analogous to our constructed library), our constructed library improves the average task success rate across three backend LLMs from 56.3% to 77.0%. This performance is close to that achieved with the original supporting theorems (e.g., with GLM 5.2, VERiBASE library achieves 81.0% success rate versus 84.0% with the original supporting theorems), suggesting comparable quality between automatic and human-developed libraries for repository-level verification.

In summary, this paper makes the following main contributions.

  • Automated construction of code and theorem libraries. We propose VERiBASE, a framework for jointly generalizing implementations and their associated theorems from successful verification solutions, updating dependent declarations, and consolidating overlapping families across tasks into reusable interfaces.

  • New Lean 4 libraries for software verification. We construct a general library containing 1,609 code declarations and 3,239 theorems, together with benchmark-specific libraries that provide additional code and theorems for their task distributions and repositories.

  • An empirical evaluation of downstream reuse. We evaluate the libraries across four benchmarks and three backend LLMs. Comparisons on VeriContest with raw-solution retrieval and ablated variants examine the benefits of retaining code with its associated theorems, generalization, and library integration.

References (16)