๐ Try out synthesis on the web!
(Supported by js_of_ocaml
compilation.)
This repository requires Coq 8.17 or later.
Note that if you install Coq from Ubuntu aptitude packages, you need libcoq-ocaml-dev
in addition to coq
.
Note that in some cases (such as installing Coq via homebrew on Mac), you may also need to install ocaml-findlib
(for ocamlfind
).
The extracted OCaml code for the standalone binaries requires OCaml 4.08 or later.
We suggest downloading the latest version of Coq.
Generation of JSON code via the Makefile also requires jq
.
Alternatively, choose your package-manager to install dependencies:
Package Manager | Command Line Invocation |
---|---|
Aptitude (Ubuntu / Debian) | apt install coq ocaml-findlib libcoq-ocaml-dev jq |
Homebrew (OS X) | brew install coq ocaml-findlib coreutils jq |
Pacman (Archlinux) | pacman -S coq ocaml-findlib ocaml-zarith jq |
You can clone this repository with
git clone --recursive https://github.com/mit-plv/fiat-crypto.git
Git submodules are used for some dependencies. If you did not clone with --recursive
, run
git submodule update --init --recursive
from inside the repository. Then run:
make
You can check out our CI to see how long the build should take; as of the last update to this line in the README, it takes about 1h10m to run make -j2
on Coq 8.11.1.
If you want to build only the command-line binaries used for generating code, you can save a bit of time by making only the standalone-unified-ocaml
target with
make standalone-unified-ocaml
The Coq development builds binary compilers that generate code using some implementation strategy. The parameters (modulus, hardware multiplication input bitwidth, etc.) are specified on the command line of the compiler. The generated C code is written to standard output.
A collection of C files for popular curves can be made with
make c-files
The C files will appear in fiat-c/src/
.
Just the compilers generating these C files can be made with
make standalone-ocaml
or make standalone-haskell
for compiler binaries generated with Haskell, or make standalone
for both the Haskell and OCaml compiler binaries.
The binaries are located in src/ExtractionOcaml/
and src/ExtractionHaskell/
respectively.
There is one compiler binary for all implementation strategies:
fiat_crypto
This binary takes arguments for the strategy:
saturated-solinas
unsaturated-solinas
word-by-word-montgomery
dettman-multiplication
solinas-reduction
base-conversion
Passing no arguments, or passing -h
or --help
(or any other invalid arguments) will result in a usage message being printed. These binaries output C code on stdout.
Here are some examples of ways to invoke the binaries (from the directories that they live in):
# Generate code for 2^255-19
./fiat_crypto unsaturated-solinas '25519' '64' '5' '2^255 - 19' carry_mul carry_square carry_scmul121666 carry add sub opp selectznz to_bytes from_bytes > curve25519_64.c # 1
./fiat_crypto unsaturated-solinas '25519' '32' '10' '2^255 - 19' carry_mul carry_square carry_scmul121666 carry add sub opp selectznz to_bytes from_bytes > curve25519_32.c # 2
# Generate code for NIST-P256 (2^256 - 2^224 + 2^192 + 2^96 - 1)
./fiat_crypto word-by-word-montgomery 'p256' '32' '2^256 - 2^224 + 2^192 + 2^96 - 1' > p256_32.c # 3
./fiat_crypto word-by-word-montgomery 'p256' '64' '2^256 - 2^224 + 2^192 + 2^96 - 1' > p256_64.c # 4
Try out the above on the web ๐1 ๐2 ๐3 ๐4.
You can find more examples in the Makefile
.
Note that for large primes, you may need to increase the stack size to avoid stack overflows. For example:
ulimit -S -s 1048576; ./fiat_crypto word-by-word-montgomery --static gost_512_paramSetB 32 '2^511 + 111'
This sets the stack size to 1 GB (= 1024 MB = 1024 * 1024 KB = 1048576 KB) before running the command. As of the last edit of this line, this command takes about an hour to run, but does in fact complete successfully. Without a sufficiently large stack-size, it instead stack overflows.
Output is supported to the research language bedrock2. The Coq development builds binary compilers that generate code using some implementation strategy. The parameters (modulus, hardware multiplication input bitwidth, etc.) are specified on the command line of the compiler. The generated bedrock2 code is then written to standard output using the bedrock2 C backend.
A collection of bedrock2/C files for popular curves can be made with
make bedrock2-files
The bedrock2/C files will appear in fiat-bedrock2/src/
.
Just the compilers generating these bedrock2/C files can be made with
make standalone-ocaml
or make standalone-haskell
for binaries generated with Haskell, or make standalone
for both the Haskell and OCaml binaries.
The binaries are located in src/ExtractionOcaml/
and src/ExtractionHaskell/
respectively.
There is one compiler binary for all implementation strategies:
bedrock2_fiat_crypto
This binary takes arguments for the strategy:
saturated-solinas
unsaturated-solinas
word-by-word-montgomery
dettman-multiplication
solinas-reduction
base-conversion
Passing no arguments, or passing -h
or --help
(or any other invalid arguments) will result in a usage message being printed. These binaries output bedrock2/C code on stdout.
Here are some examples of ways to invoke the binaries (from the directories that they live in):
# Generate code for 2^255-19
./bedrock2_fiat_crypto unsaturated-solinas --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select '25519' '64' '5' '2^255 - 19' carry_mul carry_square carry_scmul121666 carry add sub opp selectznz to_bytes from_bytes > curve25519_64.c # 1
./bedrock2_fiat_crypto unsaturated-solinas --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select '25519' '32' '10' '2^255 - 19' carry_mul carry_square carry_scmul121666 carry add sub opp selectznz to_bytes from_bytes > curve25519_32.c # 2
# Generate code for NIST-P256 (2^256 - 2^224 + 2^192 + 2^96 - 1)
./bedrock2_fiat_crypto word-by-word-montgomery --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select 'p256' '32' '2^256 - 2^224 + 2^192 + 2^96 - 1' > p256_32.c # 3
./bedrock2_fiat_crypto word-by-word-montgomery --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select 'p256' '64' '2^256 - 2^224 + 2^192 + 2^96 - 1' > p256_64.c # 4
# Generate code for 2^130 - 5
./bedrock2_fiat_crypto unsaturated-solinas --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select 'poly1305' '64' '3' '2^130 - 5' > poly1305_64.c # 5
./bedrock2_fiat_crypto unsaturated-solinas --no-wide-int --widen-carry --widen-bytes --split-multiret --no-select 'poly1305' '32' '5' '2^130 - 5' > poly1305_32.c # 6
Try out the above on the web ๐1 ๐2 ๐3 ๐4 ๐5 ๐6.
You can find more examples in Makefile.examples
.
Fiat-Crypto is distributed under the terms of the MIT License, the Apache License (Version 2.0), and the BSD 1-Clause License; users may pick which license to apply.
See COPYRIGHT
, LICENSE-MIT
, LICENSE-APACHE
, and LICENSE-BSD-1
for details.
- Andres Erbsen, Jade Philipoom, Jason Gross, Robert Sloan, Adam Chlipala. Simple High-Level Code For Cryptographic Arithmetic -- With Proofs, Without Compromises. To Appear in Proceedings of the IEEE Symposium on Security & Privacy 2019 (S&P'19). May 2019.. This paper describes multiple field arithmetic implementations, and an older version of the compilation pipeline (preserved here). It is somewhat space-constrained, so some details are best read about in theses below.
- Jade Philipoom. Correct-by-Construction Finite Field Arithmetic in Coq. MIT Master's Thesis. February 2018. Chapters 3 and 4 contain a detailed walkthrough of the field arithmetic implementations (again, targeting the previous compilation pipeline).
- Andres Erbsen. Crafting Certified Elliptic Curve Cryptography Implementations in Coq. MIT Master's Thesis. June 2017. Section 3 contains a whirlwind introduction to synthesizing field arithmetic code using coq, without assuming Coq skills, but covering a tiny fraction of the overall library. Sections 5 and 6 contain the only write-up on the elliptic-curve library in this repository.
- Jason Gross. Performance Engineering of Proof-Based Software Systems at Scale. MIT Doctoral Thesis. February 2021. Chapters 4 and 5 describe the reflective program transformation framework at the center of the newest compilation pipeline.
- The newest compilation pipeline as a whole does not have a separate document yet, but this README does go over it in some detail.
Fiat Cryptography contains a number of backends; the final step of the pipeline is transforming from straight-line C-like code to expressions in whatever language is being targeted. The Bedrock2 backend comes with proofs that the Bedrock2 AST matches the semantics of our internal AST, but none of the other backends have any proofs about them. While the transformations are not particularly involved, and our proofs ensure that we have picked integer sizes large enough to store values at each operation, there is no verification that the particular integer size casts that we emit are sufficient to ensure that gcc, clang, or whatever compiler is used on the code correctly selects integer sizes for expressions correctly. Note that even the C code printed by the Bedrock2 backend does not have proofs that the conversion to strings is correct.
Hence we provide here a table of the extent to which the various backends are maintained, tested, and proven. A โ๏ธ in "maintainer" means that the Fiat Cryptography maintainers are fully maintaining and testing the backend; โ means maintenance by external contributors. We do not provide any quality guarantees for code generated by the backends.
Backend | Maintainer / Person of Contact | Build Checked by CI | Generated Code Tested | Internal AST Proven Correct |
---|---|---|---|---|
C | โ๏ธ @JasonGross / entire team | โ๏ธ | โ๏ธ (BoringSSL test-suite) | |
Bedrock2/C | โ๏ธ @andres-erbsen / entire team | โ๏ธ | โ๏ธ (BoringSSL test-suite) | โ๏ธ |
Go | โ @mdempsky | โ๏ธ | ||
Java | โ Unmaintained | โ๏ธ | โ Known Buggy #707 | |
JSON | Experimental | โ (only syntax) | ||
Rust | โ | โ๏ธ | โ๏ธ (Dalek Cryptography test-suite) | |
Zig | โ @jedisct1 | โ๏ธ | โ (Zig standard library (generated file here) (main CI here)) |
We weclome new backends (as long as you're willing to maintain them). We hope that the process of contributing a new backend is not too painful, and welcome feedback on how the process could be streamlined. To contribute a new backend, follow the following steps (perhaps using, for example, #936, #660, #638, or #570 as examples):
- Add a new file to
src/Stringification/
for your language, modeled after the existing file of your choice - Run
git add
on your new file and thenmake update-_CoqProject
to have the build system track your file - Update
src/CLI.v
toRequire Import
your file and add your language to the listdefault_supported_languages
so that it can be passed to the binaries as an argument to--lang
- Update the
Makefile
in the following ways:- Consider adding a variable near
CARGO_BUILD
for the build invocation - Add targets to
.PHONY
analogous toc-files
,lite-c-files
,test-c-files
,only-test-c-files
- Add a variables analogous to
C_DIR
,ALL_C_FILES
, andLITE_C_FILES
for your language's generated files - Add targets analogous to
c-files
andlite-c-files
and makegenerated-files
andlite-generated-files
depend on those targets respectively - Add build rules for
ALL_<YOUR-LANGUAGE>_FILES
- Add targets for
test-<your-language>-files
andonly-test-<your-language>-files
; both targets should have the same build rule, buttest-<your-language>-files
should depend on all the generated files of your language, whileonly-test-<your-language>-files
should not have any build rule dependencies. - If you are developing a package, you can look for uses of
COPY_TO_FIAT_RUST
orCOPY_TO_FIAT_GO
to see how license files are copied
- Consider adding a variable near
- Run
make
to generate all the relevant files of your language, and add the generated files to git - Update
.gitignore
to ignore any compiled files generated by the compiler of your language (analogous to.o
and.a
for C) - Create a file in
.github/workflows/
likec.yml
,go.yml
,rust.yml
, etc, to test at least that the generated code compiles.- Optionally, also test the built code against some external project's crypto unit tests
- Update
.gitattributes
to mark your language's generated files astext
and to mark the paths of the generated files aslinguist-generated
so that diffs don't clog up PR displays. - Add your language to the table in preceeding section of the README indicating the status of your backend and marking your GitHub username as the maintainer.
The idea of the synthesis process is demoed in src/Demo.v
.
We strongly recommend reading this before studying the full-scale system.
We have some about elliptic curves, for example:
src/Curves/Edwards/AffineProofs.v
,src/Curves/Edwards/XYZT/Basic.v
,src/Curves/Montgomery/AffineProofs.v
,src/Curves/Montgomery/XZProofs.v
.
The entry point for clients of the PHOAS expressions we use is
Language/API.v
. Refer to comments in that file for an explanation
of the interface; the following text describes how the expressions are
generated, not how to interact with them.
The ordering of files (eliding *Proofs.v
files) is:
Language/*.v
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโ
AbstractInterpretation/*.v MiscCompilerPasses.v Rewriter/*.v PushButtonSynthesis/ReificationCache.v Arithmetic.v
โ โ โ โ โ
Stringification/*.v โ โ โ COperationSpecifications.v
โ โ โ โ โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโฌโโโโโโโโโโโโโโโ โ
BoundsPipeline.v CompilersTestCases.v โ
โ โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
PushButtonSynthesis/*.v
โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโ
CLI.v SlowPrimeSynthesisExamples.v
โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโ
StandaloneHaskellMain.v StandaloneOCamlMain.v
โ โ
ExtractionHaskell.v ExtractionOCaml.v
Within each directory, the dependency graphs (again eliding *Proofs.v
and related files) are:
Within Language/
:
Pre.v โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ IdentifierParameters.v
โ โ
Language.v โโโ IdentifiersBasicLibrary.v โโโโโ IdentifiersBasicGenerate.v โโโ IdentifiersBasicGENERATED.v โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ API.v
โ โ โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
UnderLets.v IdentifiersLibrary.v โโโโโโโโโโโโโ IdentifiersGenerate.v โโโโโโโโ IdentifiersGENERATED.v
โ โ โ
IdentifiersLibraryProofs.v โโโโ IdentifiersGenerateProofs.v โโ IdentifersGENERATEDProofs.v
Within Stringification/
:
Language.v
โ
IR.v
โ
โโโโดโโโโโโโโ
C.v Rust.v
We will come back to the Rewriter/*
files shortly.
The files contain:
-
Arithmetic.v
: All of the high-level field arithmetic stuff -
COperationSpecifications.v
: The specifications for the various operations to be synthesized. TODO: This file should probably be renamed. -
AbstractInterpretation/*.v
: type-code-based ZRange definitions, abstract interpretation of identifiers (which does let-lifting, for historical reasons, and the dependency on UnderLets should probably be removed), defines the passes:- PartialEvaluateWithBounds
- PartialEvaluateWithListInfoFromBounds
- CheckPartialEvaluateWithBounds
-
MiscCompilerPasses.v
: Defines the passes:- EliminateDead (dead code elimination)
- Subst01 (substitute let-binders used 0 or 1 times)
-
Rewriter/*.v
: rewrite rules, rewriting. See below for actual structure of files. Defines the passes:- RewriteNBE
- RewriteArith
- RewriteArithWithCasts
- RewriteStripLiteralCasts
- RewriteToFancy
- RewriteToFancyWithCasts
- PartialEvaluate (which is just a synonym for RewriteNBE)
-
Inside
Language/
:-
Pre.v
: A few definitions which are used in writing out rewrite rules and the interpretations of PHOAS identifiers, e.g.,ident.cast
,ident.eagerly
,Thunked.list_rect
, etc -
Language.v
: Defines parts of the PHOAS basic infrastructure parameterized over base types and identifiers including: . PHOAS . reification . denotation/intepretation . utilities for inverting PHOAS exprs . default/dummy values of PHOAS exprs . default instantiation of generic PHOAS types . Gallina reification of ground terms . Flat/indexed syntax trees, and conversions to and from PHOASDefines the passes: . ToFlat . FromFlat . GeneralizeVar
-
API.v
: Specializes the type of PHOAS expressions to the particular identifiers we're using, and defines convenience notations, tactics, and definitions for some of the specialized versions. -
IdentifierParameters.v
: Defines a couple of definitions determining the identifiers and types used by the language. These are used as input for the generation of identifier definitions. -
IdentifiersBasicLibrary.v
: Defines the package type holding basic identifier definitions. -
IdentifiersBasicGenerate.v
: Defines the tactics that generate all of the identifier-list-specific definitions used by the PHOAS machinery, in addition to defining the tactics that do reification based on the generated package. -
IdentifiersBasicGENERATED.v
: Basically autogenerated file that defines the inductives of base type codes and identifier codes (the first hand-written because it's short; the latter copy-pasted from a tactic that prints out the inductive), and calls the package-generation-tactic fromIdentifiersBasicGenerate.v
. -
UnderLets.v
: the UnderLets monad, a pass that does substitution of var-like things, a pass that inserts let-binders in the next-to-last line of code, substituting away var-like things (this is used to ensure that when we output C code, aliasing the input and the output arrays doesn't cause issues). Defines the passes: . SubstVar . SubstVarLike . SubstVarOrIdent
The following files in
Language/
are used only by the rewriter:-
IdentifiersLibrary.v
: Some definitions about identifiers and pattern identifiers and raw identifiers. Some of these definitions take generated definitions as arguments. Also defines a package record to hold all of the generated definitions. -
IdentifiersGenerate.v
: Tactics to generate definitions about untyped and pattern versions of identifiers for the rewriter. Culminates in a tactic which inhabits the package type defined inIdentifiersLibrary.v
-
IdentifiersLibraryProofs.v
: proofs about definitions in IdentifiersLibrary. Also defines a package to hold generated proofs that require destructing inductives not yet defined in this file. -
IdentifiersGenerateProofs.v
: tactics to prove lemmas to inhabit the package defined inIdentifiersLibraryProofs.v
-
IdentifiersGENERATE.v
: identifiers / inductives and definitions generated by IdentifiersGenerate. -
IdentifiersGENERATEProofs.v
: proofs generated by IdentifiersGenerateProofs, about definitions in IdentifiersGENERATE
-
-
Inside
Stringification/
:-
Language.v
: defines a printer (Show instance) for the PHOAS language, defines some common language-independent utilities for conversion to output code, and defines the spec/API of conversion from PHOAS to code in a language as strings. (Depends onAbstractInterpretation.v
for ZRange utilities.) Defines the passes: . ToString.LinesToString . ToString.ToFunctionLines -
IR.v
: Defines a common IR for C and Rust (and maybe eventually other languages), and builds most of the infrastructure necessary for instantiating the LanguageSpecification API for a language with pointers and function calls -
C.v
: conversion to C code as strings. Instantiates the API defined inStringification.Language
. -
Rust.v
: conversion to Rust code as strings. Instantiates the API defined inStringification.Language
.
-
-
CompilersTestCases.v
: Various test cases to ensure everything is working -
BoundsPipeline.v
: Assemble the various compiler passes together into a composed pipeline. It is the final interface for the compiler. Also contains some tactics for applying the BoundsPipeline correctness lemma. -
PushButtonSynthesis/ReificationCache.v
: Defines the cache that holds reified versions of operations, as well as the tactics that reify and apply things from the cache. -
PushButtonSynthesis/*
: Reifies the various operations fromArithmetic.v
, defines the compositions of the BoundsPipeline with these operations, proves that their interpretations satisfies the specs fromCOperationSpecifications.v
, assembles the reified post-bounds operations into synthesis targets. These are the files thatCLI.v
depends on:ReificationCache.v
: Defines the cache of pre-reified terms. Splitting up reification from uses of the pipeline allows us to not have to re-reify big terms every time we change the pipeline or intermediate stages thereof.InvertHighLow.v
: Defines some common definitions, around splitting apart high and low bits of things, for Barrett and FancyMontgomeryReduction.Primitives.v
: Specializes the pipeline to basic "primitive" operations such as cmovznz, addcarryx, subborrowx, etc.SmallExamples.v
: Some small examples of using the pipeline. Nothing depends on this file; it is for demonstration purposes only.*ReificationCache.v
: Holds the reified versions of the definitions used in the corresponding file.BarrettReduction.v
,FancyMontgomeryReduction.v
,SaturatedSolinas.v
,UnsaturatedSolinas.v
,WordByWordMontgomery.v
: Holds the instantiation of the pipeline to the corresponding implementation choice, as well as any relevant correctness proofs (such as that things assemble into a ring).
-
SlowPrimeSynthesisExamples.v
: Additional uses of the pipeline for primes that are kind-of slow, which I don't want extraction blocking on. Also contains some debugging examples. -
CLI.v
: Setting up all of the language-independent parts of extraction; relies on having a list of strings-or-error-messages for each pipeline, and on the arguments to that pipeline, and builds a parser for command line arguments for that. -
StandaloneHaskellMain.v
,StandaloneOCamlMain.v
,ExtractionHaskell.v
,ExtractionOCaml.v
: Extraction of pipeline to various languages
The files defined in Rewriter/
are split up into the following
dependency graph (including some files from Language/
at the top):
IdentifiersLibrary.v โโโโโโโโโโโโโโโโโโโโโโโโโโ IdentifiersGenerate.v โโโโโโโโโโโโโโโโโโโโโ IdentifiersGENERATED.v
โ โ โ โ
โ โโโโโโโโโโโโโโโโโ IdentifiersLibraryProofs.v โโโโโโโโดโ IdentifiersGenerateProofs.v โโ IdentifersGENERATEDProofs.v
โ โ โ
โ โ โ
โ โ โ
โ โ โ
โ โ โ
Rewriter.v โโโโโโโโโโโโโโโโโโโโโโโ ProofsCommon.v โโโโโโโโโโโโโโโโโโโโโ ProofsCommonTactics.v โ
โ โ โ โ โ
Reify.v โโโโโโโโโโโโโโโโ Wf.v InterpProofs.v โ โ
โ โ โ โ โ
Rules.v โโโโโโโโโโโโโ AllTactics.v โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
RulesProofs.v AllTacticsExtra.v
โ โ
โโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโดโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Passes/NBE.v Passes/Arith.v Passes/ArithWithCasts.v Passes/StripLiteralCasts.v
โ โ โ โ โ
โ โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
Passes/ToFancy.v Passes/ToFancyWithCasts.v โ
โ โ โ
โโโโโโโโโฌโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
All.v
-
Rules.v
: Defines the list of types of the rewrite rules that will be reified. Largely independent of the expression language. -
RulesProofs.v
: Proves all of the Gallina versions of the rewrite rules correct. -
Rewriter.v
: Defines the rewriter machinery. In particular, all of the rewriter definitions that have non-rewrite-rule-specific proofs about them are found in this file. -
RewrierReify.v
: Defines reification of rewrite rules, continuing on fromRewriter.v
, and culminates in the tacticRewriteRules.Tactic.Build_RewriterT
and the tactic notationmake_Rewriter
which define a package of typeRewriteRules.GoalType.RewriterT
. TheBuild_*
tactic returns aconstr
, while themake_*
tactic notation refines thatconstr
in the goal. Both tactics take two arguments: first a booleaninclude_interp
which specifies whether (true
) or not (false
) to prefix the list of rewrite rules with the reduction-to-literal rewrite rules; and second a list ofbool * Prop
which is the list of rewrite rule types to reify, each paired with a boolean saying whether or not to try rewriting again in the output of the replacement for that rule. -
ProofsCommon.v
: Defines the notion of interp-goodness and wf-goodness for rewrite rules, defines tactics to prove these notions, and contains a semi-arbitrary collection of proofs and definitions that are mostly shared between the wf proofs and the interp proofs. Importantly, this file defines everything needed to state and prove that specific rewrite rules are correct. Additionally defines a packageRewriteRules.GoalType.VerifiedRewriter
which describes the type of the overall specialized rewriter together with itsWf
andInterp
proofs. (This package should perhaps move to another file?) -
ProofsCommonTactics.v
: Defines the actual tactics used to prove that specific rewrite rules are correct, and to inhabit the packages defined inProofsCommon.v
. -
Wf.v
: Proves wf-preservation of the generic rewriter, taking in wf-goodness of rewrite rules as a hypothesis. -
InterpProofs.v
: Proves interp-correctness of the generic rewriter, taking in interp-goodness of rewrite rules as a hypothesis. -
AllTactics.v
: Defines the tacticRewriteRules.Tactic.make_rewriter
(and a similar tactic notation) which build the entireVerifiedRewriter
. They take in theinclude_interp
as inRewriter.v
tactics, as well as an hlist of proofs of rewrite rules indexed over alist (bool * Prop)
of rewrite rule types. This is the primary interface for defining a rewriter from a list of rewrite rules. -
AllTacticsExtra.v
: SpecializesAllTactics.v
to what's defined inIdentifier.v
-
{NBE, Arith, ArithWithCasts, StripLiteralCasts, ToFancy, ToFancyWithCasts}.v
: Use the tactic fromAllTactics.v
together with the proven list of rewrite rules fromRulesProofs.v
to reify and reduce the corresponding pass and generate a rewriter. -
All.v
:Definition
less file thatExport
s the rewriters defined inRewriter/*.v
Proofs files:
For Language.v
, there is a semi-arbitrary split between two files
Language.Inversion
and Language.Wf
.
-
Inversion.v
:- classifies equality of type codes and exprs
- type codes have decidable equality
- correctness of the various type-transport definitions
- correctness lemmas for the various
expr.invert_*
definitions - correctness lemmas for the various
reify_*
definitions inLanguage.v
inversion_type
, which inverts equality of type codestype_beq_to_eq
, which converts boolean equality of types to Leibniz equalityrewrite_type_transport_correct
, which rewrites with the correctness lemmas of the various type-transport definitionstype.invert_one e
which does case analysis on any inductive type indexed over type codes, in a way that preserves information about the type ofe
, and generally works even when the goal is dependently typed overe
and/or its typeident.invert
, which does case-analysis on idents whose type has structure (i.e., is not a var)ident.invert_match
, which does case-analysis on idents appearing as the discriminee of amatch
in the goal or in any hypothesisexpr.invert
, which does case-analysis on exprs whose type has structure (i.e., is not a var)expr.invert_match
, which does case-analysis on exprs appearing as the discriminee of amatch
in the goal or in any hypothesisexpr.invert_subst
, which does case-analysis on exprs which show up in hypotheses of the formexpr.invert_* _ = Some _
expr.inversion_expr
, which inverts equalities of exprs
-
Wf.v
: Depends onInversion.v
Defines:- expr.wf, expr.Wf, expr.wf3, expr.wf4, expr.Wf3, expr.Wf4
- GeneralizeVar.Flat.wf
expr.inversion_wf
(and variants), which invertwf
hypothesesexpr.wf_t
(and variants wf_unsafe_t and wf_safe_t) which make progress onwf
goals;wf_safe_t
should never turn a provable goal into an unprovable one, whilewf_unsafe_t
might.expr.interp_t
(and variants), which should make progress on equivalence-of-interp hypotheses and goals, but is not used much (mainly because I forgot I had defined it)prove_Wf
, which proves wf goals on concrete syntax trees in a more optimized way thanrepeat constructor
Proves:- funext โ (type.eqv โ Logic.eq) (
eqv_iff_eq_of_funext
) - type.related and type.eqv are PERs
- Proper instances for
type.app_curried
,type.and_for_each_lhs_of_arrow
type.is_not_higher_order
โ Reflexive (type.and_for_each_lhs_of_arrow type.eqv)- iff between
type.related{,_hetero}
and related oftype.app_curried
- various properties of
type.and{,b_bool}for_each_lhs_of_arrow
- various properties of
type.eqv
andident.{gen_,}interp
- various properties of
ident.cast
- various properties of
expr.wf
(particularly of things defined inLanguage.v
) - interp and wf proofs for the passes to/from Flat
-
UnderLetsProofs.v
: wf and interp lemmas for the various passes defined inUnderLets.v
-
MiscCompilerPassesProofs.v
: wf and interp lemmas for the various passes defined inMiscCompilerPasses.v
-
AbstractInterpretation/ZRangeProofs.v
: Proves correctness lemmas of the per-operation zrange-bounds-analysis functions -
AbstractInterpretation/Wf.v
: wf lemmas for the AbstractInterpretation pass -
AbstractInterpretation/Proofs.v
: interp lemmas for the AbstractInterpretation pass, and also correctness lemmas that combine Wf and interp