Std.Do / mvcgen bridge for SPComp #
Support-level Std.Do view of SPComp: a Std.Do.WP/Std.Do.WPMonad
instance whose weakest precondition is almost-sure (support-level)
satisfaction of the postcondition. This makes mvcgen usable for
functional-correctness goals about SPComp do-blocks. Quantitative bounds
(sdist, advantage) live outside PredTrans — expectation transformers are
monotone but not conjunctive, so they cannot inhabit
PredTrans.conjunctiveRaw; they belong to the Advantage/sdist layer.
The design mirrors VCVio's proposition-level bridge for OracleComp
(VCVio/ProgramLogic/Unary/StdDoBridge.lean).
Post shape #
SPComp α = Heap → SDistr (α × Heap) is the monad
StateT Heap (OptionT-over-PMF): failure (SDistr's none) carries no
final heap. The structural mirror of that stack is
spPostShape = .arg Heap (.except PUnit .pure)
so assertions are Heap → ULift Prop and postconditions carry a heap-free
failure barrel PUnit → ULift Prop. The alternative shape
.except PUnit (.arg Heap .pure) would give the failure barrel a Heap
argument that the semantics cannot supply (there is no heap at failure), and
wp_bind fails for it; with the heap-free barrel both WPMonad laws hold
on the nose.
⇓ r => ... (total correctness: the program must not fail) and
⇓? r => ... (partial correctness: nothing asserted on failure) both make
sense for this shape; ⇓?-triples coincide with the unary pHoare
judgment, and ⇓-triples additionally assert SPComp.NoFail.
Main definitions #
SPComp.wpProp— support-level weakest precondition as a plain predicateSPComp.wpSupport,SPComp.instWP,SPComp.instWPMonad— theStd.Doinstances at shapespPostShape- adequacy:
wpProp_iff_forall_support,triple_mayThrow_iff,triple_noThrow_iff,pHoare_iff_triple,triple_noThrow_true_iff_noFail,isPure_wpProp_iff @[spec]lemmas forSPComp.get/set/sample/failsomvcgenwalksSPCompdo-blocks
Reached via the CatCrypt.Tactics umbrella through Tactics/VC.lean
(ssprove_nofail / ssprove_phoare lower goals into this bridge).
SDistr support lemmas for bind #
Support and failure mass of SDistr.bind, in the ≠ 0 form used by the
support-level WP.
SPComp-level support lemmas #
The support-level weakest precondition #
Support-level (almost-sure) weakest precondition for SPComp: from
initial heap h, every outcome (a, h') in the support of c h satisfies
post a h'. Says nothing about the failure mass — see the failure barrel of
wpSupport for that.
Equations
Instances For
The support-level predicate transformer of an SPComp computation:
success barrel = wpProp, failure barrel = guard on nonzero failure mass.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- CatCrypt.Core.SPComp.instWP = { wp := fun {α : Type} (c : CatCrypt.Core.SPComp α) => c.wpSupport }
Unfolding lemma for the support-level WP. Deliberately not @[simp]:
mvcgen must keep wp⟦·⟧ opaque and walk via @[spec] lemmas.
Equations
- CatCrypt.Core.SPComp.instWPMonad = { toLawfulMonad := CatCrypt.Core.SPComp.instWPMonad._proof_1, toWP := CatCrypt.Core.SPComp.instWP, wp_pure := ⋯, wp_bind := ⋯ }
A Triple from pointwise success/failure obligations.
The unary pHL judgment (CatCrypt.Unary.pHoare) is exactly the
partial-correctness (⇓?) Std.Do triple.
SPComp.NoFail is the trivial total-correctness triple: the failure
barrel ⌜False⌝ of noThrow forces zero failure mass.
For an IsPure computation with witness distribution d, the
support-level WP is the ∀-over-d.support statement at the unchanged
heap.
@[spec] lemmas for the SPComp primitives #
These let mvcgen walk SPComp do-blocks: the generic Std.Do.Spec.bind /
Spec.pure handle the monadic skeleton (via instWPMonad), and these
lemmas handle the leaves.
Spec for SPComp.get: returns the heap's value at l, heap unchanged,
never fails.
Spec for SPComp.set: writes v at l, returns (), never fails.
Spec for SPComp.sample: the result can be any element of A
(uniform has full support), heap unchanged, never fails.
Spec for SPComp.fail: empty support, always fails — the precondition
is the failure barrel.
Spec for the prefix form SPComp.pure (the generic Std.Do.Spec.pure
covers Pure.pure; this covers explicit SPComp.pure leaves).
Examples: mvcgen-closed functional-correctness triples #
Demo location storing a Bool.
Equations
- CatCrypt.Core.StdDoBridgeExamples.bLoc = { id := 0, ty := Bool, fintype := Bool.fintype, inhabited := instInhabitedBool }