-
Notifications
You must be signed in to change notification settings - Fork 63
Add tentative auto-generated EasyCrypt language documentation #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ EasyCrypt reference manual | |
| .. toctree:: | ||
| :maxdepth: 2 | ||
|
|
||
| language | ||
| tactics | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| The EasyCrypt language | ||
| ======================================================================== | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
| :glob: | ||
|
|
||
| language/* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| .. _language-overview: | ||
|
|
||
| ======================================================================== | ||
| Overview | ||
| ======================================================================== | ||
|
|
||
| EasyCrypt is an interactive proof assistant designed for reasoning about | ||
| the security of cryptographic constructions. It provides: | ||
|
|
||
| - A **typed functional language** for writing mathematical definitions: | ||
| types, operators, predicates, lemmas, and proofs. | ||
|
|
||
| - An **imperative programming language** for describing the behavior | ||
| of cryptographic algorithms and adversaries as probabilistic programs. | ||
|
|
||
| - A collection of **program logics** -- Hoare logic, probabilistic | ||
| Hoare logic, probabilistic relational Hoare logic, and others -- for | ||
| reasoning about the behavior of those programs. | ||
|
|
||
| This chapter introduces the general structure of EasyCrypt files and | ||
| how the various pieces fit together. | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| File structure | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| An EasyCrypt source file has the extension ``.ec``. A file consists of | ||
| a sequence of top-level declarations and definitions. The main kinds | ||
| of top-level items are: | ||
|
|
||
| - **Type declarations**: introduce new types (abstract, aliases, | ||
| records, algebraic datatypes). | ||
|
|
||
| - **Operator and predicate declarations**: introduce new functions and | ||
| predicates, either abstract or with a concrete definition. | ||
|
|
||
| - **Axioms and lemmas**: state properties (axioms are assumed, lemmas | ||
| must be proved). | ||
|
|
||
| - **Module type declarations**: describe the interface of a module | ||
| (a collection of mutable state and procedures). | ||
|
|
||
| - **Module declarations**: define modules that implement a module type. | ||
|
|
||
| - **Theories**: group related declarations together under a name. | ||
|
|
||
| - **Sections**: provide a scoping mechanism for local assumptions. | ||
|
|
||
| - **Clone directives**: instantiate abstract theories with concrete | ||
| definitions. | ||
|
|
||
| Items are terminated by a period (``.``). | ||
|
|
||
| Here is a minimal EasyCrypt file that declares a type, defines an | ||
| operator, and states a lemma: | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require import AllCore. | ||
|
|
||
| type color = [Red | Green | Blue]. | ||
|
|
||
| op is_primary (c : color) : bool = | ||
| with c = Red => true | ||
| with c = Green => false | ||
| with c = Blue => true. | ||
|
|
||
| lemma red_is_primary : is_primary Red. | ||
| proof. by []. qed. | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| Loading theories | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| EasyCrypt files can load other files (called *theories*) using the | ||
| ``require`` command: | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require AllCore. | ||
|
|
||
| This makes the contents of ``AllCore`` available under a qualified | ||
| name (e.g. ``AllCore.List.size``). To bring the names into scope | ||
| without qualification, add ``import``: | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require import AllCore. | ||
|
|
||
| There is also ``export``, which re-exports the imported names so that | ||
| any file that later imports the current file also sees them: | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require export AllCore. | ||
|
|
||
| You can require several theories at once: | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require import AllCore List FSet. | ||
|
|
||
| The ``import`` and ``export`` keywords can also be used standalone to | ||
| import or export a theory that has already been required: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain/Given an example to show that this can be used to |
||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require AllCore. | ||
| import AllCore. | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| Comments | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| Comments in EasyCrypt are delimited by ``(*`` and ``*)`` and can be | ||
| nested: | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| (* This is a comment *) | ||
|
|
||
| (* Comments (* can be *) nested *) | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| A first example | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| To give a flavor of how the language pieces fit together, here is a | ||
| small but complete example. It defines an abstract type, an operator | ||
| over that type, and proves a simple property. | ||
|
|
||
| .. code-block:: easycrypt | ||
|
|
||
| require import AllCore. | ||
|
|
||
| (* An abstract type with decidable equality *) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not an ideal comment here. |
||
| type key. | ||
|
|
||
| (* A simple operator *) | ||
| op xor (x y : key) : key. | ||
|
|
||
| (* We assume xor is involutive *) | ||
| axiom xorK (x y : key) : xor (xor x y) y = x. | ||
|
|
||
| (* A consequence: xor is a left-inverse of itself *) | ||
| lemma xor_cancel (x y : key) : xor (xor x y) y = x. | ||
| proof. by apply xorK. qed. | ||
|
|
||
| The following chapters describe each part of the language in detail. | ||
| :ref:`Types <language-types>` covers the type system. | ||
| :ref:`Operators and predicates <language-operators>` explains how to | ||
| define functions and predicates. :ref:`Expressions <language-expressions>` | ||
| and :ref:`Formulas <language-formulas>` describe the term language. | ||
| :ref:`Programs <language-programs>` introduces the imperative fragment. | ||
| :ref:`Modules <language-modules>` covers the module system. | ||
| :ref:`Theories and sections <language-theories>` and | ||
| :ref:`Cloning <language-cloning>` explain theory management. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EasyCrypt source files can also have the extension
.ecafor abstract theories. (Add a cross-ref to relevant section?)