pRHL for statements and procedures #
The relational judgment on the statements and procedures of the language, EasyCrypt's
equiv [ c₁ ~ c₂ : P ==> Q ]: from any two states related by P, the two runs can be coupled
so that the final states are related by Q. It is the coupling judgment
ProgramDenotation.prhl2 (Logic/PRHL2.lean) at the statements' denotations, so all its rules
apply; this file states the ones the tactics use at the level of statements:
- sequencing (
prhlStmt_seq),skip, consequence, case analysis; - one-sided tails (
prhlStmt_seq_left/_right): a statement run on one side only, which must terminate there — deterministic code (Stmt.Det) and lossless samplings are the instances the wp driver uses; - a sampling on both sides, coupled along a function (
prhlStmt_seq_sample, EC'srnd f); - the synchronized loop rule (
prhlStmt_while); - transport along statement equivalences, on either side (what
stmt_inline/stmt_splituse); - procedures (
prhlProc), the bridge to the statement form, and EC'sbyequiv(Procedure.Pr_eq_of_prhlProc).
equiv[ A ==> B ] { c₁ } ~ { c₂ }: from states related by A, the runs of c₁ and c₂ can
be coupled so that the final states are related by B.
Equations
- One or more equations did not get rendered due to their size.
Instances For
equiv[ p₁ ~ p₂ : A ==> B ]: for all arguments, from globals related by A, the runs of the
two procedures can be coupled so that the results and the final globals are related by B.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Couplings, generically #
A positive-mass point of a subprobability is in its support.
A statement's run, as its expectations: the subprobability is determined by them.
The marginal conditions, as expectations.
Two reads coupled: a point mass.
Basic rules #
Consequence: a stronger precondition, a weaker postcondition.
Strengthening the precondition, the judgment first (as hoare_pre).
Weakening the postcondition, the judgment first.
Symmetry: the two sides swapped.
Symmetry, backwards: the judgment with the sides swapped.
Sequencing: an intermediate relation B. The second judgment comes first, so that the wp
steps can fill B.
Case analysis on a relation of the initial states.
An existential in the precondition (EC's exists*/elim*).
Replace the first statement on the left by one with the same runs from the states the
precondition allows (EC's transitivity{1} with an equivalence proven denotationally).
Replace the second statement on the right by one with the same runs.
EC's exists* e{1}; elim* => v: fix the value of an expression of the left state.
EC's exists* e{2}; elim* => v: fix the value of an expression of the right state.
A false precondition.
One-sided tails #
A statement at the end of one side only, matched against nothing on the other: it must terminate
(the other side does nothing, so the coupling has to pair every run of it with the other
side's final state), and the postcondition must hold on all its outcomes. Deterministic code and
lossless samplings are the instances; EC's wp and rnd{1}.
A program run on the left only: lossless where the precondition holds, and the postcondition
on all its outcomes. (ProgramDenotation.prhl2.kill_left, with losslessness only where it is
needed.)
One-sided tail, left: d at the end of the left side, nothing on the right.
One-sided tail, right: the mirror of prhlStmt_seq_left.
A deterministic statement runs as a point mass.
Deterministic tail, left (Stmt.Det): the postcondition after the update.
Deterministic tail, right.
A sampling's run: draw, then write.
Sampling on the left only (EC's rnd{1}): a lossless distribution, and the
postcondition for every value in its support.
Sampling on the right only (EC's rnd{2}).
A loop terminates with probability 1 from the states of an invariant I under which its
body is lossless and strictly decreases a variant V (EC's while{i} I V, the termination half).
What a Hoare triple guarantees holds on every outcome.
Replace the second statement on the right by one with the same runs from every state the
first statement can reach (a Hoare postcondition Q of it): EC's transitivity{2} against a
program proven equivalent denotationally after a.
A loop on the right only (EC's while{2} I V for a trailing loop): from where the code
before it establishes I (for the left state as it ends), the loop terminates (its body lossless
and decreasing the variant V under I; both may depend on the left state), keeps I, and I with the failed test gives B.
A loop on the left only (EC's while{1} I V): prhlStmt_seq_while_right, mirrored.
Two-sided sampling (EC's rnd f) #
Coupled samplings: the two draws coupled along f (which may depend on the two states
before the draws), which must push the left distribution to the right one; the postcondition
for every left value in the support, paired with its image.
A sampling against code that samples the same: x₁ <$ d on the left, on the right any
statement t whose run (from the state before it) draws from d and writes the draw to x₂
(EC's rnd after rewriting the right side into one sampling, e.g. a two-step sampling).
A sampling against code that samples a preimage: x₁ <$ d on the left, on the right a
statement t whose run draws b from μ and writes it to x₂, with d the image of μ by f
(prhlStmt_seq_sample_run_right with a map; e.g. a block against a loop of bits).
Pushing a distribution along a function #
The first conjunct prhlStmt_seq_sample leaves: the coupling function pushes the left
distribution to the right one.
The identity coupling.
A bijection pushes the uniform distribution to itself.
Loops #
Synchronized loops: under the invariant the guards agree, and the bodies keep the invariant; on exit, the invariant and the (common) guard false.
The loop rule at the end of both sides, as the tactic applies it: the body keeps I, I
and the guard false give B, and the code before the loops establishes I.
The fixed-point equation of a loop, on denotations.
A loop whose guard is false does nothing.
A loop on the left that does not run (EC's rcondf{1}, for a trailing loop): its guard
is false where it starts.
A loop on the right that does not run (EC's rcondf{2}).
Conditionals #
Synchronized conditionals: the guards agree, and the branches are related.
A conditional runs one of its branches.
A conditional on the left only (EC's if{1}): each branch against the right side.
A conditional on the right only (EC's if{2}).
Judgments about equivalent statements #
Along s.EquivInLens s' l, a judgment about s on one side is the judgment about s' with the
conditions read through l on that side: what stmt_inline and stmt_split use, per side.
Transport on the left side, the conditions given up to an equation (as the inliner cleans them).
Transport on the right side.
Transport on the left, without renaming.
Transport on the right, without renaming.
Procedures #
A call statement's run: the callee's, its result written to x and its globals kept.
A call of a lossless procedure terminates (the losslessness half of EC's call{1} p_ll).
Every outcome of a call is the caller's state with the callee's result and globals written back, for an outcome of the callee.
From a procedure judgment to a statement judgment: the procedures' judgment is the one
about the two call statements res <- call pᵢ (args), the arguments in local slots argsLᵢ and
the results in local slots resLᵢ (phoareProc_as_phoareStmt for pRHL).
EC's byequiv, for expectations: expectations that agree on related outcomes are equal.
EC's byequiv: events that agree on related outcomes have the same probability.
EC's byequiv, one-sided: if related outcomes in E₁ are in E₂, then E₁ is at most as
likely as E₂.
Symmetry of procedure judgments: the two sides swapped.
Symmetry of procedure judgments, backwards: the judgment with the sides swapped.
The union bound for a procedure's events.
EC's byequiv: bad (the fundamental lemma): if related outcomes agree on the bad events,
and on the events outside them, the events' probabilities differ by at most the bad event's.
Calls on both sides, with a procedure judgment (EC's call (_ : P ==> Q)): the callees'
runs coupled by h, from the arguments and globals before the calls; the postcondition for
every results and globals h relates, written back.
Transitivity of procedure judgments (game hopping): couplings of p₁ with p₂ and of
p₂ with p₃ glue along p₂ (ProgramDenotation.prhl2.trans).
Consequence for procedure judgments.
Abstract procedures (EC's call (_ : ={glob A})) #
Reflexivity: any procedure, on equal arguments from equal globals, can be coupled with
itself to equal results and equal globals (EC's call (_ : true) on the same code).
Calls of the same procedure on both sides (EC's call (_ : true) on the same code): from
equal arguments and equal globals, the two calls return the same result and the same globals
(prhlProc_refl), so the postcondition must hold for every result r and globals g written
back on both sides.
prhlStmt_seq_call_refl for callees that are equal but not spelled the same (modules built
differently that reduce to the same procedure): their equality is a premise.
The adversary rule: a procedure confined to the footprint R (on every argument), run
on equal arguments from globals that agree on what it can touch (R.touched_getter, EC's
glob A), returns equal results and globals that again agree on it (prhl2_glob).