11/-
22# Controls: the composition walk and its probability (`Library/Compose.lean`)
33
4- Negative (what the bare disjunction does not say). `forgery_trivial`, for
5- the capped `Forgery`: under the key of any known signer and for every log within `logCap`, a
6- `Forgery` exists with no other hypothesis (a signed one-entry trace whose answer to the empty
7- query is not in the log, which exists since the log has fewer than `2^256` entries). So
8- `compose_exists_free`: `compose_exists`'s conclusion holds for such a key with none of its
9- hypotheses used. The content is `walk`'s ( and `compose`'s) membership of the forgery in the
10- extraction tree of the root signed proof .
4+ Negative (what the outcome types do not say). `forgery_trivial`, for the capped `Forgery`:
5+ under the key of any known signer and for every log within `logCap`, a `Forgery` exists with no
6+ other hypothesis (a signed one-entry trace whose answer to the empty query is not in the log,
7+ which exists since the log has fewer than `2^256` entries). `collision_nonempty`: a Keccak-256
8+ collision exists (pigeonhole), so `Outcome` and `SignedOutcome` are inhabited with no content.
9+ The content is the compiled `walk` and `walkSigned`, which compute their outcome ( the forgery's
10+ membership of the extraction tree included), and the theorems about what they return .
1111
1212Negative (an escape is the knowledge-soundness failure, and `compose_prob`'s event is reachable).
1313`noExt` is the witness-sending submission with an extractor that returns nothing; its `acc` is the
@@ -23,6 +23,24 @@ log, `walk` returns the leaf starts:
2323 proofs gives `[s₁, s₂]`.
2424 And `ws_compose_prob`: under every key and against every adversary, its walk escapes with
2525probability `0` (`compose_prob` at `ε = 0`, `qV = 0`).
26+
27+ Against the service's signed traces (`Forgery.reduce`, `walkSigned`), with `queryLeaf`, the leaf
28+ proof of `(s, n)` carrying the one-entry trace `(qMax, a)` (a query of exactly `queryCap` bytes),
29+ accepted by the one-query verifier `oneQuery qMax` (`Controls/Relation.lean`):
30+ * Positive (the EUF-CMA outcome is reached through the walk): with the empty log and a service
31+ that signed nothing, `walkSigned` returns an EUF-CMA forgery at the root
32+ (`walkSigned_queryLeaf_euf`); so the adversary that holds the key, asks nothing and outputs that
33+ proof makes the EUF-CMA term of `compose_prob_signed` certain (`queryLeaf_euf_prob`). Against a
34+ service that signed nothing, the reduction returns every forgery as an EUF-CMA forgery
35+ (`reduce_nil`).
36+ * Positive (`Honest` on a non-empty trace): a log holding `(qMax, a)` accounts for the service
37+ having signed that trace (`honest_queryLeaf`), and `walkSigned` then extracts the leaf's start
38+ (`walkSigned_queryLeaf_starts`). On the honest one-leaf witness-sending tree, whose trace is
39+ empty (so `Honest` holds vacuously, `honest_leaf`), it returns the leaf's start as well
40+ (`walkSigned_one_leaf`).
41+ * Negative: if the service's signed traces include the forged trace, the forgery is no EUF-CMA
42+ forgery and `Honest` fails (`forgery_signed_not_euf`), so the hypothesis is what makes the
43+ forgery an EUF-CMA one; `noExt`'s `walkSigned` escapes (`noExt_walkSigned_escaped`).
2644 Symbolic (`decode_encode`, `sigOk_sign`, `extract_of_E`, `walkFrom_leaf`); no hash is evaluated.
2745-/
2846import RecursionFast.Library.Compose
@@ -35,7 +53,7 @@ namespace RecursionFast.Controls.Compose
3553open RecursionFast RecursionFast.Compose RecursionFast.WitnessSending
3654open RecursionFast.Controls.Relation (leafSigned acc_leafSigned)
3755
38- /-! ## Negative: the bare disjunction is free under a known signer's key -/
56+ /-! ## Negative: a `Forgery` against a log is free under a known signer's key -/
3957
4058/-- A log of at most `logCap` entries misses some answer to the empty query. -/
4159theorem fresh_answer (L : Log) (hlen : L.length ≤ logCap) :
@@ -61,17 +79,6 @@ theorem forgery_trivial (sk : ℕ → ℕ → Digest) (L : Log) (hlen : L.length
6179 fun e he => List.mem_singleton.mp he ▸ Nat.zero_le _, Signer.sigOk_sign sk 0 (by decide) _,
6280 fun h => ha (h _ (List.mem_singleton_self _))⟩⟩
6381
64- /-- Hence `compose_exists`'s conclusion, for such a key, uses none of its hypotheses but the
65- log's length. -/
66- theorem compose_exists_free (S : Submission) (sk : ℕ → ℕ → Digest) (L : Log)
67- (hlen : L.length ≤ logCap) (n r : ℕ) (hs : List Digest) (p : Signed) :
68- (∃ ss, List.Forall₂ (fun s h => chainEnd s n = h) ss hs) ∨ Nonempty Collision ∨
69- Nonempty (Forgery (Signer.pk sk) L) ∨
70- ∃ (c : Digest) (q : Signed) (bs : List Bool), bs.length ≤ r ∧
71- InTree S L (treeRoot (hs.map fun h => leafStmt h n)) p bs c q ∧
72- Escape S (Signer.pk sk) L c q :=
73- Or.inr (Or.inr (Or.inl (forgery_trivial sk L hlen)))
74-
7582/-! ## Negative: an escape is the knowledge-soundness failure -/
7683
7784/-- The witness-sending submission with an extractor that returns nothing. -/
@@ -188,4 +195,108 @@ theorem ws_compose_prob (vk : Digest) {n : ℕ} (hn : n ≤ chainCap) (r : ℕ)
188195 le_antisymm ((compose_prob (ks vk) n hn r hs hr A hA (by simpa [submission] using hQ)).trans
189196 (by simp [submission])) bot_le
190197
198+ /-! ## The forgery outcome against the service's signed traces -/
199+
200+ /-- **A collision exists** : Keccak-256 maps infinitely many strings to `2^256` digests. So the
201+ outcome types `Outcome` and `SignedOutcome` are inhabited with no content (by their collision
202+ constructor); the content is what the compiled `walk` and `walkSigned` compute, and the theorems
203+ about it. -/
204+ theorem collision_nonempty : Nonempty Collision := by
205+ by_contra h
206+ exact not_injective_infinite_finite keccakDigest fun x y heq =>
207+ by_contra fun hne => h ⟨⟨x, y, hne, heq⟩⟩
208+
209+ /-- **Positive** (the EUF-CMA branch is reached): against a service that signed nothing, the
210+ reduction returns every forgery against the log as an EUF-CMA forgery, in particular the known
211+ signer's of `forgery_trivial`. -/
212+ theorem reduce_nil {vk : Digest} {L : Log} (f : Forgery vk L) :
213+ (f.reduce [] ⟨nofun , nofun ⟩).isLeft = true := by
214+ unfold Forgery.reduce
215+ split
216+ · rename_i h; exact absurd (List.mem_of_find?_eq_some h) List.not_mem_nil
217+ · rfl
218+
219+ /-- **Negative** (`Honest` is needed): if the service's signed traces include the forged trace,
220+ which the log does not hold, the forgery is no EUF-CMA forgery against them, and the log does not
221+ account for them. -/
222+ theorem forgery_signed_not_euf {vk : Digest} {L : Log} (f : Forgery vk L) :
223+ ¬ EufForgery (SigOk vk) (issued [(f.p.tr, f.p.σ)]) (traceDigest f.p.tr) f.p.σ ∧
224+ ¬ Honest [(f.p.tr, f.p.σ)] L :=
225+ ⟨fun h => h.2 (mem_fst_issued.mpr ⟨_, List.mem_singleton_self _, rfl⟩),
226+ fun h => f.notIn (h.inLog _ (List.mem_singleton_self _))⟩
227+
228+ /-- The signed traces of the honest one-leaf witness-sending tree: the leaf proof's trace and
229+ signature, which the empty log accounts for (vacuously: the trace is empty). -/
230+ theorem honest_leaf (sk : ℕ → ℕ → Digest) (s : Digest) (n : ℕ) :
231+ Honest [((leafSigned sk 0 s n).tr, (leafSigned sk 0 s n).σ)] [] :=
232+ ⟨by simp [leafSigned], by simp [leafSigned]⟩
233+
234+ /-- **Positive** : on the honest one-leaf tree, the walk against its signed traces returns the
235+ leaf's start. -/
236+ theorem walkSigned_one_leaf (sk : ℕ → ℕ → Digest) (s : Digest) {n : ℕ} (hn : n ≤ chainCap) :
237+ (walkSigned [] _ (honest_leaf sk s n) n hn 0 [chainEnd s n] rfl (leafSigned sk 0 s n)
238+ (acc_leafSigned sk (by decide) s hn)).starts? = some [s] :=
239+ (Outcome.starts?_reduce _ _).trans (walk_one_leaf sk s hn)
240+
241+ /-- **Negative** : `noExt`'s walk against the same signed traces escapes at the root, so the
242+ knowledge-soundness term of `compose_prob_signed` is needed. -/
243+ theorem noExt_walkSigned_escaped (sk : ℕ → ℕ → Digest) (s : Digest) {n : ℕ}
244+ (hn : n ≤ chainCap) :
245+ (walkSigned [] _ (honest_leaf sk s n) n hn 0 [chainEnd s n] rfl (leafSigned sk 0 s n)
246+ (noExt_acc_leaf sk s hn)).Escaped :=
247+ (Outcome.escaped_reduce _ _).mpr (noExt_walk_escaped sk s hn)
248+
249+ /-! ## The forgery outcome through the walk: a one-query leaf proof -/
250+
251+ open RecursionFast.Controls.Relation (oneQuery qMax acc_query_at_cap)
252+
253+ /-- The leaf proof of `(s, n)` with the one-entry trace `(qMax, a)`, signed with key `0`. -/
254+ def queryLeaf (sk : ℕ → ℕ → Digest) (s a : Digest) (n : ℕ) : Signed :=
255+ ⟨encode (.leaf s n), [(qMax, a)], Signer.sign sk 0 (traceDigest [(qMax, a)])⟩
256+
257+ /-- The one-query verifier accepts it, for the one-leaf tree's root. -/
258+ theorem acc_queryLeaf (sk : ℕ → ℕ → Digest) (s a : Digest) (n : ℕ) :
259+ (oneQuery qMax).acc (Signer.pk sk) (treeRoot ([chainEnd s n].map fun h => leafStmt h n))
260+ (queryLeaf sk s a n) = true :=
261+ acc_query_at_cap sk a _ (by rw [size_encode_leaf]; decide)
262+
263+ /-- **Positive** (the EUF-CMA outcome through the walk): with the empty log and a service that
264+ signed nothing, the walk against its signed traces returns an EUF-CMA forgery at the root. -/
265+ theorem walkSigned_queryLeaf_euf (sk : ℕ → ℕ → Digest) (s a : Digest) {n : ℕ}
266+ (hn : n ≤ chainCap) :
267+ (walkSigned [] [] ⟨nofun , nofun ⟩ n hn 0 [chainEnd s n] rfl (queryLeaf sk s a n)
268+ (acc_queryLeaf sk s a n)).IsEuf := by
269+ unfold walkSigned walk walkFrom
270+ rw [extract_forgery (L := []) _ fun h => List.not_mem_nil (h _ (List.mem_singleton_self _))]
271+ exact Outcome.isEuf_reduce_forgery _ _ _ _ _
272+ ⟨Signer.sigOk_sign sk 0 (by decide) _, fun h => by
273+ obtain ⟨_, hx, _⟩ := mem_fst_issued.mp h; exact List.not_mem_nil hx⟩
274+
275+ /-- **The EUF-CMA term of `compose_prob_signed` is reached** : against a service that signed
276+ nothing (`T = fun _ _ => []`), the adversary that holds the key, asks nothing and outputs
277+ `queryLeaf` makes the EUF-CMA event certain. -/
278+ theorem queryLeaf_euf_prob (sk : ℕ → ℕ → Digest) (s a : Digest) {n : ℕ} (hn : n ≤ chainCap) :
279+ prob (fun p L => ∃ hacc : (oneQuery qMax).acc (Signer.pk sk)
280+ (treeRoot ([chainEnd s n].map fun h => leafStmt h n)) p = true ,
281+ (walkSigned L [] ⟨nofun , nofun ⟩ n hn 0 [chainEnd s n] rfl p hacc).IsEuf)
282+ (.ret (queryLeaf sk s a n)) [] = 1 :=
283+ (prob_ret _ _ _).trans (ind_of ⟨_, walkSigned_queryLeaf_euf sk s a hn⟩)
284+
285+ /-- **Positive** (`Honest` on a non-empty trace): a log holding `(qMax, a)` accounts for the
286+ service having signed `queryLeaf`'s trace. -/
287+ theorem honest_queryLeaf (sk : ℕ → ℕ → Digest) (s a : Digest) (n : ℕ) :
288+ Honest [((queryLeaf sk s a n).tr, (queryLeaf sk s a n).σ)] [(qMax, a)] :=
289+ have hq : qMax.size = queryCap := by simp [qMax, ByteArray.size]
290+ ⟨by simp [queryLeaf], fun x hx e he => by
291+ rw [List.mem_singleton.mp hx] at he
292+ rw [List.mem_singleton.mp he, hq]⟩
293+
294+ /-- **Positive** : with that log and those signed traces, the walk returns the leaf's start. -/
295+ theorem walkSigned_queryLeaf_starts (sk : ℕ → ℕ → Digest) (s a : Digest) {n : ℕ}
296+ (hn : n ≤ chainCap) :
297+ (walkSigned [(qMax, a)] _ (honest_queryLeaf sk s a n) n hn 0 [chainEnd s n] rfl
298+ (queryLeaf sk s a n) (acc_queryLeaf sk s a n)).starts? = some [s] :=
299+ (Outcome.starts?_reduce _ _).trans (walkFrom_leaf hn rfl rfl (by simp [queryLeaf])
300+ (decode_encode (.leaf s n) (hn.trans_lt (by decide))) rfl)
301+
191302end RecursionFast.Controls.Compose
0 commit comments