skip to main content
research-article
Open access

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

Published: 20 December 2019 Publication History

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.

Supplementary Material

WEBM File (a8-sozeau.webm)

References

[1]
Martin Abadi, Luca Cardelli, P-L Curien, and J-J Lévy. 1991. Explicit substitutions. Journal of functional programming 1, 4 (1991), 375–416.
[2]
Andreas Abel, Joakim Öhman, and Andrea Vezzosi. 2018. Decidability of conversion for type theory in type theory. PACMPL 2, POPL (2018), 23:1–23:29.
[3]
Andreas Abel, Brigitte Pientka, David Thibodeau, and Anton Setzer. 2013. Copatterns: programming infinite structures by observations. In The 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’13, Rome, Italy - January 23 - 25, 2013, Roberto Giacobazzi and Radhia Cousot (Eds.). ACM, 27–38.
[4]
Abhishek Anand, Andrew Appel, Greg Morrisett, Zoe Paraskevopoulou, Randy Pollack, Olivier Savary Belanger, Matthieu Sozeau, and Matthew Weaver. 2017. CertiCoq: A verified compiler for Coq. In CoqPL. Paris, France. http://conf.researchr. org/event/CoqPL-2017/main-certicoq-a-verified-compiler-for-coq
[5]
Abhishek Anand, Simon Boulier, Cyril Cohen, Matthieu Sozeau, and Nicolas Tabareau. 2018. Towards Certified MetaProgramming with Typed Template-Coq. In ITP 2018 (Lecture Notes in Computer Science), Jeremy Avigad and Assia Mahboubi (Eds.), Vol. 10895. Springer, 20–39.
[6]
Bruno Barras. 1999. Auto-validation d’un système de preuves avec familles inductives. Thèse de Doctorat. Université Paris 7. http://pauillac.inria.fr/~barras/publi/these_barras.ps.gz
[7]
Bruno Barras and Bruno Bernardo. 2008. The Implicit Calculus of Constructions as a Programming Language with Dependent Types. In FoSSaCS (Lecture Notes in Computer Science), Roberto M. Amadio (Ed.), Vol. 4962. Springer, 365–379.
[8]
Michael A. Bender, Jeremy T. Fineman, Seth Gilbert, and Robert E. Tarjan. 2015. A New Approach to Incremental Cycle Detection and Related Problems. ACM Trans. Algorithms 12, 2, Article 14 (Dec. 2015), 22 pages.
[9]
Thierry Coquand and Gérard Huet. 1988. The Calculus of Constructions. Information and Computation 76, 2–3 (February/-March 1988), 95–120.
[10]
Yannick Forster and Fabian Kunze. 2019. A certifying extraction with time bounds from Coq to call-by-value λ-calculus. In Tenth International Conference on Interactive Theorem Proving. Springer.
[11]
Gallium, Marelle, CEDRIC, and PPS. 2008. The CompCert project. Compilers You Can Formally Trust. http://compcert. inria.fr/index.html
[12]
Gaëtan Gilbert, Jesper Cockx, Matthieu Sozeau, and Nicolas Tabareau. 2019. Definitional Proof-Irrelevance without K. In 46th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2019) (POPL). Lisbon, Portugal. https://hal.inria.fr/hal-01859964
[13]
Carlos Eduardo Giménez. 1996. Un calcul de constructions infinies et son application à la vérification de systèmes communicants. Ph.D. Dissertation. Ecole Normale Supérieure de Lyon. ftp://ftp.inria.fr/INRIA/LogiCal/Eduardo.Gimenez/thesis.ps.gz
[14]
Stéphane Glondu. 2012. Vers une certification de l’extraction de Coq. Ph.D. Dissertation. Université Paris Diderot.
[15]
Armaël Guéneau, Jacques-Henri Jourdan, Arthur Charguéraud, and François Pottier. 2019. Formal Proof and Analysis of an Incremental Cycle Detection Algorithm. In ITP 2019 - 10th Conference on Interactive Theorem Proving. Portland, United States. https://hal.inria.fr/hal-02167236
[16]
Lars Hupel and Tobias Nipkow. 2018. A verified compiler from Isabelle/HOL to CakeML. In European Symposium on Programming. Springer, 999–1026.
[17]
Pierre Letouzey. 2002. A New Extraction for Coq. In TYPES’02 (Lecture Notes in Computer Science), Herman Geuvers and Freek Wiedijk (Eds.), Vol. 2646. Springer, 200–219.
[18]
Pierre Letouzey. 2004. Programmation fonctionnelle certifiée: l’extraction de programmes dans l’assistant Coq. Thèse de Doctorat. Université Paris-Sud. http://www.pps.jussieu.fr/~letouzey/download/these_letouzey.pdf
[19]
Per Martin-Löf. 1998. An intuitionistic theory of types. In Twenty-five years of constructive type theory (Venice, 1995), Giovanni Sambin and Jan M. Smith (Eds.). Oxford Logic Guides, Vol. 36. Oxford University Press, 127–172.
[20]
Conor McBride and James McKinna. 2004. The view from the left. J. Funct. Program. 14, 1 (2004), 69–111.
[21]
Eric Mullen, Stuart Pernsteiner, James R. Wilcox, Zachary Tatlock, and Dan Grossman. 2018. Œuf: minimizing the Coq extraction TCB. In Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2018, Los Angeles, CA, USA, January 8-9, 2018, June Andronick and Amy P. Felty (Eds.). ACM, 172–185.
[22]
Magnus O Myreen and Scott Owens. 2014. Proof-producing translation of higher-order logic into pure and stateful ML. Journal of Functional Programming 24, 2-3 (2014), 284–315.
[23]
Pierre-Marie Pédrot and Nicolas Tabareau. 2017. An effectful way to eliminate addiction to dependence. In 32nd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2017, Reykjavik, Iceland, June 20-23, 2017. IEEE Computer Society, 1–12.
[24]
Andreas Rossberg, Claudio V. Russo, and Derek Dreyer. 2014. F-ing modules. J. Funct. Program. 24, 5 (2014), 529–607.
[25]
Steven Schäfer, Tobias Tebbi, and Gert Smolka. 2015. Autosubst: Reasoning with de Bruijn Terms and Parallel Substitutions. In Interactive Theorem Proving - 6th International Conference, ITP 2015, Nanjing, China, August 24-27, 2015, Proceedings (Lecture Notes in Computer Science), Christian Urban and Xingyuan Zhang (Eds.), Vol. 9236. Springer, 359–374.
[26]
Gert Smolka. 2015. Confluence and Normalization in Reduction Systems. (2015). https://www.ps.uni-saarland.de/courses/ sem-ws15/ars.pdf Lecture Notes.
[27]
Matthieu Sozeau, Abhishek Anand, Simon Boulier, Cyril Cohen, Yannick Forster, Fabian Kunze, Gregory Malecha, Nicolas Tabareau, and Théo Winterhalter. 2019. The MetaCoq Project. (June 2019). https://hal.inria.fr/hal-02167423 (submitted).
[28]
Matthieu Sozeau and Cyprien Mangin. 2019. Equations Reloaded. PACMPL 3, ICFP (August 2019), 86–115.
[29]
Matthieu Sozeau and Nicolas Tabareau. 2014. Universe Polymorphism in Coq. In Interactive Theorem Proving - 5th International Conference, ITP 2014, Held as Part of the Vienna Summer of Logic, VSL 2014, Vienna, Austria, July 14-17, 2014. Proceedings (Lecture Notes in Computer Science), Gerwin Klein and Ruben Gamboa (Eds.), Vol. 8558. Springer, 499–514.
[30]
Pierre-Yves Strub, Nikhil Swamy, Cédric Fournet, and Juan Chen. 2012. Self-certification: Bootstrapping certified typecheckers in F* with Coq. In 39th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages - POPL’12. Philadelphia, United States. https://hal.inria.fr/inria-00628775
[31]
Masako Takahashi. 1989. Parallel reductions in λ-calculus. Journal of Symbolic Computation 7, 2 (1989), 113–123.
[32]
The Coq Development Team. 2019. The Coq Proof Assistant, version 8.9.0.
[33]
Amin Timany and Matthieu Sozeau. 2017. Consistency of the Predicative Calculus of Cumulative Inductive Constructions (pCuIC). Research Report RR-9105. KU Leuven, Belgium ; Inria Paris. 30 pages. https://hal.inria.fr/hal-01615123

