Skip to content

Commit 7ecd179

Browse files
authored
Merge pull request #29 from scaraven/lib/euf-cma
library: the composition walk's forgery is an EUF-CMA forgery or a Keccak collision, in the kernel; vacuous theorems removed
2 parents 7543acc + 5524aac commit 7ecd179

13 files changed

Lines changed: 735 additions & 132 deletions

‎AGENTS.md‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,15 @@ From [`harness/season.toml`](harness/season.toml) (the CI smoke uses
428428
`build_s`, so a slow build may fit only when the cache hits.
429429
- **Keccak-256** (FIPS 202's `Keccak-f[1600]` sponge with Keccak's padding): collision resistance
430430
on the seven tagged domains, one-wayness of the chain step, and `Keccak-256(k ‖ ·)` with a secret
431-
32-byte key `k` as a PRF. The signature's unforgeability follows from these
432-
(on paper).
431+
32-byte key `k` as a PRF. The signature's unforgeability (EUF-CMA, each index used once)
432+
follows from these (on paper). The composition across the tree needs EUF-CMA and collision
433+
resistance only. A signed trace the log does not hold is reduced, for any tree shape, to an
434+
EUF-CMA forgery against the service's signed traces or an explicit collision
435+
([`Library/Compose.lean`](RecursionFast/Library/Compose.lean), `Forgery.reduce`); the walk
436+
around it (`walkSigned`, `compose_prob_signed`) is kernel for balanced trees. Security against
437+
signature-only forgery, which the original signed-oracle construction (Chiesa–Tromer, ICS 2010)
438+
also assumes, is not used: the walk matches a signed proof to the log by its trace, the signed
439+
message, not by its signature.
433440
- **The badge**: the code Lean's compiler emits for `acc`, built from the same build the kernel
434441
checked; and the harness tools (gate, source rule, manifest, renderer, sandbox).
435442
- **The runner and the service**, tested, not proved ([`tests/`](tests/), [`.github/workflows/ci.yml`](.github/workflows/ci.yml)).
@@ -476,8 +483,10 @@ From [`harness/season.toml`](harness/season.toml) (the CI smoke uses
476483
third party who checks it.
477484
- **The service is trusted runtime**: a bug that signs a wrong answer, reuses an index or exposes
478485
the key would be accept-all.
479-
- **On paper, not in the kernel**: unforgeability of the signature, the PRF step from the random
480-
oracle to the keyed deployment, and the composition across the stream's comb (the union bound
486+
- **On paper, not in the kernel**: unforgeability of the signature (EUF-CMA) and the bounds on the
487+
probabilities of the walk's EUF-CMA and collision outcomes (the per-run reduction to them, given
488+
the service's signed traces, is kernel; the model has no signing oracle), the PRF step from the
489+
random oracle to the keyed deployment, and the composition across the stream's comb (the union bound
481490
over any finite set of paths is kernel; the walk is kernel for balanced trees only).
482491
- **`KS` is textbook knowledge soundness only for adversaries that ask the verifier's queries
483492
themselves**: its extractor also reads the verifier's answers, so for an adversary that leaves

‎RecursionFast/Contract/Certificate.lean‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ knowledge content is the named extractor `E` with its program and budget (`Secur
2626
certifiable (`Controls/Certificate.lean`, `sigTrust_no_certificate`), and a certificate never
2727
rests on unforgeability. Unforgeability is used once, outside the certificate: the composition
2828
argument across the tree (`Library/Compose.lean`) returns a forgery when a signed trace in
29-
the extraction tree is not in the run's one oracle log.
29+
the extraction tree is not in the run's one oracle log, an EUF-CMA forgery against the
30+
service's signed traces or a collision (`walkSigned`).
3031
* *Why the trace is used up exactly and its queries capped.* Completeness is
3132
required for every witness of the relation, and a node witness carries its children's traces.
3233
If a trace could carry entries after the verifier's last query, or queries of any length, the

‎RecursionFast/Contract/Signature.lean‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ refuses after `2^16` signatures (`service/PROTOCOL.md` §3).
3434
**What is not here.** Key generation, the secret chain starts and signing are the service's (a
3535
Lean reference signer and the theorem that its signatures pass `SigOk` are in
3636
`Library/Signer.lean`). Unforgeability (EUF-CMA of this scheme with each index used once) is an
37-
assumption of the design argued on paper, not a theorem of the contract; the composition theorem
38-
(`Library/Compose.lean`) returns an explicit forgery when it is what fails.
37+
assumption of the design argued on paper, not a theorem of the contract; the composition walk
38+
(`Library/Compose.lean`, `walkSigned`) returns an explicit EUF-CMA forgery against the service's
39+
signed traces, or a collision, when it is what fails. Security against signature-only forgery
40+
(Chiesa–Tromer, ICS 2010) is not needed: the walk matches signed traces by message.
3941
-/
4042
import RecursionFast.Contract.Relation
4143

‎RecursionFast/Controls.lean‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
Keccak (known answers and FIPS 202's constants) · Relation (signed children, the reference
55
signer) · Oracle (with `runSeq`) · Security · Completeness · Potential · Machine · Extractor (the
66
output format) · LogScan · WitnessSending · Tree · Certificate (the key quantifier) · Backdoor
7-
(certified in the model, harmless under the keyed deployment) · Compose (the composition walk and
8-
its probability) · Signature (trace digest, WOTS digits, chain, leaf, node, root, `SigOk`).
7+
(certified in the model, harmless under the keyed deployment) · Unforgeability (the forgery
8+
events and the service's signed traces) · Compose (the composition walk, its reduction to EUF-CMA
9+
and collisions, and its probability) · Signature (trace digest, WOTS digits, chain, leaf, node,
10+
root, `SigOk`).
911
Security holds the direct controls of the textbook `KS`; Security and Potential hold the
1012
potential controls as facts about the library's `KState`.
1113
-/
@@ -23,4 +25,5 @@ import RecursionFast.Controls.WitnessSending
2325
import RecursionFast.Controls.Tree
2426
import RecursionFast.Controls.Certificate
2527
import RecursionFast.Controls.Backdoor
28+
import RecursionFast.Controls.Unforgeability
2629
import RecursionFast.Controls.Compose

‎RecursionFast/Controls/Certificate.lean‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ Negative:
2323
with an extractor that returns nothing, is **not certified**: the certificate's key quantifier
2424
reaches `Signer.pk sk`, and the adversary that holds `sk` (`SigTrust.adversary`) asks nothing,
2525
outputs a statement with its signature, and wins with probability `1`. With any extractor,
26-
`sigTrust_certificate_opens`: a certificate would make the extractor open the signature of every
27-
statement, on the empty log, to a witness of the relation. **Why the quantifier is what does
28-
it**: `sigTrust_ks_unsignable` (the same verifier is knowledge-sound at error `0` under any key
29-
for which no signature verifies), so a certificate stated for one key could not exclude it.
30-
That no such key can be exhibited (it would need a digest outside the image of a Keccak-256
31-
tree) is why the twin is stated for every such key rather than for one.
26+
knowledge soundness under such a key makes the extractor open the signature of every
27+
statement, on the empty log, to a witness (`SigTrust.sigTrust_ks_extracts`), and the verifier
28+
has a knowledge state exactly when every statement has a witness
29+
(`SigTrust.sigTrust_kstate_iff`): a signature is no knowledge.
3230
* The certificate does **not** exclude a verifier that recognises a public function of the
3331
oracle (`Controls/Backdoor.lean`); the deployment does.
3432
@@ -117,22 +115,6 @@ theorem sigTrust_no_certificate (S : Submission) (hV : ∀ vk, S.V vk = SigTrust
117115
have hs := small_of_caps h.cap.2.2.1 h.cap.1
118116
SigTrust.sigTrust_not_ks_none (fun _ _ => 0) _ hs.1 hs.2 (hV _ ▸ hE ▸ h.secure _)
119117

120-
/-- With any extractor, a certificate would open every statement's signature, on the empty log,
121-
to a witness of the relation. -/
122-
theorem sigTrust_certificate_opens (S : Submission) (hV : ∀ vk, S.V vk = SigTrust.Vsig vk)
123-
(h : Certificate S) (sk : ℕ → ℕ → Digest) (c : Digest) :
124-
∃ w, S.E c (SigTrust.sigProof (Signer.sign sk 0 c)) [] = some w ∧
125-
Rel (S.acc (Signer.pk sk)) c w :=
126-
have hs := small_of_caps h.cap.2.2.1 h.cap.1
127-
SigTrust.sigTrust_ks_extracts sk (hV _ ▸ h.secure (Signer.pk sk)) hs.1 hs.2 c
128-
129-
/-- **The twin**: under a key for which no signature verifies, the signature-trusting verifier
130-
is knowledge-sound for the relation of every `acc` and every extractor. -/
131-
theorem sigTrust_ks_unsignable {vk : Digest} (hvk : ∀ m σ, SigOk vk m σ = false)
132-
(acc : Digest → Signed → Bool) (E : Digest → Proof → Log → Option Wit) :
133-
KS (Rel acc) (SigTrust.Vsig vk) E 0 0 :=
134-
SigTrust.sigTrust_ks_of_unsignable hvk _ E
135-
136118
/-! ## What the certificate does not exclude -/
137119

138120
open Classical in

‎RecursionFast/Controls/Compose.lean‎

Lines changed: 130 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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
1212
Negative (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
2525
probability `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
-/
2846
import RecursionFast.Library.Compose
@@ -35,7 +53,7 @@ namespace RecursionFast.Controls.Compose
3553
open RecursionFast RecursionFast.Compose RecursionFast.WitnessSending
3654
open 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. -/
4159
theorem 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+
191302
end RecursionFast.Controls.Compose

0 commit comments

Comments
 (0)