Documentation

GaudisCrypt.Logic.HoareWp

Backwards wp steps on a Hoare triple #

hoare_wp k: the last k statements by wp — the judgment-generic Judgment.wpStep (Logic/JudgmentWp.lean) with the Hoare rules this file registers (hoare_seq_det, hoare_seq_sample), the postcondition simplified by simpReadsDecls after each step. Plus hoare_call, hoare_while_raw and hoare_skip, which are Hoare-specific.

theorem GaudisCrypt.intoLocal_varLens_get_resetSetter (n : String) (T : Type) (i : Nonempty T) (k : ℕ) (hk : k = VariableName.encode n) (S : Set String) (u : Unit) (σ : ProgramState) :
(varLens { name := n, type := T, nonempty := i, key := k, keyCorrect := hk }).intoLocal.get ((resetSetter S).set u σ) = if n ∈ S then VariableAssignment.init { name := n, type := T, nonempty := i, key := k, keyCorrect := hk } else (varLens { name := n, type := T, nonempty := i, key := k, keyCorrect := hk }).intoLocal.get σ

A local variable read after a reset: its initial value if the reset covers its name, else what it was before. Unconditional, so that simp needs no discharger for it; the condition is decided afterwards, on the literal set the reset prints with. The slot is spelled with its fields and @Lens.intoLocal T, as a slot in a program is: stated for a variable v, the content type would be the projection v.type, which does not unify with T before v is known.

The globals of a state after a write: what a global read in a condition becomes once it is a plain g.get σ.globals (eval_lens_global). eval keeps its state in an instance argument, where simp does not rewrite, so the reads are taken out of eval first.

A global's read in the program state is its read in the globals.

theorem GaudisCrypt.Setter.throwaway_set {A : Type u_1} (v : A) (τ : ProgramState) :
throwaway.set v τ = τ

A discarded result (_ <- call …) writes nothing.

Membership in a prefix region, as a statement about character lists that decide settles on literals. A rewrite of the membership only: unfolding stringsStartingWith itself would also change how the resets in the program print.

The simp set of simpReads: theorems are rewritten with, definitions unfolded.

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

    Simplify argument i of the goal (an application, hoareStmt A s B say) with simp only over the declarations decls (theorems are rewritten with, definitions unfolded) and the default simprocs, leaving the other arguments alone. Never fails; an unchanged goal is returned as is.

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

      Reads through writes, in the postcondition of a goal hoareStmt A s B (as hoare_assign_wp leaves it): liftLens of a program-state lens is the lens itself, Lens.pair splits a tuple write into one write per slot, eval_lens_full turns a read pinned at a written state into a get, a read of the written slot is the value (Lens.set_get), and a read of a disjoint slot ignores the write (Lens.get_of_disjoint_set; disjointness by instance search, so for slots with literal names), and a read after a reset is decided by whether the reset covers the name (intoLocal_varLens_get_resetSetter, then membership in the literal set the reset prints with, by decide). simp only with simpReadsDecls and the default simprocs.

      Only the postcondition is rewritten: the same lemmas would also unfold the lenses of the statement itself (a tuple l-value into a raw Setter structure), which then no longer prints in the program syntax. Never fails; an unchanged goal is returned as is.

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

        hoare_wp k's step: the last k statements by wp, one at a time from the end — the judgment-generic Judgment.wpStep, with the Hoare rules registered above (deterministic code: the postcondition after the update; a sampling: every value in the support), the postcondition simplified by simpReadsDecls after each step.

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

            One backwards step over a call, on a goal hoareStmt A {x₁; …; xₙ₋₁; x <- call p (args)} B: close the call (hoare_seq), and continue with the triple about x₁; …; xₙ₋₁, its postcondition simplified (simpReads). h is either a procedure triple about p, used through hoare_call_wp (the new postcondition is h's precondition at the arguments, and B after any result and globals that h's postcondition allows), or a rule concluding a statement triple about the call itself, such as hoare_call_frame L hp, whose remaining arguments are found by unification. Arguments of the rule that unification leaves open are returned as goals.

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

              hoare_call h: hoareCallStep h on the main goal — the last statement is a call, closed by h: a procedure triple about the callee (EC's call (_ : P ==> Q)), or a rule for the call statement, such as hoare_call_frame L hp (the callee does not touch L). Without h, the trivial triple hoareProc_true: the call may return anything and write any globals.

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

                A loop step, on a goal hoareStmt A {x₁; …; xₙ₋₁; while c body} B and an invariant I: hoare_while_raw closes the loop, leaving three goals, in order: the body preserves I (from I ∧ c), I with a failed test implies B (reads generalized, generalizeReads), and the triple about x₁; …; xₙ₋₁ with postcondition I.

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

                  hoare_while_raw I: hoareWhileStep on the main goal, with the invariant I written like a condition of a hoare[ ] triple — §x reads the program variable x of the goal's program, or a global. Goals: body, exit, then the code before the loop with postcondition I.

                  EC's while I — two goals, the exit under the loop's frame in the second — is hoare_while (Logic/ECWhileHoare.lean).

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

                    The end of a backwards proof, on a goal hoareStmt A skip B (the statement possibly under its lets): the implication ∀ σ, A σ → B σ (hoare_skip_of_imp), with the reads of the state in it generalized to plain values (generalizeReads), if there are any.

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

                      hoare_skip: hoareSkip on the main goal — from hoareStmt A skip B to ∀ x …, A → B with the reads of the state as plain values.

                      Equations
                      Instances For