-
Notifications
You must be signed in to change notification settings - Fork 2
/
flp.v
537 lines (444 loc) · 13.1 KB
/
flp.v
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
(** FLP Impossibility Proof **)
(** Done by Alexander Chepurnoy **)
(** Public domain **)
(** Made after original paper http://cs-www.cs.yale.edu/homes/arvind/cs425/doc/fischer.pdf **)
(** described more informally in the awesome blogpost http://the-paper-trail.org/blog/a-brief-tour-of-flp-impossibility/ **)
(** Some constructive proofs existed before, e. g. **)
(** http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.221.7907&rep=rep1&type=pdf **)
(** and http://www.cs.cornell.edu/courses/cs7412/2011sp/ConsensusRebecca.pdf **)
(** Unlike previous proofs, this one has the same model as the original paper **)
(** But instead of Lemma3, it has own constructive small-step proof of a bivalent run existence **)
Require Import Arith.
Require Import List.
Require Import Coq.Logic.Classical.
Set Implicit Arguments.
Import ListNotations.
Definition Binary := bool.
(** "Processes are modeled as automata (with possibly infinitely many states)"
For our purposes it's enough to enumerate states with some natural numbers,
encoding process identificator within a number as well, so there's bidirectional
injective mapping (process_id, state) <-> nat **)
(** Definition ProcessState := nat. **)
Parameter Process: Set.
Definition Step := nat.
Definition Configuration := list Step.
(** Abstract function returning True if some process(es) in configuration reached
final state associated with given binary value **)
Parameter decidedValue: Configuration -> Binary -> Prop.
Definition decides(cfg:Configuration):Prop := decidedValue cfg true \/ decidedValue cfg false.
(** No two processes decide differently **)
Axiom Agreement: forall cfg, ~(decidedValue cfg true /\ decidedValue cfg false).
Parameter processId: Step -> Process.
(** Configuration transition function **)
Definition stepFn(cfg:Configuration)(step:Step):Configuration := cfg ++ [step].
(** There's no change in deciding value **)
Axiom Termination: forall cfg b step, decidedValue cfg b -> decidedValue (stepFn cfg step) b.
(** A particular execution, defined by a possibly infinite sequence of events from
a starting configuration C is called a schedule and the sequence of steps taken
to realise the schedule is a run **)
Definition Schedule := list Step.
Fixpoint run (cfg:Configuration)(s:Schedule): Configuration :=
match s with
| nil => cfg
| cons step t => stepFn (run cfg t) step
end.
Axiom RunCommutativity2: forall cfg step s, run (run cfg [step]) s = run cfg (step :: s).
(** todo: proove? **)
Axiom RunCommutativity: forall cfg s1 s2, run (run cfg s1) s2 = run cfg (s1 ++ s2).
Lemma Termination1: forall cfg b s, decidedValue cfg b -> decidedValue (run cfg s) b.
Proof.
intros.
pose proof Termination as T.
unfold run.
induction s.
trivial.
auto.
Qed.
Definition true_univalent(cfg:Configuration):=
(exists s1, decidedValue(run cfg s1) true) /\ ~(exists s2, decidedValue (run cfg s2) false).
Definition false_univalent(cfg:Configuration):=
(exists s1, decidedValue(run cfg s1) false) /\ ~(exists s2, decidedValue (run cfg s2) true).
Definition univalent(cfg:Configuration):= true_univalent cfg \/ false_univalent cfg.
Definition bivalent(cfg:Configuration):= (~ decides cfg) /\
(exists s1, decidedValue (run cfg s1) false) /\ (exists s2, decidedValue (run cfg s2) true).
(** "By the total correctness of P, and the fact that there are always admissible runs, V > 0" **)
Axiom Correctness: forall cfg, bivalent cfg \/ univalent cfg.
Lemma UnNotBiv: forall cfg, univalent cfg <-> ~ bivalent cfg.
Proof.
intros cfg.
unfold bivalent.
unfold univalent.
unfold true_univalent.
unfold false_univalent.
pose proof Correctness as C.
specialize (C cfg).
tauto.
Qed.
Lemma BivNotUn: forall cfg, bivalent cfg <-> ~ univalent cfg.
Proof.
intros.
unfold bivalent.
unfold univalent.
unfold true_univalent.
unfold false_univalent.
pose proof Correctness as C.
specialize (C cfg).
tauto.
Qed.
Lemma BivalentPaths: forall cfg, bivalent cfg ->
(exists s1, false_univalent(run cfg (s1))) /\
(exists s2, true_univalent(run cfg (s2))).
Proof.
intros cfg.
pose proof Agreement as A.
pose proof Termination1 as T.
unfold bivalent. unfold false_univalent. unfold true_univalent.
intuition.
destruct H.
destruct H2.
exists x.
specialize (T (run cfg x) false).
intuition.
exists [].
trivial.
destruct H2.
specialize(T x1).
intuition.
generalize dependent H2. generalize dependent H3.
specialize (A (run (run cfg x) x1)).
tauto.
destruct H.
destruct H2.
exists x0.
specialize (T (run cfg x0) true).
intuition.
exists [].
trivial.
destruct H2.
specialize (A (run (run cfg x0) x1)).
auto.
Qed.
Lemma BivalentPaths2: forall cfg, bivalent cfg ->
(exists pid1 ps1, false_univalent(run cfg (pid1::ps1))) /\
(exists pid2 ps2, true_univalent(run cfg (pid2::ps2))).
Proof.
intros cfg.
pose proof BivalentPaths as BP.
specialize(BP cfg).
intuition.
destruct H1.
destruct x.
firstorder.
firstorder.
destruct H2.
destruct x.
firstorder.
firstorder.
Qed.
Lemma UnFNotBiv: forall cfg, false_univalent cfg -> ~ bivalent cfg.
Proof.
intros cfg.
pose proof Correctness as C.
specialize (C cfg).
pose proof BivalentPaths as B.
specialize (B cfg).
unfold univalent in C.
unfold false_univalent.
unfold bivalent.
unfold false_univalent in C.
unfold true_univalent in C.
unfold bivalent in C.
unfold false_univalent in B.
unfold true_univalent in B.
unfold bivalent in B.
tauto.
Qed.
Lemma UnTNotBiv: forall cfg, true_univalent cfg -> ~ bivalent cfg.
Proof.
intros cfg.
pose proof Correctness as C.
specialize (C cfg).
pose proof BivalentPaths as B.
specialize (B cfg).
unfold univalent in C.
unfold true_univalent.
unfold bivalent.
unfold false_univalent in C.
unfold true_univalent in C.
unfold bivalent in C.
unfold false_univalent in B.
unfold true_univalent in B.
unfold bivalent in B.
tauto.
Qed.
Lemma Correctness2: forall cfg, true_univalent cfg -> false_univalent cfg -> False.
Proof.
intros.
unfold true_univalent in H.
destruct H.
unfold false_univalent in H0.
destruct H.
destruct H0.
destruct H0.
destruct H1.
exists x0.
trivial.
Qed.
Lemma Correctness3: forall cfg, false_univalent cfg -> true_univalent cfg -> False.
Proof.
intros.
unfold false_univalent in H.
destruct H.
unfold true_univalent in H0.
destruct H.
destruct H0.
destruct H0.
destruct H1.
exists x0.
trivial.
Qed.
Lemma Correctness4: forall cfg s, false_univalent cfg -> ~ true_univalent (run cfg s).
Proof.
intros cfg s.
unfold false_univalent.
unfold true_univalent.
intuition.
destruct H.
pose proof RunCommutativity as RC.
specialize (RC cfg s x).
rewrite RC in H.
generalize dependent H.
firstorder.
Qed.
Lemma Correctness5: forall cfg ps, true_univalent cfg -> ~ false_univalent (run cfg ps).
Proof.
intros cfg ps.
unfold false_univalent.
unfold true_univalent.
intuition.
destruct H.
pose proof RunCommutativity as RC.
specialize (RC cfg ps x).
rewrite RC in H.
generalize dependent H.
firstorder.
Qed.
Axiom Correctness6: forall cfg ps, true_univalent cfg -> true_univalent (run cfg ps).
Axiom Correctness7: forall cfg ps, false_univalent cfg -> false_univalent (run cfg ps).
Lemma Lemma3: forall cfg ss, false_univalent (run cfg ss) -> bivalent cfg \/ false_univalent cfg.
Proof.
intros.
pose proof Correctness as C.
specialize(C cfg).
unfold univalent in C.
destruct C.
tauto.
pose proof Correctness5 as C5.
specialize(C5 cfg ss).
intuition.
Qed.
Lemma Lemma3C: forall cfg s ss, false_univalent (run cfg (s :: ss)) -> bivalent (run cfg [s]) \/ false_univalent (run cfg [s]).
Proof.
intros.
pose proof RunCommutativity2 as RC2.
pose proof Lemma3 as L3.
specialize (RC2 cfg s ss).
specialize (L3 (run cfg [s]) ss).
rewrite RC2 in L3.
tauto.
Qed.
Lemma Correctness9: forall cfg pid ps, true_univalent (run cfg (pid :: ps)) -> bivalent (run cfg [pid]) \/ true_univalent (run cfg [pid]).
Proof.
intros.
pose proof Correctness as C.
specialize(C (run cfg [pid])).
unfold univalent in C.
destruct C.
tauto.
pose proof Correctness4 as C4.
specialize(C4 (run cfg [pid]) ps).
intuition.
pose proof RunCommutativity2 as RC2.
specialize(RC2 cfg pid ps).
rewrite RC2 in H0.
tauto.
Qed.
Axiom Async1: forall cfg s1 s2, processId s1 <> processId s2 /\ run cfg ([s1;s2]) = run cfg ([s2;s1]).
Lemma OneStepLemmaP1: forall cfg s1 s2,
processId s1 <> processId s2 /\
false_univalent (run cfg [s1]) /\
true_univalent (run cfg [s2]) -> False.
Proof.
intuition.
pose proof RunCommutativity2 as RC.
specialize(RC cfg).
pose proof Async1 as A1.
specialize(A1 cfg s1 s2).
pose proof Correctness6 as C6.
pose proof Correctness7 as C7.
specialize (C6 (run cfg [s2]) [s1]).
rewrite RC in C6.
specialize (C7 (run cfg [s1]) [s2]).
rewrite RC in C7.
intuition.
pose proof Correctness3 as C3.
specialize(C3 (run cfg [s2; s1])).
rewrite H3 in H4.
tauto.
Qed.
Lemma Lemma1: forall cfg s1 s2,
false_univalent (run cfg [s1]) /\
true_univalent (run cfg [s2]) -> processId s1 = processId s2.
Proof.
intros cfg p1 p2.
pose proof OneStepLemmaP1 as P1.
specialize(P1 cfg p1 p2).
tauto.
Qed.
Axiom AnotherProcessStepExists: forall step, exists step0, processId step <> processId step0.
Parameter randomStep: Configuration -> Step.
Lemma BivNotUnTAndUnF: forall cfg, bivalent cfg <-> ~ true_univalent cfg /\ ~ false_univalent cfg.
Proof.
intros.
intuition.
(** CASE: true_univalent cfg **)
pose proof UnTNotBiv as UT.
specialize(UT cfg).
tauto.
(** CASE: false_univalent cfg **)
pose proof UnFNotBiv as UF.
specialize(UF cfg).
tauto.
(** CASE: opposite direction **)
apply BivNotUn.
unfold univalent.
tauto.
Qed.
Lemma Lemma2: forall cfg s1 s2, (processId s1 = processId s2 /\
true_univalent (run cfg [s1]) /\ false_univalent (run cfg [s2])) ->
forall s, processId s <> processId s1 -> bivalent (run cfg [s]).
Proof.
intuition.
apply BivNotUn.
unfold univalent.
pose proof OneStepLemmaP1 as P1.
intuition.
(** CASE : true_univalent (run cfg [step]) **)
assert(P1T := P1 cfg s2 s).
rewrite H0 in H1.
auto.
(** CASE : false_univalent (run cfg [step]) **)
assert(P1H := P1 cfg s s1).
auto.
Qed.
(** only the same process could goes to true_univalent & false_univalent states, so if we choose another process
it must be bivalent as proven by the OtherBivalent lemma **)
Lemma OneStepLemmaP3: forall cfg step1 step2, true_univalent (run cfg [step1]) /\ false_univalent (run cfg [step2]) ->
exists step: Step, bivalent (run cfg [step]).
Proof.
intros.
pose proof Lemma1 as P2.
specialize(P2 cfg step2 step1).
intuition.
assert(AP := AnotherProcessStepExists step1).
destruct AP.
pose proof Lemma2 as OB.
specialize (OB cfg step1 step2).
intuition.
rewrite H in H3.
intuition.
specialize(H3 x).
intuition.
exists x.
assumption.
Qed.
(** The main lemma, named OneStepLemma after Constable's paper **)
Lemma Lemma4: forall cfg, bivalent cfg -> exists p, bivalent (run cfg [p]).
Proof.
intros.
assert(rp := randomStep cfg).
pose proof Correctness as C.
specialize(C (run cfg [rp])).
intuition.
(** CASE: bivalent (run cfg [rp]) **)
exists rp.
assumption.
(** --CASE: bivalent (run cfg [rp]) proven **)
unfold univalent in H0.
pose proof BivalentPaths2 as B2.
specialize(B2 cfg).
destruct H0.
(** CASE: true_univalent (run cfg [rp]) - follow false_univalent path then if processes are different **)
intuition.
destruct H2.
(** if there are some steps before entering false_univalent, enter first one if processes are different or step
with other process (it should be bivalent if protocol is partially correct) **)
destruct H1.
pose proof Lemma3C as L3.
specialize(L3 cfg x x0).
intuition.
exists x.
trivial.
pose proof OneStepLemmaP3 as P3.
specialize(P3 cfg rp x).
tauto.
(** CASE: false_univalent (run cfg [rp]) - symmetrical to previous **)
intuition.
destruct H3.
destruct H1.
pose proof Correctness9 as C9.
specialize(C9 cfg x x0).
intuition.
exists x.
trivial.
pose proof OneStepLemmaP3 as P3.
specialize(P3 cfg x rp).
tauto.
Qed.
(** Not strictly corresponding to the original paper, as there's no any
process & event considered **)
Theorem FLP_Lemma4: forall cfg, bivalent cfg -> forall m, exists s, length s > m -> bivalent (run cfg s).
Proof.
intros.
pose proof Lemma4 as O.
specialize (O cfg).
intuition.
destruct H0.
exists [x].
intros.
apply H0.
Qed.
(** Initial Configuration & its properties **)
Variable InitialConfiguration: Configuration.
Axiom InitialNoConsensus: ~decides InitialConfiguration.
Axiom TrueReacheable: exists s1, decidedValue (run InitialConfiguration s1) true.
Axiom FalseReacheable: exists s2, decidedValue (run InitialConfiguration s2) false.
(** Lemma 2 from original paper **)
(** Initial configuration is bivalent **)
Theorem FLP_Lemma2: bivalent(InitialConfiguration).
Proof.
pose proof InitialNoConsensus as I.
pose proof TrueReacheable as T.
pose proof FalseReacheable as F.
unfold bivalent.
intuition.
Qed.
(** THEOREM 1. No consensus protocol is totally correct in spite of one fault. **)
(** We say that a run is deciding provided that some process eventually decides according
to the properties of consensus. The theorem says the non-deciding run of arbitrary length
is possible **)
Theorem FLP: forall m, exists s, length s > m -> ~ decides (run InitialConfiguration s).
Proof.
intros m.
pose proof FLP_Lemma2 as FL2.
pose proof FLP_Lemma4 as FL4.
specialize (FL4 InitialConfiguration).
intuition.
specialize (H m).
destruct H.
apply ex_intro with (x:=x).
generalize dependent H.
unfold bivalent.
unfold decides.
tauto.
Qed.