Documentation

GaudisCrypt.Logic.PRHLWp

Tactics for relational judgments (pRHL) #

prhlStmt registers one descriptor per side with the judgment registry (Logic/Judgment.lean), so the generic statement steps work on it, on both sides or on one ({1}, {2}):

And the relational steps proper:

Relations written in tactics (I, M, P, the coupling f) are relational conditions as in equiv[ … ]: §x{1}, §x{2}, ={x}, over the program variables of the goal.

The simp set for relational conditions: the reads through writes of simpReads, and the trivial coupling conditions equiv_rnd leaves (the identity and negation push a uniform distribution to itself, and its support is everything).

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    The names of the binders of ty's leading ∀s.

    Apply the lemma lem to g by unifying its conclusion with the goal (no unfolding of the judgment, which MVarId.apply would do to count arguments): pre sets the lemma's arguments by binder name first. The arguments left open are returned, in order.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Generalizing the reads of two states #

      Does σ.globals occur in e other than as the state of a read x.get σ.globals?

      Does the state σ occur in e only as read (collectReadsOf) or as its globals?

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        On a goal ∀ σ₁ σ₂ : ProgramState, P σ₁ σ₂: generalizeReads for both states — every read of σ₁ becomes a value x₁, every read of σ₂ a value x₂ (named after the variable), and the states are dropped if nothing else mentions them; a state that occurs other than read is left alone (onlyRead), its reads with it. Where the globals themselves occur (§allGlobals, the globals a call leaves), they become a value globals₁/globals₂ first, and the reads of global variables stay reads of it (x.get globals₁), so nothing is lost. Atomic, as generalizeReads.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Relational conditions in tactics #

          Elaborate the relational term t (§x{1}, §x{2}, ={x} over the program variables of the goal goalTy) at type T, as a function ProgramState → ProgramState → T.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            A relational condition (Prop-valued).

            Equations
            Instances For

              generalizeReadsRel, for the tactic tac: if it fails, the goal stays about the two states, and tac says so (ECReport.fallback).

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                The goal's type, checked to be a prhlStmt judgment.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  From procedures to statements #

                  On a goal prhlProc A p₁ p₂ B: the judgment about the two call statements res <- call pᵢ (x₁, …, xₙ), one local variable per parameter (prhlProc_of_prhlStmt), the conditions with the reads simplified.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    equiv_proc_to_stmt: from equiv[ M₁ ~ M₂ : P ==> Q ] to the judgment about the call statements res <- call Mᵢ (x₁, …, xₙ) (equivProcToStmt); inline them with stmt_inline 0. EC's proc, to the bodies, is equiv_proc (Logic/ECProc.lean).

                    Equations
                    Instances For

                      Relational steps #

                      skip ~ skip: the implication, reads generalized (generalizeReadsRel).

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        equiv_skip: at skip ~ skip (what stmt_wp leaves when the code is all deterministic), the implication from the precondition to the postcondition, the reads of the two states as plain values x₁, x₂.

                        Equations
                        Instances For

                          equiv_skip, the decide instances normalized first (TacticMisc.normDecide), so that every read is generalized (EC's auto uses it).

                          Equations
                          Instances For

                            EC's rnd{i}: the last statement of side i is a sampling x <$ d, which goes by itself (prhlStmt_seq_sample_left/_right): the postcondition before it asks d lossless and the postcondition for every value in its support.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              equiv_rnd f: the last statements of both sides are samplings x₁ <$ d₁, x₂ <$ d₂, coupled along f (prhlStmt_seq_sample): the postcondition before them asks that f push d₁ to d₂, and the postcondition for every a in the support of d₁ paired with f a. f is a relational term (it may read both states, §x{1}, §x{2}); without it, the identity.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                equiv_rnd_run k: the last statement of the left side is a sampling x₁ <$ d, and the last k statements of the right side sample from d into the same variable (prhlStmt_seq_sample_run_right). The postcondition before them asks for that run, as an equation of the right side's run with the sampling, and the postcondition for every draw.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  equiv_while_raw I (the older form of EC's while I, which is equiv_while, Logic/ECWhileRel.lean): the last statements of both sides are loops, synchronized by the invariant I (prhlStmt_seq_while). Goals: body (the bodies keep I, from I and the guard), guard (under I the guards agree), exit (I and a false guard give the postcondition), then the code before the loops, with postcondition I.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    equiv_while_noframe{i} I V (the older form of EC's while{i} I V, which is equiv_while{i}, Logic/ECWhileRel.lean): the last statement of side i is a loop, run on that side only, with the invariant I and the variant V : ℕ (both relational, EC's while{i} I V; prhlStmt_seq_while_left/_right). Goals: lossless (the body terminates under I and the guard), variant (the body keeps I and decreases V, a Hoare triple for each state of the other side and each value of V), exit (I and a false guard give the postcondition), then the code before the loop, with postcondition I.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      equiv_seq_last k₁ k₂ : M: cut both statements, the last k₁ (left) and k₂ (right) statements after the cut, with the relation M in between (prhlStmt_seq). Goals: the code before the cut (to M), then the code after it (from M).

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        A procedure judgment h with the procedure aliases of modules in its type (proc f = c;, @[gaudiModuleAlias]) rewritten to their callees by their X.f.apply_simp lemmas: EC's call (RO_LRO_D (D2(D))) names the alias, the program calls the callee. A module made of aliases only is opened too (X.apply_simp, and the accessors' mk_simp on the record it gives): D2(D) applied, a single-procedure module, is its alias. h itself when its type mentions no alias.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          The call rule without a frame (prhlStmt_seq_call, prhlStmt_seq_call_refl): what equiv_call h and equiv_call do when no framed rule applies (Logic/ECCallEquiv.lean), and equiv_call_frameless by name.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            equiv_call h: the last statements of both sides are calls x₁ <- call p₁ (e₁), x₂ <- call p₂ (e₂), and h a procedure judgment equiv[ p₁ ~ p₂ : P ==> Q ] about the callees (prhlStmt_seq_call; for an abstract procedure, prhlProc_glob hA: EC's call (_ : ={glob A})). The postcondition before the calls: P at the arguments and globals, and the postcondition after them for all results and globals Q relates.

                                            equiv_call alone: both calls are of the same procedure (EC's call (_ : true) on the same code, prhlStmt_seq_call_refl): the postcondition before them asks for equal arguments and equal globals, and the postcondition after them for every result and globals, the same on both sides.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              equiv_call_frameless h / equiv_call_frameless: the call rule without a frame, by name (what equiv_call h falls back to, with a warning, when the framed rule does not apply).

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For

                                                equiv_call_frame X: equiv_call (same procedure on both sides) where the postcondition may also assume that the variable X kept its value through the call (prhlStmt_seq_call_refl_frame). X must lie outside the callee's footprint: the module's own (Module.Proc.inFootprint_fvP, or a hypothesis), the disjointness shown by fp_disjoint from the restriction hypotheses in context. EC proves such a step with swap or sim, from its memory restrictions.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For

                                                  simp_reads: simplify the goal with the read-through-write lemmas the judgment tactics use (relSimpDecls: a variable read after writes to other variables, resets, the globals written by a call), for goals left after unfolding expectations or judgments by hand.

                                                  Equations
                                                  Instances For

                                                    phoare_ewp: on a goal phoareStmt A s g ρ r about loop-free code, introduce the state and the precondition and spell the expectation s.ewp g σ out (Stmt.ewp_seq, _ifThenElse, _assign, _sample, _skip): samplings become expected, conditionals ifs (also those with a sampling inside, which phoare_wp does not take), calls stay the callee's expectation. Then simp_reads, and the tests back to propositions. What is left is about the initial state only.

                                                    Equations
                                                    Instances For

                                                      if c t e; s (through the lets of the locals) as if c (t; s) (e; s), and the equivalence (Stmt.Equiv.seq_ite); fails on anything else.

                                                      equiv_if: both statements are conditionals (prhlStmt_if): goals then, else (with the test true, resp. false, on both sides) and guard (the tests agree under the precondition). equiv_if{i}: side i's statement is a conditional (prhlStmt_if_left/_right, EC's if{i}): goals then, else, each against the other side. To reach a conditional inside a sequence, cut first (equiv_seq, equiv_seq_last).

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        equiv_rcondf{i}: the last statement of side i is a loop that does not run — its guard is false where it starts (EC's rcondf{i}, for a trailing loop; prhlStmt_seq_while_false_left/_right). The postcondition before it adds the false guard.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For

                                                          equiv_sym: swap the two sides (prhlStmt.symm, on a procedure judgment prhlProc.symm; EC's symmetry).

                                                          Equations
                                                          Instances For

                                                            equiv_case P: case analysis on the relation P of the initial states (prhlStmt_case): goals with A ∧ P and with A ∧ ¬P as preconditions.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              equiv_sim: EC's sim on straight-line code. Backwards over both statements, as long as one of these applies: stmt_wp (trailing deterministic code, both sides), equiv_call (calls of the same procedure, or of procedures spelled differently, their equality tried by rfl and left as a callee goal otherwise). When both statements are used up, equiv_skip, and the implication it leaves closed by simp_all if it can. It stops at anything else (a conditional, a loop, a sampling, calls of different procedures), leaving that goal: cut there with equiv_seq … : M.

                                                              Equations
                                                              Instances For