Automatic Test-Case Reduction in Proof Assistants: A Case Study in Coq

Jason Gross, Théo Zimmermann, Miraya Poddar-Agrawal, Adam Chlipala · OpenReview

Abstract

As the adoption of proof assistants increases, there is a growing need for efficiency in identifying and fixing compatibility issues arising from software evolution. We present the Coq Bug Minimizer, a tool designed to automatically transform large, failing Coq projects into minimal, standalone test cases. Integrated with Coq’s continuous integration (CI) pipeline, the tool leverages specific insights into the structure of proof assistants—such as linear processing and proof irrelevance—to reduce the manual overhead of debugging. Our evaluation on over 150 real-world CI failures shows that the tool successfully reduces failures 75% of the time, producing standalone files that are significantly smaller and faster to compile than the original developments.

Introduction

Proof assistants like Coq are foundational for formal verification, yet they are complex software projects that evolve rapidly. To maintain stability, Coq developers utilize "reverse CI," testing proposed changes against a massive suite of community-maintained projects. When a change in Coq breaks an external project, developers are often left with a massive codebase they did not write, requiring hours to compile and complex environment setups. Finding the specific line of code that triggered the regression is a "needle in a haystack" problem.

Traditional test-case reduction tools, such as those using delta debugging for languages like C, struggle with Coq due to its dependent types, metaprogramming facilities (Ltac), and complex global state. The Coq Bug Minimizer addresses these challenges by employing strategies tailored to the unique constraints of proof assistants.

Methodology

The authors developed a specialized minimization strategy that capitalizes on the semantic structure of Coq files.

Linear Simplification

Unlike many general-purpose languages, Coq generally forbids forward references. This allows the minimizer to use a "backward-pass" strategy: it deletes everything following the error-generating line and then attempts to remove preceding commands one by one. This top-to-bottom processing makes reduction significantly faster and more predictable than in languages with mutual recursion across files.

Proof Admission

Proof scripts are often the most computationally expensive part of a Coq development. Instead of simply deleting them—which might break subsequent definitions—the tool replaces proof blocks with the Admitted command or the admit tactic. This "trusts" the proof, allowing the tool to focus on the structural definitions and declarations that actually trigger the bug.

Dependency Inlining and Standalone Generation

To eliminate the need for complex build systems, the tool "inlines" dependencies into a single file. This is a complex task involving the resolution of name conflicts (shadowing) and the management of global state (notations and search paths). The tool utilizes Coq’s .glob files to track name resolution and wraps inlined files in modules to isolate their effects, resulting in a portable, standalone test case.

Relaxed Error Matching

A minimized file may not produce the exact same error string as the original (e.g., universe levels might be numbered differently). The authors implemented "fuzzy" matching for error messages to ensure the reduction process does not stall on trivial differences, provided the underlying bug remains the same.

Evaluation and Results

The tool was evaluated using 191 minimization runs across 51 different Pull Requests on the Coq GitHub repository, representing a diverse set of community projects.

Key empirical results include:

  • Success Rate: The tool successfully produced a reduced test case in 75% of the cases it was triggered on.
  • Standalone Quality: 89% of successful reductions resulted in a fully standalone file with no external dependencies.
  • Size Reduction: On average, the final test case was approximately one-third the size of the original relevant code.
  • Speedup: The average reduced test case compiles in just 1.25 seconds, with 75% taking under half a second. This turns a lengthy debugging process into a near real-time experimentation loop.

Discussion and Limitations

Despite its success, the tool faces challenges with Coq's global state. Settings like flags and notations can leak out of modules, making perfect linearization difficult. Currently, the tool uses partial workarounds for these issues. Additionally, in about 2% of cases, the minimizer encountered infinite loops or CI timeouts.

Future work may involve "structural awareness"—removing entire modules or sections at once—and integration with incremental compilation to further accelerate the reduction process.

Conclusion

The Coq Bug Minimizer significantly reduces the manual effort required to diagnose regressions in the Coq proof assistant. By automating the creation of minimal, standalone examples, it enables developers to fix bugs faster and maintain a more stable ecosystem. The insights regarding linear simplification and proof admission are expected to generalize to other proof assistants with similar architectures.

Summary updated

BibTeX
@inproceedings{gross2022automatic,
  author = {Jason Gross and Théo Zimmermann and Miraya Poddar-Agrawal and Adam Chlipala},
  title = {{Automatic Test-Case Reduction in Proof Assistants: A Case Study in Coq}},
  booktitle = {ITP},
  year = {2022},
  url = {https://openreview.net/forum?id=S5qJJq0-IP},
}
Figure