The cascade is a PRF on prefix-free inputs
OpenCityMD.cascade_prfFor a nonempty finite key set, every prefix-free distinguisher making at most queries of at most blocks against the cascade of yields a -query distinguisher against with (Bellare–Canetti–Krawczyk 1996).
import Mathlib import Definitions.Def_CityMD open Cryptography.MerkleDamgard CityMD
/-- The cascade is a PRF on prefix-free queries (Bellare–Canetti–Krawczyk 1996):
a prefix-free distinguisher making at most `q` queries of at most `ℓ` blocks has
advantage at most `q ℓ` times that of some `q`-query distinguisher against `f`. -/
theorem CityMD.cascade_prf {K B : Type} [Fintype K] [Nonempty K] [DecidableEq K] [Fintype B]
[DecidableEq B] (ℓ q : ℕ) (f : K → B → K) (A : OComp (Msg B ℓ) K Bool)
(hq : ∀ O, A.queries O ≤ q) (hA : PrefixFree A) :
∃ D : OComp B K Bool, (∀ O, D.queries O ≤ q) ∧
advPRF (fun k (x : Msg B ℓ) => cascade f k x) A ≤ q * ℓ * advPRF f D := by sorryRead-back
What the Lean code literally says, in plain math · claude-opus-5-5
CityMD.cascade_prf
Read-back
Let K be a nonempty finite type and B a finite type, both with decidable equality, let ℓ, q ∈ ℕ, and let f : K → B → K. Let A be a deterministic adaptive oracle program that queries messages x ∈ Msg B ℓ (nonempty, at most ℓ blocks), receives answers in K, and outputs a bit. Assume:
- (hq) against every oracle, A makes at most q queries (repeats counted);
- (hA) against every oracle, no query of A is a proper prefix of another of its queries.
Then there is a deterministic program D with oracle B → K such that D makes at most q queries against every oracle, and
|Pr_{k←K}[A^{x ↦ hash_f(k, x)} = 1] − Pr_{ρ←(Msg B ℓ → K)}[A^ρ = 1]| ≤ q · ℓ · |Pr_{k←K}[D^{f(k,·)} = 1] − Pr_{ρ←(B → K)}[D^ρ = 1]|.
D may depend on f and A (non-uniform), and running time is not modelled.
Audit notes
- The first draft omitted
[Nonempty K]and was false for empty K (0/0 = 0 convention; machine-checked counterexample). Fixed:[Nonempty K]is now a hypothesis. - With K nonempty, I believe the statement is true. It is the standard BCK result. Hybrids H_i (i = 0..ℓ) replace the first i levels with a random function on prefixes, and H_ℓ coincides with the ideal function on Msg because of prefix-freeness. Each adjacent pair is a multi-instance PRF game with at most q instances and q queries in total. A further hybrid over the instances costs a factor of q, and each single-instance distinguisher makes at most q queries. Derandomization is fine because |E_coins Δ| ≤ max_coins |Δ|, so a deterministic D that is best for some fixing of the coins achieves the bound, and D may depend on f. Overall this matches the qℓ·Adv_f(q) bound of BCK96.
- Other edge cases: B empty with K nonempty gives an empty Msg, so the left side is 0. When ℓ = 0 and K is nonempty, A makes no queries and the left side is 0. Repeated queries are harmless because both worlds answer them consistently.
toListis injective on Msg, so prefix comparison via lists is faithful. - The docstring matches the code apart from the missing nonemptiness of K. The bound is quantitative only in queries; no running time is modelled.