paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Coq Coq correct! verification of type checking and erasure for Coq, in Coq

Coq Coq correct! 在 Coq 中验证 Coq 的类型检查与擦除
POPL 4(POPL)2019匹配度 2/10 · 论文属于形式化验证与类型系统方向,验证 Coq 内核类型检查器与擦除,虽与形式化验证相关,但用户关注的是 LLM/Agent 与静态分析/形式化验证的交叉,以及浮点或贝叶斯程序分析,本文不涉及 LLM/Agent、静态分析或这些交叉方向。引用 66 inbox
Matthieu Sozeau, Simon Boulier, Yannick Forster, Nicolas Tabareau, Théo Winterhalter
crossref: 2026-09-10

AI 速览

一句话:在 Coq 中形式化验证 Coq 内核的类型检查器与类型/证明擦除,将可信代码基缩小为可信理论基。

Coq 的内核类型检查器实现复杂、依赖隐式不变量,平均每年出现关键 bug;提取中的类型与证明擦除也很微妙。本文基于 MetaCoq,对作为 Coq 基础的 PCUIC 类型关系给出形式规约,实现相对高效且可靠的类型检查器,并在 Coq 中证明其相对于该规约与部分元理论公理的正确性。由于哥德尔不完备定理,无法在 Coq 内证明规约本身的完全正确性,因此该方法将可信代码基(TCB)转为可信理论基(TTB)。作者还验证了类型与证明擦除步骤,从而支持安全类型检查器的经验证提取。这是首个针对 Coq 内核(不含模块系统与模板多态)的经验证类型检查器实现。

问题
Coq 内核类型检查器的实现正确性不清晰,代码依赖隐式不变量,平均每年出现关键 bug;extraction 的类型与证明擦除也微妙。
方法
基于 MetaCoq,对 PCUIC 类型关系进行形式规约,实现相对高效且可靠的类型检查器,并在 Coq 中证明其相对于规约和部分元理论公理的正确性;同时验证类型与证明擦除。
评估
机器化证明覆盖不含模块系统与模板多态的 Coq 内核,在假设规约正确的前提下把 TCB 缩小为 TTB,并支持经验证的安全类型检查器提取。
原文摘要(Abstract)

Coq is built around a well-delimited kernel that perfoms typechecking for definitions in a variant of the Calculus of Inductive Constructions (CIC). Although the metatheory of CIC is very stable and reliable, the correctness of its implementation in Coq is less clear. Indeed, implementing an efficient type checker for CIC is a rather complex task, and many parts of the code rely on implicit invariants which can easily be broken by further evolution of the code. Therefore, on average, one critical bug has been found every year in Coq. This paper presents the first implementation of a type checker for the kernel of Coq (without the module system and template polymorphism), which is proven correct in Coq with respect to its formal specification and axiomatisation of part of its metatheory. Note that because of Gödel's incompleteness theorem, there is no hope to prove completely the correctness of the specification of Coq inside Coq (in particular strong normalisation or canonicity), but it is possible to prove the correctness of the implementation assuming the correctness of the specification, thus moving from a trusted code base (TCB) to a trusted theory base (TTB) paradigm. Our work is based on the MetaCoq project which provides metaprogramming facilities to work with terms and declarations at the level of this kernel. Our type checker is based on the specification of the typing relation of the Polymorphic, Cumulative Calculus of Inductive Constructions (PCUIC) at the basis of Coq and the verification of a relatively efficient and sound type-checker for it. In addition to the kernel implementation, an essential feature of Coq is the so-called extraction: the production of executable code in functional languages from Coq definitions. We present a verified version of this subtle type-and-proof erasure step, therefore enabling the verified extraction of a safe type-checker for Coq.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot510,
  title = {Coq Coq correct! verification of type checking and erasure for Coq, in Coq},
  author = {Matthieu Sozeau and Simon Boulier and Yannick Forster and Nicolas Tabareau and Théo Winterhalter},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {4},
  number = {POPL},
  year = {2019},
  doi = {10.1145/3371076}
}