Cited By

View all
  • (2024)Embedding Differential Dynamic Logic in PVSElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.402.7402(43-62)Online publication date: 23-Apr-2024
  • (2024)Dependent Ghosts Have a Reflection for FreeProceedings of the ACM on Programming Languages10.1145/36746478:ICFP(630-658)Online publication date: 15-Aug-2024
  • (2024)Gradual Indexed Inductive TypesProceedings of the ACM on Programming Languages10.1145/36746448:ICFP(544-572)Online publication date: 15-Aug-2024
  • Show More Cited By

Index Terms

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

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 4, Issue POPL
    January 2020
    1984 pages
    EISSN:2475-1421
    DOI:10.1145/3377388
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution-NonCommercial International 4.0 License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 20 December 2019
    Published in PACMPL Volume 4, Issue POPL

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. certification
    2. proof assistants
    3. type checker

    Qualifiers

    • Research-article

    Funding Sources

    • erc

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)357
    • Downloads (Last 6 weeks)37
    Reflects downloads up to 21 Sep 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Embedding Differential Dynamic Logic in PVSElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.402.7402(43-62)Online publication date: 23-Apr-2024
    • (2024)Dependent Ghosts Have a Reflection for FreeProceedings of the ACM on Programming Languages10.1145/36746478:ICFP(630-658)Online publication date: 15-Aug-2024
    • (2024)Gradual Indexed Inductive TypesProceedings of the ACM on Programming Languages10.1145/36746448:ICFP(544-572)Online publication date: 15-Aug-2024
    • (2024)Verified Extraction from Coq to OCamlProceedings of the ACM on Programming Languages10.1145/36563798:PLDI(52-75)Online publication date: 20-Jun-2024
    • (2024)Securing Verified IO Programs Against Unverified Code in F*Proceedings of the ACM on Programming Languages10.1145/36329168:POPL(2226-2259)Online publication date: 5-Jan-2024
    • (2024)Mechanizing Refinement TypesProceedings of the ACM on Programming Languages10.1145/36329128:POPL(2099-2128)Online publication date: 5-Jan-2024
    • (2024)Towards a Scalable Proof Engine: A Performant Prototype Rewriting Primitive for CoqJournal of Automated Reasoning10.1007/s10817-024-09705-668:3Online publication date: 14-Aug-2024
    • (2024)End-to-End Mechanized Proof of a JIT-Accelerated eBPF Virtual Machine for IoTComputer Aided Verification10.1007/978-3-031-65627-9_16(325-347)Online publication date: 24-Jul-2024
    • (2023)Engineering a Formally Verified Automated Bug FinderProceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3611643.3616290(1165-1176)Online publication date: 30-Nov-2023
    • (2023)Formalising Decentralised Exchanges in CoqProceedings of the 12th ACM SIGPLAN International Conference on Certified Programs and Proofs10.1145/3573105.3575685(290-302)Online publication date: 11-Jan-2023
    • Show More Cited By

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media