MirrorShard: Proof by Computational Reflection with Verified Hints

Gregory Malecha, Adam Chlipala, Thomas Braibant, Patrick Hulin, Edward Z. YangarXiv 2013

Abstract

MirrorShard is a framework for the Coq proof assistant designed to bridge the gap between high-speed "proof by reflection" and the extensible needs of modern program verification. By replacing massive, tactic-generated proof scripts with verified-correct procedures and a modular system of "hints," MirrorShard achieves dramatic performance improvements. This paper details the architecture of MirrorShard, its handling of extensible syntax, and the performance optimizations that allow it to scale to complex verification tasks.

Introduction

Formal verification—the process of mathematically proving that software adheres to its specification—is often hindered by a fundamental trade-off between trust and automation. In proof assistants like Coq, traditional "tactic-based" automation (using the Ltac language) is highly flexible but notoriously slow. These tactics generate large, primitive proof terms that the Coq kernel must validate step-by-step, a process that can take hours for large-scale systems.

An alternative approach is Proof by Reflection. In this paradigm, developers write a prover as a function within Coq's logic (Gallina), prove its soundness once, and then execute it as a program. While extremely fast, reflective provers are typically "closed" systems; they cannot easily be extended to reason about new user-defined data structures without modifying the core prover. MirrorShard addresses this "extensibility gap," providing a reflective framework that can be extended with domain-specific knowledge through a modular hint system without sacrificing performance or soundness.

Methods and Architecture

MirrorShard introduces several technical innovations to make reflection both extensible and efficient. Central to its design is a representation of Coq terms as a data structure that the reflective prover can manipulate, including support for unification variables.

The Hint Architecture

The framework utilizes three primary types of modular hints to "teach" the prover about new domains:

  1. Refinement Hints: These guide the prover in unfolding abstract predicates, such as identifying a memory region as a linked list.
  2. Base Theory Provers: Verified Gallina functions designed to handle specific logical domains, such as linear arithmetic.
  3. Memory Evaluators: Specialized functions that understand heap operations within the context of separation logic.
The MirrorShard proof search process using modular extension points.

As shown in Figure 1, the proof process involves a sequence of forward refinement, symbolic evaluation, and backward refinement. Extension points allow the prover to call out to specific hints to resolve goals or prove side-conditions via a base theorem prover.

OCaml Reification

To bridge the gap between standard Coq goals and the internal reflective format, MirrorShard utilizes a custom OCaml plugin for "reification." By bypassing Coq's standard tactic language (Ltac), which re-typechecks every intermediate step in a quadratic-time process, the OCaml plugin achieves a massive 88x speedup in preparing goals for the reflective engine.

Key Insights and Performance

A significant finding during the development of MirrorShard was the impact of the "Dependent Type Tax." While using highly dependent types can guarantee well-typedness during computation, it often forces Coq to spend excessive time reducing complex proof terms embedded within those types.

Performance impact of term representation on cancellation tasks.

As illustrated in Figure 2, moving from a dependent to a non-dependent term representation leads to a dramatic reduction in both verification and checking time. MirrorShard adopts a strategy of using simpler types for computation and proving soundness "after the fact," which proves to be significantly more efficient.

Evaluation

MirrorShard was evaluated across several classic data structure and systems programming challenges, including:

  • LinkedList: Operations such as reverse and length.
  • Malloc: A verified memory allocator.
  • ListSet & TreeSet: Implementations of finite sets.
  • Queue & Memoize: Higher-order functions and FIFO structures.

In microbenchmarks involving 32 conjuncts, MirrorShard completed tasks in under a second that caused traditional tactic-based systems to time out. Furthermore, the "annotation burden"—the ratio of proof code to program code—remained competitive with or better than existing non-reflective systems, typically ranging from 1.0 to 5.2 lines of proof per line of code.

Conclusion and Future Work

MirrorShard demonstrates that computational reflection can be made extensible and modular. By shifting the heavy lifting of proof search to verified Gallina functions and optimizing the reification process, it provides a path toward faster, more scalable formal verification.

Future work aims to address the remaining "Ltac glue" problem—where non-reflective preparation code still accounts for two-thirds of total verification time. Additionally, expanding the library of verified base theory provers will further reduce the need to "ping-pong" goals back to standard Coq tactics for side-condition resolution.

Summary updated

BibTeX
@misc{malecha2013mirrorshard,
  author = {Gregory Malecha and Adam Chlipala and Thomas Braibant and Patrick Hulin and Edward Z. Yang},
  title = {{MirrorShard: Proof by Computational Reflection with Verified Hints}},
  year = {2013},
  eprint = {1305.6543},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1305.6543},
}
Figure