Repository navigation
Expand file tree
/
Copy pathBasic.lean
More file actions
385 lines (328 loc) · 19.8 KB
/
Copy pathBasic.lean
File metadata and controls
385 lines (328 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/-
Copyright (c) 2024 ArkLib Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Quang Dao, Tobias Rothmann
-/
module
public import ArkLib.OracleReduction.Security.Basic
public import ArkLib.Data.Fin.Fold
public import VCVio.EvalDist.Monad.Option
/-!
# Functional Commitment Schemes (with Oracle Openings)
A commitment scheme, relative to an oracle `oSpec : OracleSpec ι`, and for a given
function `oracle : Data → Query → Response` transforming underlying data `Data` into an
oracle `Query → Response`, is a tuple of three operations:
- KeyGen, which is a function `keygen : OracleComp oSpec (ComKey × VerifKey)` that samples keys
for the committer and the verifier.
- Commit, which is a function `commit : Data → OracleComp oSpec (Commitment × Decommitment)`.
The `Decommitment` value captures any auxiliary information (e.g. blinding randomness) produced
during the commit phase that is needed to open the commitment later.
- Open, which is (roughly) an interactive proof (relative to `oSpec`) for the following relation:
- `StmtIn := (cm : Commitment) × (x : Query) × (y : Response)`
- `WitIn := Data × Decommitment`
- `rel : StmtIn → WitIn → Prop :=
fun ⟨cm, x, y⟩ ⟨d, dc⟩ ↦ commit d ⇝ (cm, dc) ∧ oracle d x = y`
For deterministic schemes (e.g. KZG), `Decommitment` is `Unit`.
For randomized schemes (e.g. Pedersen, RO-based), `Decommitment` carries the blinding factor.
There is one inaccuracy about the relation above: `commit` is an oracle computation, and not a
deterministic function; hence the relation is not literally true as described. This is why
security definitions for commitment schemes have to be stated differently than those for IOPs.
## References
* [Chiesa, A., Guan, Z., Knabenhans, C., and Yu, Z., *On the Fiat-Shamir Security of
Succinct Arguments from Functional Commitments*][CGKY25]
-/
@[expose] public section
namespace Commitment
open OracleSpec OracleComp SubSpec ProtocolSpec
variable {ι : Type} (oSpec : OracleSpec ι) (Data Commitment Decommitment ComKey VerifKey : Type)
/-- Key generation for a commitment scheme, producing a committer key and a verifier key. -/
structure KeyGen where
keygen : OracleComp oSpec (ComKey × VerifKey)
/-- The commitment algorithm, parameterized by the committer key and the data to commit. -/
structure Commit where
commit : ComKey → Data → OracleComp oSpec (Commitment × Decommitment)
variable [O : OracleInterface Data] {n : ℕ} (pSpec : ProtocolSpec n)
/-- The opening protocol used to prove a claimed oracle response for committed data. -/
structure Opening where
opening : (ComKey × VerifKey) →
Proof oSpec (Commitment × (q : O.Query) × O.Response q) (Data × Decommitment) pSpec
/-- A commitment scheme with key generation, commitment, and opening algorithms. -/
structure Scheme extends
KeyGen oSpec ComKey VerifKey,
Commit oSpec Data Commitment Decommitment ComKey,
Opening oSpec Data Commitment Decommitment ComKey VerifKey pSpec
section Security
noncomputable section
open scoped NNReal ENNReal
variable [DecidableEq ι]
{oSpec : OracleSpec ι} {Data : Type} [O : OracleInterface Data]
{Commitment Decommitment ComKey VerifKey : Type} [∀ t, Fintype (oSpec.Range t)] {n : ℕ}
{pSpec : ProtocolSpec n} [∀ t, Inhabited ([pSpec.Challenge]ₒ.Range t)]
[∀ t, Fintype ([pSpec.Challenge]ₒ.Range t)]
[∀ i, VCVCompatible (pSpec.Challenge i)]
[∀ i, SampleableType (pSpec.Challenge i)]
{σ : Type} (init : ProbComp σ) (impl : QueryImpl oSpec (StateT σ ProbComp))
(scheme : Scheme oSpec Data Commitment Decommitment ComKey VerifKey pSpec)
/-- A commitment scheme satisfies **correctness** with error `correctnessError` if for all
`data : Data` and `query : O.Query`, the probability of accepting upon executing the commitment
and opening procedures honestly is at least `1 - correctnessError`. Any randomness used by the
committer is sampled inside the `OracleComp` in `scheme.commit`.
-/
def correctness (correctnessError : ℝ≥0) : Prop :=
∀ data : Data,
∀ query : O.Query,
let pImpl : QueryImpl (oSpec + [pSpec.Challenge]ₒ) (StateT σ ProbComp) :=
QueryImpl.addLift impl challengeQueryImpl
Pr{let result ← (OptionT.mk do
(simulateQ pImpl (do
let (ck, vk) ← liftComp scheme.keygen _
let (cm, decomm) ← liftComp (scheme.commit ck data) _
let proof := scheme.opening (ck, vk)
let stmt : Commitment × (q : O.Query) × O.Response q :=
(cm, ⟨query, O.answer data query⟩)
let wit : Data × Decommitment := (data, decomm)
(proof.run stmt wit).run
)).run' (← init))}[let ⟨⟨_, (prvStmtOut, witOut)⟩, stmtOut⟩ := result
(stmtOut, witOut) ∈ acceptRejectRel ∧ prvStmtOut = stmtOut] ≥ 1 - correctnessError
/-- A commitment scheme satisfies **perfect correctness** if it satisfies correctness with no error.
-/
def perfectCorrectness : Prop :=
correctness init impl scheme 0
omit [DecidableEq ι] [∀ t, Fintype (oSpec.Range t)] [∀ t, Inhabited ([pSpec.Challenge]ₒ.Range t)]
[∀ t, Fintype ([pSpec.Challenge]ₒ.Range t)]
[(i : pSpec.ChallengeIdx) → VCVCompatible (pSpec.Challenge i)] in
/-- **Perfect correctness from perfect completeness of the opening.**
If every honest key/commitment pair puts
the claimed opening statement into a relation `rel`, and the opening protocol is perfectly
complete for `rel` **from every post-setup state** (hence the `pure s` initialization — the
opening runs in whatever oracle state key generation and commitment left behind), then the
scheme is perfectly correct.
This is the generic bridge between the reduction-level completeness theory and the
commitment-level correctness game: the game's setup prefix is peeled off support-element by
support-element (`OptionT.prEvent_mk_bind_eq_one_of_support`), and each leaf is the completeness
game of the opening at the honest input. -/
theorem perfectCorrectness_of_opening_perfectCompleteness
(rel : ComKey → VerifKey →
Set ((Commitment × (q : O.Query) × O.Response q) × (Data × Decommitment)))
(hRel : ∀ data query ck vk cm dc, (ck, vk) ∈ support scheme.keygen →
(cm, dc) ∈ support (scheme.commit ck data) →
((cm, ⟨query, O.answer data query⟩), (data, dc)) ∈ rel ck vk)
(hComplete : ∀ ck vk, (ck, vk) ∈ support scheme.keygen → ∀ s : σ,
(scheme.opening (ck, vk)).perfectCompleteness (pure s) impl (rel ck vk)) :
perfectCorrectness init impl scheme := by
intro data query
simp only [ENNReal.coe_zero, tsub_zero]
refine ge_of_eq ?_
-- Normalize the game into nested `ProbComp` binds.
simp only [simulateQ_bind, StateT.run'_eq, StateT.run_bind, QueryImpl.addLift_def,
QueryImpl.simulateQ_add_liftComp_left, QueryImpl.liftTarget_self, map_bind]
-- Peel off the setup prefix, support-element by support-element.
refine OptionT.prEvent_mk_bind_eq_one_of_support _ (prEvent_true_eq_one _) _ _ (fun s _ => ?_)
refine OptionT.prEvent_mk_bind_eq_one_of_support _ (prEvent_true_eq_one _) _ _ (fun p hp => ?_)
have hkg : p.1 ∈ support scheme.keygen :=
support_simulateQ_run'_subset impl _ s
(by rw [StateT.run'_eq, support_map]; exact ⟨p, hp, rfl⟩)
refine OptionT.prEvent_mk_bind_eq_one_of_support _ (prEvent_true_eq_one _) _ _ (fun p₁ hp₁ => ?_)
have hcm : p₁.1 ∈ support (scheme.commit p.1.1 data) :=
support_simulateQ_run'_subset impl _ p.2
(by rw [StateT.run'_eq, support_map]; exact ⟨p₁, hp₁, rfl⟩)
-- The leaf: the opening's perfect completeness at the honest input, from the post-setup state.
have hmem := hRel data query p.1.1 p.1.2 p₁.1.1 p₁.1.2 (by simpa using hkg) (by simpa using hcm)
have hcore := hComplete p.1.1 p.1.2 (by simpa using hkg) p₁.2
rw [Proof.perfectCompleteness, Reduction.perfectCompleteness_eq_prob_one] at hcore
have h := hcore (p₁.1.1, ⟨query, O.answer data query⟩) (data, p₁.1.2) hmem
simp only [pure_bind, StateT.run'_eq, QueryImpl.addLift_def,
QueryImpl.liftTarget_self] at h
exact h
/-- An adversary in the (evaluation) binding game returns a commitment `cm`, a query `q`, two
purported responses `r₁, r₂` to the query, and an auxiliary private state (to be passed to the
malicious prover in the opening procedure). -/
structure BindingAdversary (oSpec : OracleSpec ι) (Data Commitment AuxState : Type)
[O : OracleInterface Data] {n : ℕ} (pSpec : ProtocolSpec n) (ComKey : Type)
where
claim : (ComKey →
OracleComp oSpec
(Commitment × (q : O.Query) × O.Response q × O.Response q × AuxState × AuxState))
prover : (ComKey →
Prover oSpec (Commitment × (q : O.Query) × O.Response q) AuxState Bool Unit pSpec)
/-- Evaluation binding condition for an adversary to win the binding game. -/
abbrev bindingCondition :
((query : O.Query) × O.Response query × O.Response query × Bool × Bool) → Prop :=
fun ⟨_, resp₁, resp₂, accept₁, accept₂⟩ ↦
resp₁ ≠ resp₂ ∧ accept₁ ∧ accept₂
/-- The evaluation-binding game for a specific adversary. -/
abbrev bindingGame (AuxState : Type)
(adversary : BindingAdversary oSpec Data Commitment AuxState pSpec ComKey) :
OptionT ProbComp ((query : O.Query) × O.Response query × O.Response query × Bool × Bool) :=
let pImpl : QueryImpl (oSpec + [pSpec.Challenge]ₒ) (StateT σ ProbComp) :=
QueryImpl.addLift impl (challengeQueryImpl (pSpec := pSpec))
OptionT.mk do
let s ← init
let ((ck, vk), sAfterSetup) ← (simulateQ impl scheme.keygen).run s
(simulateQ pImpl <| (show OracleComp _ _ from do
let ⟨cm, query, resp₁, resp₂, st₁, st₂⟩ ← liftComp (adversary.claim ck) _
let reduction := Reduction.mk (adversary.prover ck) (scheme.opening (ck, vk)).verifier
let accept₁ := (← (reduction.verdict
(cm, (⟨query, resp₁⟩ : (q : O.Query) × O.Response q)) st₁).run).getD false
let accept₂ := (← (reduction.verdict
(cm, (⟨query, resp₂⟩ : (q : O.Query) × O.Response q)) st₂).run).getD false
pure (some ((⟨query, resp₁, resp₂, accept₁, accept₂⟩ :
(query : O.Query) × O.Response query × O.Response query × Bool × Bool)))
)).run' sAfterSetup
/-- The probability of breaking evaluation binding for a specific adversary. -/
def bindingExperiment (AuxState : Type)
(adversary : BindingAdversary oSpec Data Commitment AuxState pSpec ComKey) : ℝ≥0∞ :=
Pr{let result ← bindingGame init impl scheme AuxState adversary}[
bindingCondition (Data := Data) result]
/-- A commitment scheme satisfies **(evaluation) binding** with error `bindingError` if for all
adversaries that output a commitment `cm`, query `q`, two responses `resp₁, resp₂`, and
auxiliary state `st`, and for all malicious provers in the opening procedure taking in `st`, the
probability that:
1. The responses are different (`resp₁ ≠ resp₂`);
2. The verifier accepts both openings
is at most `bindingError`.
Informally, evaluation binding says that it's computationally infeasible to open a commitment to
two different responses for the same query. -/
def binding (bindingError : ℝ≥0) : Prop :=
∀ AuxState : Type,
∀ adversary : BindingAdversary oSpec Data Commitment AuxState pSpec ComKey,
bindingExperiment init impl scheme AuxState adversary ≤ bindingError
/-- A **straightline extractor** for a commitment scheme takes in the commitment, the log of queries
made during the commitment phase, and returns the underlying data for the commitment. -/
abbrev StraightlineExtractor (oSpec : OracleSpec ι) (Data Commitment : Type) :=
Commitment → QueryLog oSpec → Data
/-- An adversary in the extractability game is an oracle computation that returns a commitment, a
query, a response value, and some auxiliary state (to be used in the opening procedure), given
the commitment key. -/
abbrev ExtractabilityAdversary (oSpec : OracleSpec ι) (Data Commitment AuxState : Type)
[O : OracleInterface Data] (ComKey : Type) :=
ComKey → OracleComp oSpec (Commitment × (q : O.Query) × O.Response q × AuxState)
/-- The extractability game logs the adversary's commitment phase and continues the opening
from the oracle state left by that phase. Failed openings count as rejection. -/
abbrev extractabilityGame (extractor : StraightlineExtractor oSpec Data Commitment)
(AuxState : Type)
(adversary : ExtractabilityAdversary oSpec Data Commitment AuxState ComKey)
(prover : Prover oSpec (Commitment × (q : O.Query) × O.Response q) AuxState Bool Unit pSpec) :
OptionT ProbComp (Bool × Data × (q : O.Query) × O.Response q) :=
let pImpl : QueryImpl (oSpec + [pSpec.Challenge]ₒ) (StateT σ ProbComp) :=
QueryImpl.addLift impl (challengeQueryImpl (pSpec := pSpec))
OptionT.mk do
let s ← init
let ((ck, vk), sAfterSetup) ← (simulateQ impl scheme.keygen).run s
let ((⟨cm, query, response, st⟩, queryLog), sAfterCommit) ←
((simulateQ impl.withLogging (adversary ck)).run).run sAfterSetup
(simulateQ pImpl <| (show OracleComp _ _ from do
let reduction := Reduction.mk prover (scheme.opening (ck, vk)).verifier
let accept := (← (reduction.verdict
(cm, (⟨query, response⟩ : (q : O.Query) × O.Response q)) st).run).getD false
pure (some (accept, extractor cm queryLog, ⟨query, response⟩))
)).run' sAfterCommit
/-- The probability of an accepted opening inconsistent with the data extracted from the
commitment-phase query log. -/
def extractabilityExperiment (extractor : StraightlineExtractor oSpec Data Commitment)
(AuxState : Type)
(adversary : ExtractabilityAdversary oSpec Data Commitment AuxState ComKey)
(prover : Prover oSpec (Commitment × (q : O.Query) × O.Response q) AuxState Bool Unit pSpec) :
ℝ≥0∞ :=
Pr{let result ← extractabilityGame init impl scheme extractor AuxState adversary prover}[
let ⟨accept, data, query, response⟩ := result
accept ∧ O.answer data query ≠ response]
/-- A commitment scheme satisfies **extractability** with error `extractabilityError` if there
exists a straightline extractor `E` such that for all adversaries that output a commitment `cm`,
a query `q`, a response `r`, and some auxiliary state `st`, and for all malicious provers in the
opening procedure that takes in `st`, the probability that:
1. The verifier accepts in the opening procedure given `cm, q, r`
2. The extracted data `d` is inconsistent with the claimed response (i.e., `O.answer d q ≠ r`)
is at most `extractabilityError`.
Informally, extractability says that if an adversary can convince the verifier to accept an
opening, then the extractor must be able to recover some underlying data that is consistent with
the evaluation query. -/
def extractability (extractabilityError : ℝ≥0) : Prop :=
∃ extractor : StraightlineExtractor oSpec Data Commitment,
∀ AuxState : Type,
∀ adversary : ExtractabilityAdversary oSpec Data Commitment AuxState ComKey,
∀ prover : Prover oSpec (Commitment × (q : O.Query) × O.Response q) AuxState Bool Unit pSpec,
extractabilityExperiment init impl scheme extractor AuxState adversary prover ≤
extractabilityError
-- TODO: version where the query is chosen according to some public coin?
-- TODO: multi-instance versions?
/-- An adversary in the function binding game returns a commitment `cm`, and for each index in
`Fin L`, a query, a claimed response to the query, and an auxiliary private state (to be passed
to the malicious prover in the opening procedure). -/
structure FunctionBindingAdversary (oSpec : OracleSpec ι) (Data Commitment AuxState : Type)
[O : OracleInterface Data] (L : ℕ) {n : ℕ} (pSpec : ProtocolSpec n) (ComKey : Type)
where
claim : (ComKey →
OracleComp oSpec (Commitment ×
(queryOf : Fin L → O.Query) ×
((i : Fin L) → O.Response (queryOf i)) ×
(Fin L → AuxState)))
prover : (ComKey →
Prover oSpec (Commitment × (q : O.Query) × O.Response q) AuxState Bool Unit pSpec)
/-- Function binding condition for an adversary to win the function-binding game. -/
abbrev functionBindingCondition {L : ℕ} :
((queryOf : Fin L → O.Query) ×
((i : Fin L) → O.Response (queryOf i)) × (Fin L → Bool)) → Prop :=
fun ⟨queryOf, responseOf, acceptedOf⟩ ↦
let S : Finset (Fin L) := Finset.univ
(∀ i ∈ S, acceptedOf i = true)
∧ (¬ ∃ (d : Data), ∀ i ∈ S, O.answer d (queryOf i) = responseOf i)
/-- The function-binding game for a specific adversary. -/
abbrev functionBindingGame {L : ℕ} (hn : n = 1)
(AuxState : Type)
[∀ i, SampleableType ((hn ▸ pSpec).Challenge i)]
(scheme : Scheme oSpec Data Commitment Decommitment ComKey VerifKey (hn ▸ pSpec))
(adversary :
FunctionBindingAdversary oSpec Data Commitment AuxState L (hn ▸ pSpec)
ComKey) :
OptionT ProbComp ((queryOf : Fin L → O.Query) ×
((i : Fin L) → O.Response (queryOf i)) × (Fin L → Bool)) :=
let pImpl : QueryImpl (oSpec + [(hn ▸ pSpec).Challenge]ₒ) (StateT σ ProbComp) :=
QueryImpl.addLift impl (challengeQueryImpl (pSpec := hn ▸ pSpec))
OptionT.mk do
let s ← init
let ((ck, vk), sAfterSetup) ← (simulateQ impl scheme.keygen).run s
(simulateQ pImpl <| (show OracleComp _ _ from do
let ⟨cm, queryOf, responseOf, stateOf⟩ ← liftComp (adversary.claim ck) _
let reduction := Reduction.mk (adversary.prover ck) (scheme.opening (ck, vk)).verifier
let (accepts : Option (Fin L → Bool)) ← reduction.allVerdicts
(fun i ↦
(cm, (⟨queryOf i, responseOf i⟩ : (q : O.Query) × O.Response q)))
stateOf
pure (accepts.map fun accepts ↦ (⟨queryOf, responseOf, accepts⟩ :
(queryOf : Fin L → O.Query) ×
((i : Fin L) → O.Response (queryOf i)) × (Fin L → Bool)))
)).run' sAfterSetup
/-- The probability of breaking function binding for a specific adversary. -/
def functionBindingExperiment {L : ℕ} (hn : n = 1)
(AuxState : Type)
[∀ i, SampleableType ((hn ▸ pSpec).Challenge i)]
(scheme : Scheme oSpec Data Commitment Decommitment ComKey VerifKey (hn ▸ pSpec))
(adversary :
FunctionBindingAdversary oSpec Data Commitment AuxState L (hn ▸ pSpec)
ComKey) : ℝ≥0∞ :=
Pr{let result ← functionBindingGame init impl hn AuxState scheme adversary}[
functionBindingCondition (Data := Data) result]
/-- A commitment scheme satisfies **function binding** with error `functionBindingError` if for all
adversaries that output a commitment `cm`, and a vector of length `L` of queries `q_i`, claimed
responses `r_i` to the queries, and auxiliary private states `st_i` (to be passed to the adversary
prover in the opening procedure), and for all malicious provers in the opening procedure taking in
`st_i`, the probability that:
1. The verifier accepts all `r_i` to the respective `q_i` in the opening procedure for `cm`
2. There exists no data `d` that is consistent with the claimed responses
(i.e. for all data `d`, for some `i`, `O.answer d q_i ≠ r_i`)
is at most `functionBindingError`.
Informally, function binding says it's computationally infeasible to convince the
verifier to accept responses for which no consistent (source) data exists.
Note: This is an adaptation of the function binding property introduced in [CGKY25]. -/
def functionBinding {L : ℕ} (hn : n = 1)
[∀ i, SampleableType ((hn ▸ pSpec).Challenge i)]
(scheme : Scheme oSpec Data Commitment Decommitment ComKey VerifKey (hn ▸ pSpec))
(functionBindingError : ℝ≥0) : Prop :=
∀ AuxState : Type,
∀ adversary : FunctionBindingAdversary oSpec Data Commitment AuxState L (hn ▸ pSpec) ComKey,
functionBindingExperiment init impl hn AuxState scheme adversary ≤
functionBindingError
end
end Security
end Commitment