Statistical Distance on Kleisli Morphisms #
This file defines statistical distance (sdist) between Kleisli morphisms of SPComp,
based on a distinguisher-supremum formulation. This avoids needing TV distance on SDistr
and directly reuses the existing prTrue infrastructure.
Main definitions #
Main results #
sdist_self,sdist_sym,sdist_triangle— pseudometric propertiessdist_comp_right— right post-processing lemma (PPL, post-composition)sdist_comp_left— left post-processing lemma (PPL, pre-composition)sdist_wkR_le,sdist_wkL_le— tensor doesn't increase distancesdist_comp_add— composition of ε-close morphisms
Sub-SMC structure #
The composition bound sdist_comp_add and the tensor bound sdist_mapSum_le (in RC.lean)
together establish that sdist-bounded pairs form a wide sub-SMC of Kl(SPComp):
- Objects: all types (same as
Kl(SPComp)) - Morphisms from
αtoβ: pairs(f, g)withsdist f g ≤ ε - Composition:
sdist_comp_add—(ε₁, ε₂)compose toε₁ + ε₂ - Tensor:
sdist_mapSum_le—(ε₁, ε₂)tensor tomax(ε₁, ε₂) - Identity:
sdist_self—(id, id)has distance0
This sub-SMC is the semantic foundation for game-hopping proofs: each hop replaces one morphism with an ε-close one, and the total distance is bounded by the sum of hops.
Design: distinguisher-supremum formulation #
We define sdist via ⨆ D a h₀, absDiff(prTrue(bind(f a) D, h₀), prTrue(bind(g a) D, h₀))
rather than via TV distance on SDistr. This makes the right PPL trivial (compose D with g
to get a new distinguisher) and matches the game-hopping methodology directly.
The left PPL requires a convexity/weighted-average argument (absDiff_prTrue_bind_le).
Absolute Difference #
Statistical Distance #
Statistical distance between Kleisli morphisms, defined as the supremum
over all distinguishers, inputs, and initial heaps of the absolute difference
in probability of returning true.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pseudometric Properties #
Post-Processing Lemmas #
Right PPL: post-composition doesn't increase distance.
This is immediate because D ∘ g is just another distinguisher.
Representation: prTrue(bind c k, h₀) = ∑' p, (c h₀)(p) * val(p).
This lemma factors out the weighted-sum structure of prTrue(bind ...).
Helper for left PPL: weighted average of ε-close values is ε-close.
Uses prTrue_bind_eq_weighted to reduce to a weighted-sum inequality.
Helper: absDiff of common-prefix bind. If the continuations differ by at most ε pointwise, then the bound propagates through a shared computation prefix.
Left PPL: pre-composition doesn't increase distance.
The proof uses the weighted average argument via absDiff_prTrue_bind_le.
Two-level sdist_comp_left: pre-composition with two nested binds
(shared across both sides) does not increase sdist. Derives from
a single sdist_comp_left by collapsing the two binds via associativity.
Dependent two-level sdist_comp_left (uniform bound variant):
if the innermost continuations g₁ b₁, g₂ b₁ are pointwise-ε-close
for every intermediate value b₁, then the full two-bind composition
is also ε-close.
The dependent version is needed when the continuation depends on both
the intermediate bind value and the sampled one — e.g., when routing
ciphertext-output p.1 from an outer epoch ratchet into the final
output while an inner sample W supplies the next epoch's chain key.
Tensor (Coproduct) Distance Bounds #
Distance of right-whiskered morphisms. On .inl, only f runs; on .inr, distance is 0.
Distance of left-whiskered morphisms. On .inr, only g runs; on .inl, distance is 0.
Composition Bound #
Two ε-close morphisms compose to give (ε₁+ε₂)-close morphisms.
Monotonicity #
If sdist f g ≤ ε, then for any specific distinguisher, input, and heap,
the distinguishing advantage is bounded by ε.
IsPure Bridge: Advantage → sdist #
For IsPure computations, sdist can be bounded using only Heap.empty.
When f and g are heap-independent, prTrue(f a >>= D, h₀) depends on h₀
only through D. By "shifting" the distinguisher to absorb h₀, we reduce
the supremum over all heaps to evaluation at Heap.empty alone.
This bridges the gap between Advantage (defined at Heap.empty) and
sdist (which takes the supremum over ALL initial heaps).
AdvantageA Bridge #
sdist_isPure_le takes arguments in (D, a) order, but security hypotheses
are typically stated in (a, D) order: ∀ x D, AdvantageA (f x) (g x) D ≤ ε.
These variants eliminate the manual argument swapping.
Bridge sdist from per-input AdvantageA bounds.
This is the most common pattern in protocol security proofs: given IsPure games and a per-input advantage bound, derive sdist.
Compared to sdist_isPure_le, the advantage hypothesis uses (a, D) order
matching the convention in security definitions.
Example usage:
exact sdist_of_isPure_advantageA foo_real_isPure foo_ideal_isPure hAdv
replaces the 4-line pattern:
apply sdist_isPure_le
· intro x; exact foo_real_isPure x
· intro x; exact foo_ideal_isPure x
· intro D x; exact hAdv x D
Variant of sdist_of_isPure_advantageA with raw absDiff instead of AdvantageA.
For proofs where the advantage bound is stated as raw absDiff (prTrue ...),
with (a, D) argument order.
Oracle-Game sdist Bridge #
For oracle-based games where the game just passes an oracle record to the
adversary (G b A = A (oracles_b)), we can compute sdist from Advantage.
The key observations:
- D-absorption: For Bool-valued output, any post-distinguisher D can be
absorbed into the adversary:
A(o) >>= D = A'(o)whereA' o = A o >>= D. - Heap absorption: The adversary controls the heap via
initHeap. For any initial heaph₀, defineA'(o) = initHeap h₀ >> A(o). ThenG b A' at Heap.empty = G b A at h₀.
Together these show: sdist G_real G_ideal = ⨆_A Advantage(G_real A, G_ideal A).
Replace the current heap with h₀, discarding the old heap.
(initHeap h₀ >> c) h = c h₀ for any h.
Equations
Instances For
For games of the form G A = A record (game is pure function application),
sdist equals the supremum of Advantage over all adversaries.
This bridges oracle-game security (∀ A, Advantage ≤ ε) to the categorical
sdist framework, giving access to PPLs, composition, and tensor bounds.
The hypotheses state that G_real and G_ideal are pure application:
G_real A h = A real_oracles h and G_ideal A h = A ideal_oracles h.
PseudoEMetricSpace Instance #
The pseudometric properties sdist_self, sdist_sym, sdist_triangle are exactly
the axioms of Mathlib's PseudoEMetricSpace. We register this instance on a wrapper
type KlMorph α β to make sdist available as edist, gaining automatic
triangle-inequality chaining, edist_comm, metric space topology, etc.
Wrapper type for Kleisli morphisms α → SPComp β.
This is a thin wrapper that exists solely to carry the PseudoEMetricSpace
instance using sdist as the extended distance function.
Equations
- CatCrypt.Crypto.KlMorph α β = (α → CatCrypt.Core.SPComp β)
Instances For
Unwrap a KlMorph to the underlying Kleisli morphism.
Instances For
Equations
- CatCrypt.Crypto.instEDistKlMorph = { edist := fun (f g : CatCrypt.Crypto.KlMorph α β) => CatCrypt.Crypto.sdist f.run g.run }
Kleisli morphisms α → SPComp β form a pseudo-extended-metric space
under statistical distance. This is a pseudometric (not a metric) because
sdist f g = 0 does not imply f = g — two computationally different
programs can have identical output distributions.
Equations
- One or more equations did not get rendered due to their size.