pRHL Loop-Congruence Rules #
Relational Hoare rules for List.forM and List.foldlM over SPComp,
analogous to VCVio's rvcstep congruence steps for List.mapM/List.foldlM.
Instead of manually unrolling lists with repeated rHoare_bind/rHoare_ret,
these rules discharge a synchronized loop in one application:
rHoare_forM— the two sides iterate over listsxs,ysrelated pointwise byR(aList.Forall₂ R xs yswitness); a heap invariantI : RPreis carried through every iteration.rHoare_forM_same— the common synchronous specialization: same input list, two different loop bodies related pointwise.rHoare_foldlM— likerHoare_forM, butList.foldlMadditionally threads accumulators; a value relationVon the accumulators is carried alongside the heap invariantI.rHoare_foldlM_same— synchronousfoldlMspecialization (same list, same accumulator relation, bodies related pointwise).
A unary companion section (in the CatCrypt.Core.SPComp namespace) provides
the IsPure loop lemmas:
SPComp.mapM_isPure/SPComp.forM_isPure/SPComp.foldlM_isPure— a monadic loop whose body is heap-pure at every element of the list is heap-pure. These discharge theIsPureside conditions on games defined viaList.mapM(e.g. Heliosprivacy_real/privacy_ideal).
Usage sketch #
-- Both sides write the same key schedule; heap equality is invariant:
example (l : Location) (vs : List l.ty) :
rHoare eqPre (vs.forM fun v => SPComp.set l v)
(vs.forM fun v => SPComp.set l v)
(fun _ h₁ _ h₂ => eqPre h₁ h₂) :=
rHoare_forM_same vs fun v _ => rHoare_set_sync l v ...
Unary IsPure loop lemmas #
List.forM over SPComp is heap-pure when the body is heap-pure at every
element of the list.
List.foldlM over SPComp is heap-pure when the step is heap-pure at
every accumulator and every element of the list.
Loop congruence for List.forM: if xs and ys are related pointwise by
R and every related pair of loop bodies preserves the heap invariant I,
then the two loops preserve I.
Synchronous specialization of rHoare_forM: both sides iterate over the
same list xs, with loop bodies f and g related pointwise on the elements
of xs.
List.foldlM congruence #
Loop congruence for List.foldlM: in addition to the heap invariant I,
a value relation V on the accumulators is threaded through every iteration.
If the initial accumulators are V-related and each related step preserves
both I and V, the folds end I-and-V-related.
Synchronous specialization of rHoare_foldlM: both sides fold over the
same list xs, with step functions related pointwise on elements of xs.