-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNM_unsat.ec
589 lines (506 loc) · 22.4 KB
/
CNM_unsat.ec
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
pragma Goals:printall.
require import AllCore DBool List Distr Real Int.
require WholeMsg D1D2.
(* generic type parameters *)
type pubkey, message, commitment, openingkey.
type relation = message -> message list -> bool.
(* the commitment scheme is a triple of algorithms (Gen,Commit,Verify) *)
op Gen : pubkey distr.
op Commit (pk : pubkey) (m : message) : (commitment * openingkey) distr.
op Verify : pubkey -> message * (commitment * openingkey) -> bool.
abbrev (\notin) ['a] (z : 'a) (s : 'a list) : bool = !mem s z.
(* the commitment scheme is functional *)
axiom S_correct pk m c d: pk \in Gen => (c,d) \in Commit pk m => Verify pk (m, (c, d)).
axiom S_inj pk m1 m2 c d: pk \in Gen => m1 <> m2 => (c,d) \in Commit pk m2 => !Verify pk (m1, (c, d)).
(* the commitment sampling and key generation are efficient *)
axiom Com_ll pk m : is_lossless (Commit pk m).
axiom Gen_ll : is_lossless Gen.
module type AdvNNMO = {
proc init(pk : pubkey) : message distr
proc commit(c : commitment) : relation * commitment list
proc decommit(d : openingkey) : openingkey list * message list
}.
module NNMO_G0(A : AdvNNMO) = {
var m : message
var c : commitment
proc main() : bool = {
var rel, pk, mdistr, d, cs, ds, ms;
pk <$ Gen;
mdistr <@ A.init(pk);
m <$ mdistr;
(c, d) <$ Commit pk m;
(rel, cs) <@ A.commit(c);
(ds, ms) <@ A.decommit(d);
return (forall x, x \in zip ms (zip cs ds) => Verify pk x)
/\ rel m ms
/\ c \notin cs
/\ size cs = size ds
/\ size ms = size ds
/\ cs <> [];
}
}.
module NNMO_G1(A : AdvNNMO) = {
var m : message
var n : message
var c : commitment
proc main() : bool = {
var rel, pk, mdistr, d, cs, ds, ms;
pk <$ Gen;
mdistr <@ A.init(pk);
m <$ mdistr;
n <$ mdistr;
(c, d) <$ Commit pk m;
(rel, cs) <@ A.commit(c);
(ds, ms) <@ A.decommit(d);
return (forall x, x \in zip ms (zip cs ds) => Verify pk x)
/\ rel n ms
/\ c \notin cs
/\ size cs = size ds
/\ size ms = size ds
/\ cs <> [];
}
}.
section.
op m1, m2 : message.
declare axiom m1_and_m2_diff : m1 <> m2.
clone import WholeMsg as WM with type message <- message,
type ain <- unit,
op m1 <- m1,
op m2 <- m2
proof *.
realize m1_and_m2_diff. apply m1_and_m2_diff. qed.
module A : AdvNNMO = {
var pk : pubkey
var c, c' : commitment
var d' : openingkey
proc init(x : pubkey) : message distr = {
pk <- x;
return duniform [m1 ; m2];
}
proc commit(y : commitment) : relation * commitment list = {
var rel;
c <- y;
(c', d') <$ Commit pk m1;
rel <- fun (x : message) (xs : message list)
=> x = m1 /\ head witness xs = m1;
return (rel, [c']);
}
proc decommit(d : openingkey) : openingkey list * message list = {
var c2, d2;
(c2, d2) <$ Commit pk m2;
return (if Verify pk (m1, (c, d)) then ([d'], [m1])
else ([d2], [m2]));
}
}.
local lemma g0 &m : Pr[ NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 ] = 1%r/2%r.
proof.
byphoare (_: _ ==> _) => //.
proc. inline*.
seq 5 : (NNMO_G0.m = m1) (1%r/2%r) (1%r) (1%r/2%r) (0%r).
rnd. wp. rnd. skip. progress.
rnd. wp. rnd. skip. progress.
rewrite duniformE => //=. case (m1 = m2) => b => //.
have : m1 <> m2. apply m1_and_m2_diff.
move => c => //=. rewrite b2i1 => //=.
rewrite eq_sym in b. rewrite b. rewrite b2i0 => //.
rewrite Gen_ll => //.
wp. rnd. wp. rnd. wp. rnd. skip. progress.
rewrite Com_ll => //. rewrite Com_ll => //. rewrite Com_ll => //.
hoare.
wp. rnd. wp. rnd. wp. rnd. skip. progress. progress.
qed.
(* the winning probability in terms of an event complement to the c <> c' condition *)
local lemma g0a &m : Pr[ NNMO_G0(A).main() @ &m : res ] = 1%r/2%r -
Pr[ NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'].
proof.
have : Pr[ NNMO_G0(A).main() @ &m : res ] =
Pr[ NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c <> A.c'].
byequiv(_: _ ==> _) => //. proc. inline*.
wp. rnd. wp. rnd. wp. rnd. rnd. wp. rnd. simplify.
skip. progress.
have : Verify pkL (m1, (cdL.`1, cdL.`2)).
have : (c'd'L.`1, c'd'L.`2) \in Commit pkL m1. rewrite -pairS =>//.
rewrite S_correct. apply H. rewrite -pairS. apply H3. progress.
move => h.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H3. progress.
have : x \in zip
(if Verify pkL (m1, (cdL.`1, cdL.`2)) then ([c'd'L.`2], [m1])
else ([c2d2L.`2], [m2])).`2
(zip [c'd'L.`1]
(if Verify pkL (m1, (cdL.`1, cdL.`2)) then ([c'd'L.`2], [m1])
else ([c2d2L.`2], [m2])).`1) =
x \in zip ([c'd'L.`2], [m1]).`2 (zip [c'd'L.`1] ([c'd'L.`2], [m1]).`1 ).
rewrite h => //=. progress.
have ->: x = (m1, (c'd'L.`1, c'd'L.`2)). rewrite -H12. apply H10.
rewrite S_correct. apply H. rewrite -pairS => //.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H3. progress.
rewrite H10 =>//.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H3. progress.
rewrite H10 =>//.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H3. progress.
rewrite H10 =>//.
have : Pr[ NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 ] =
Pr[ NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c' ] +
Pr[ NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c <> A.c'].
rewrite Pr[mu_split NNMO_G0.c = A.c']. reflexivity.
move => h1.
have ->: Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c <> A.c'] =
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1] -
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'].
rewrite h1.
have ->: Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'] +
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c <> A.c'] -
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'] =
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c <> A.c'].
have f1 : forall (x y : real), x + y - x = y. progress. smt.
progress. apply f1. auto.
rewrite g0 =>//.
qed.
local lemma g1 &m:
Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 ] = 1%r/4%r.
proof.
byphoare (_: _ ==> _) => //.
proc. inline*.
seq 5 : (NNMO_G1.m = m1) (1%r/2%r) (1%r/2%r) (1%r/2%r) (0%r) (mdistr = duniform[m1; m2]).
rnd. wp. rnd. skip. progress.
rnd. wp. rnd. skip. progress.
rewrite duniformE. progress.
case (m1 = m2). progress.
have : m1 <> m2. apply m1_and_m2_diff. progress. progress.
rewrite eq_sym in H. rewrite H.
rewrite b2i0 b2i1 =>//.
rewrite Gen_ll => //.
seq 1 : (NNMO_G1.n = m1) (1%r/2%r) (1%r) (1%r/2%r) (0%r) (mdistr = duniform[m1; m2] /\ NNMO_G1.m = m1).
rnd. skip. progress.
rnd. skip. progress.
rewrite duniformE. progress.
case (m1 = m2). progress.
have : m1 <> m2. apply m1_and_m2_diff. progress. progress.
rewrite eq_sym in H. rewrite H.
rewrite b2i0 b2i1 =>//.
wp. rnd. wp. rnd. wp. rnd. skip. progress.
rewrite Com_ll =>//. rewrite Com_ll =>//. rewrite Com_ll =>//.
hoare.
wp. rnd. wp. rnd. wp. rnd. skip. progress.
progress. hoare.
wp. rnd. wp. rnd. wp. rnd. rnd. skip. progress. rewrite H.
progress. progress.
qed.
(* the winning probability in terms of an event complement to the c <> c' condition *)
local lemma g1a &m:
Pr[ NNMO_G1(A).main() @ &m : res ] = 1%r/4%r
- Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c'].
proof.
have : Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c <> A.c'] =
Pr[ NNMO_G1(A).main() @ &m : res ].
byequiv(_: _ ==> _) => //.
proc. inline*.
wp. rnd. wp. rnd. wp. rnd. rnd. rnd. wp. rnd.
skip. progress.
have : Verify pkL (m1, (cdL.`1, cdL.`2)).
have : (cdL.`1, cdL.`2) \in Commit pkL m1. rewrite -pairS =>//.
rewrite S_correct. apply H. rewrite -pairS. apply H5. progress. move => h1.
have : x \in zip
(if Verify pkL (m1, (cdL.`1, cdL.`2)) then ([c'd'L.`2], [m1])
else ([c2d2L.`2], [m2])).`2
(zip [c'd'L.`1]
(if Verify pkL (m1, (cdL.`1, cdL.`2)) then ([c'd'L.`2], [m1])
else ([c2d2L.`2], [m2])).`1) =
x \in zip ([c'd'L.`2], [m1]).`2 (zip [c'd'L.`1] ([c'd'L.`2], [m1]).`1 ).
rewrite h1 =>//=. progress.
have : x = (m1, (c'd'L.`1, c'd'L.`2)). rewrite -H13. apply H12. progress.
rewrite S_correct. apply H. rewrite -pairS. apply H7.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H5. progress. rewrite H12 =>//.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H5. progress. rewrite H12 =>//.
have : Verify pkL (m1, (cdL.`1, cdL.`2)). rewrite S_correct.
apply H. rewrite -pairS. apply H5. progress. rewrite H12 =>//.
case (mL = m1). auto.
move => H16.
have : mL = m2.
rewrite supp_duniform mem_seq2 in H1.
elim H1 => [mL1 | mL2] => //.
move => mLem2.
have : Verify pkL (mL, (cdL.`1, cdL.`2)). apply S_correct. apply H0. rewrite -pairS. rewrite H5.
progress. rewrite mLem2. rewrite S_correct. apply H. rewrite -pairS. rewrite -mLem2 H5. smt.
have : Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 ] =
Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c' ] +
Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c <> A.c'].
rewrite Pr[mu_split NNMO_G1.c = A.c'].
have ->: Pr[NNMO_G1(A).main() @ &m : (NNMO_G1.m = m1 /\ NNMO_G1.n = m1) /\ NNMO_G1.c = A.c']
= Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c'].
rewrite Pr[mu_eq]. progress. auto.
have ->: Pr[NNMO_G1(A).main() @ &m : (NNMO_G1.m = m1 /\ NNMO_G1.n = m1) /\ NNMO_G1.c <> A.c']
= Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c <> A.c'].
rewrite Pr[mu_eq]. progress. auto.
progress. move => b.
have ->: Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c'] =
Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1] -
Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c <> A.c'].
rewrite b. smt.
rewrite g1.
have ->: 1%r / 4%r -
(1%r / 4%r - Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c <> A.c']) =
Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c <> A.c']. smt.
progress. rewrite H. auto.
qed.
local lemma df &m:
1%r/4%r -
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'] +
Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c'] =
Pr[ NNMO_G0(A).main() @ &m : res ] - Pr[ NNMO_G1(A).main() @ &m : res ].
proof.
have : Pr[ NNMO_G0(A).main() @ &m : res ] - Pr[ NNMO_G1(A).main() @ &m : res ] =
1%r / 4%r - Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'] +
Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c'].
rewrite g0a g1a. smt.
move => h6. rewrite h6. auto.
qed.
local module N1 = {
var n : message
var m : message
var c : commitment
proc main() : bool = {
var pk, x, mdistr, rel0, rel, cs, ms, ds, d, y, d0, c2, d2;
pk <$ Gen;
x <- pk;
A.pk <- x;
mdistr <- duniform [m1; m2];
NNMO_G1.m <$ mdistr;
NNMO_G1.n <$ mdistr;
(NNMO_G1.c, d) <$ Commit pk NNMO_G1.m;
y <- NNMO_G1.c;
A.c <- y;
(A.c', A.d') <$ Commit A.pk m1;
rel0 <- fun (x0 : message) (xs : message list) => x0 = m1 /\ head witness xs = m1;
(rel, cs) <- (rel0, [A.c']);
d0 <- d;
(c2, d2) <$ Commit A.pk m2;
(ds, ms) <- if Verify A.pk (m1, (A.c, d0)) then ([A.d'], [m1])
else ([d2], [m2]);
return (forall x, x \in zip ms (zip cs ds) => Verify pk x)
/\ rel n ms
/\ c \notin cs
/\ size cs = size ds
/\ size ms = size ds
/\ cs <> [];
}
}.
local module N2 = {
proc main() : bool = {
var pk, x, mdistr, rel0, rel, cs, ms, ds, d, y, d0, c2, d2;
pk <$ Gen;
x <- pk;
A.pk <- x;
mdistr <- duniform [m1; m2];
NNMO_G1.m <$ mdistr;
NNMO_G1.n <$ mdistr;
(NNMO_G1.c, d) <$ Commit pk NNMO_G1.m;
y <- NNMO_G1.c;
A.c <- y;
(A.c', A.d') <$ Commit A.pk m1;
rel0 <- fun (x0 : message) (xs : message list) => x0 = m1 /\ head witness xs = m1;
(rel, cs) <- (rel0, [A.c']);
d0 <- d;
(c2, d2) <$ Commit A.pk m2;
(ds, ms) <- if Verify A.pk (m1, (A.c, d0)) then ([A.d'], [m1])
else ([d2], [m2]);
return NNMO_G1.m = m1
/\ NNMO_G1.n = m1
/\ NNMO_G1.c = A.c';
}
}.
local lemma n &m:
Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c' ] =
Pr[ N2.main() @ &m : res].
proof.
byequiv =>//. proc. inline*.
wp. rnd. wp. rnd. wp. rnd. rnd. rnd. wp. rnd.
skip. progress.
qed.
local module N1T = {
proc main(mm : message,a:unit) : bool = {
var pk, x, mdistr, rel0, rel, cs, ms, ds, d, y, d0, c2, d2;
NNMO_G1.n <- mm;
pk <$ Gen;
x <- pk;
A.pk <- x;
mdistr <- duniform [m1; m2];
NNMO_G1.m <$ mdistr;
(NNMO_G1.c, d) <$ Commit pk NNMO_G1.m;
y <- NNMO_G1.c;
A.c <- y;
(A.c', A.d') <$ Commit A.pk m1;
rel0 <- fun (x0 : message) (xs : message list) => x0 = m1 /\ head witness xs = m1;
(rel, cs) <- (rel0, [A.c']);
d0 <- d;
(c2, d2) <$ Commit A.pk m2;
(ds, ms) <- if Verify A.pk (m1, (A.c, d0)) then ([A.d'], [m1])
else ([d2], [m2]);
return NNMO_G1.m = m1
/\ NNMO_G1.n = m1
/\ NNMO_G1.c = A.c';
}
}.
local module NN = {
proc main() = {
var n, r;
n <$ duniform [m1; m2];
r <@ N1T.main(n,tt);
return r;
}
}.
local lemma gg &m:
Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c' ] =
Pr[ N1.main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c' ].
proof.
byequiv => //. proc. inline*.
wp. rnd. wp. rnd. wp. rnd. rnd. rnd. wp. rnd.
skip. progress.
qed.
local lemma gg1 &m :
Pr[ N2.main() @ &m : res ] =
Pr[ NN.main() @ &m : res ].
proof.
byequiv =>//. proc. inline*.
wp. rnd. wp. rnd.
swap{2} 4 4.
swap{2} 9 -1.
swap{2} 2 6.
wp. swap {2} 1 6. rnd. wp. rnd. rnd. wp. rnd. wp.
skip. progress.
qed.
local lemma gg3 &m :
Pr[ N2.main() @ &m : res ] =
1%r/2%r * Pr[ N1T.main(m1,tt) @ &m : res ] +
1%r/2%r * Pr[ N1T.main(m2,tt) @ &m : res ].
proof.
have : Pr[ N2.main() @ &m : res ]
= Pr[ W(N1T).main() @ &m : res ].
byequiv => //. proc. inline*.
wp.
swap{2} 4 4.
swap{2} 3 4.
swap{2} 2 4. swap{2} 1 4.
rnd. wp. rnd. swap{1} 6 -1. wp. rnd. rnd. wp. rnd. wp. rnd.
skip. progress.
move => H. rewrite H.
apply (splitcases N1T).
qed.
local lemma gg4 &m :
Pr[ NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c' ] =
1%r/2%r * Pr[ N1T.main(m1,tt) @ &m : res ] +
1%r/2%r * Pr[ N1T.main(m2,tt) @ &m : res ].
proof.
rewrite n gg3. reflexivity.
qed.
local lemma g &m:
Pr[NNMO_G1(A).main() @ &m : NNMO_G1.m = m1 /\ NNMO_G1.n = m1 /\ NNMO_G1.c = A.c'] =
1%r/2%r * Pr[N1T.main(m1,tt) @ &m : res].
proof.
rewrite gg4.
have ->: Pr[N1T.main(m2,tt) @ &m : res] = 0%r.
byphoare(_: arg = (m2, tt) ==> _) => //. hoare.
proc.
inline*.
wp. rnd. wp. rnd. wp. rnd. rnd. wp. rnd. wp.
skip. progress.
rewrite !negb_and.
have : m1 <> m2. apply m1_and_m2_diff. rewrite eq_sym.
move => H4. rewrite H4. progress.
apply invr0.
qed.
(* the probability of c = c' can be assumed to be negligible for any realistic commitment scheme with sufficient randomness *)
module Q = {
var c, c' : commitment
proc main(m : message, a : unit) : bool = {
var pk, d, d';
pk <$ Gen;
(c, d) <$ Commit pk m;
(c', d') <$ Commit pk m;
return c = c';
}
}.
local module G = {
var m : message
proc main() : bool = {
var v;
m <$ duniform [m1; m2];
v <@ Q.main(m,tt);
return v;
}
}.
local lemma splitG &m:
Pr[ G.main() @ &m : res ]
= 1%r/2%r * Pr[ Q.main(m1,tt) @ &m : res ]
+ 1%r/2%r * Pr[ Q.main(m2,tt) @ &m : res ].
proof.
have : Pr[ G.main() @ &m : res ] = Pr[ W(Q).main() @ &m : res ].
byequiv => //. proc. inline*. sim.
move => H. rewrite H.
apply (splitcases Q).
qed.
local lemma h &m:
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'] =
1%r/2%r * Pr[ Q.main(m1,tt) @ &m : res].
proof.
have ->: Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'] = Pr[ G.main() @ &m : res /\ G.m = m1 ].
byequiv =>//. proc. inline*.
swap {2} 4 -3. swap {2} 4 -2. wp.
seq 5 3 : (pk{1} \in Gen /\ ={pk} /\ A.pk{1} = pk{1} /\ mdistr{1} = duniform [m1; m2] /\ NNMO_G0.m{1} \in duniform [m1; m2] /\ G.m{2} \in duniform [m1; m2] /\ NNMO_G0.m{1} = G.m{2}).
rnd. wp. rnd. skip. progress. sp.
case(m{2} = m2).
conseq (_: _ ==> NNMO_G0.m{1} <> m1 /\ G.m{2} <> m1). progress.
rnd. wp. rnd {1}. wp. rnd. skip. progress. rewrite Com_ll. rewrite eq_sym. apply m1_and_m2_diff.
rewrite eq_sym. apply m1_and_m2_diff.
rnd{1}. wp. rnd. wp. rnd. skip. progress.
have : G.m{2} = m1. smt.
smt. smt. rewrite Com_ll.
byphoare(_: (glob Q) = (glob Q){m} ==> _) =>//.
pose z := Pr[Q.main(m1,tt) @ &m : res].
proc.
seq 1 : (G.m = m1) (1%r/2%r) z (1%r/2%r) 0%r.
rnd. skip. progress.
rnd. skip. progress.
rewrite duniformE. progress.
case (m1 = m2). progress.
have : m1 <> m2. apply m1_and_m2_diff. progress. progress.
rewrite eq_sym in H. rewrite H.
rewrite b2i0 b2i1 =>//.
have phr : phoare[ Q.main : arg = (m1,tt) ==> res ] = Pr[Q.main(m1,tt) @ &m : res].
bypr. progress. byequiv. proc.
rnd. rnd. rnd.
skip. progress.
have : m{m0} = m1. rewrite H. rewrite fst_pair. auto.
move => H6. rewrite H6. auto. smt. smt. smt. progress.
call phr.
skip. progress.
hoare. call(_:true). wp. rnd. wp. rnd. rnd.
skip. progress.
skip. progress.
have ->: G.m{hr} <> m1. apply H. auto.
progress.
qed.
(* the advantage of adversary is 1/4 - 1/4 * negligible *)
lemma cnm_unsat &m:
1%r/4%r -
1%r/4%r * Pr[ Q.main(m1,tt) @ &m : res ] =
`|Pr[ NNMO_G0(A).main() @ &m : res ] - Pr[ NNMO_G1(A).main() @ &m : res ]|.
proof.
rewrite -df g. progress.
have ->: Pr[N1T.main(m1,tt) @ &m : res] =
Pr[NNMO_G0(A).main() @ &m : NNMO_G0.m = m1 /\ NNMO_G0.c = A.c'].
byequiv(_: _ ==> _) => //. proc. inline*.
wp. rnd. wp. rnd.
wp. rnd. rnd. wp. rnd. wp.
skip. progress.
rewrite h.
have ->: (inv 4%r - 1%r / 2%r * Pr[Q.main(m1,tt) @ &m : res] + 1%r / 2%r * Pr[Q.main(m1,tt) @ &m : res] / 2%r) =
(inv 4%r - 1%r / 4%r * Pr[Q.main(m1,tt) @ &m : res]). smt.
progress. smt.
qed.