-
Notifications
You must be signed in to change notification settings - Fork 0
/
Refinement.v
3642 lines (3527 loc) · 96 KB
/
Refinement.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
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* Refinement Theorem *)
Require Import Program Arith PeanoNat List CpdtTactics EquivDec.
Require Import Assumption Quorum Low_def High_def High_proof Temporal.
(* Low-level Lemmas *)
Definition extract_decision (i : nat) (gs : GlobalState) :=
match (local_states gs) i with
| Some (Honest ls) => decision ls
| None => None
end.
Definition extract_history (i : nat) (gs : GlobalState) :=
match (local_states gs) i with
| Some (Honest ls) => Some (history ls (hl_round_no ls))
| None => None
end.
Definition extract_historyr (i : nat) (gs : GlobalState) (r : nat) :=
match (local_states gs) i with
| Some (Honest ls) => Some (history ls r)
| None => None
end.
Definition extract_historyrj (i : nat) (gs : GlobalState) (r : nat) (j : nat):=
match (local_states gs) i with
| Some (Honest ls) => history ls r j
| None => None
end.
Definition extract_estimationr (i : nat) (gs : GlobalState) (r : nat) :=
match (local_states gs) i with
| Some (Honest ls) => (estimation ls r)
| None => None
end.
Definition extract_estimationr' (i : nat) (r : nat) (gs : GlobalState) :=
match (local_states gs) i with
| Some (Honest ls) => (estimation ls r)
| None => None
end.
Lemma extract_estimationr_eqiv : forall i r gs, extract_estimationr i gs r = extract_estimationr' i r gs.
Proof.
crush.
Qed.
Definition extract_round (i : nat) (gs : GlobalState) :=
match (local_states gs) i with
| Some (Honest ls) => Some (hl_round_no ls)
| None => None
end.
Ltac forget v :=
match goal with
| [Heq : v = ?v' |- _] => repeat (
match goal with
| [H : context[v] |- _] => rewrite Heq in H
end) ; clear v Heq
| [Heq : ?v' = v |- _] => repeat (
match goal with
| [H : context[v] |- _] => rewrite <- Heq in H
end) ; clear v Heq
end.
Definition EqDecOptionMSG : EqDec (option Message) eq.
assert (EqDec bool eq).
crush.
assert (EqDec nat eq).
crush.
assert (EqDec (option bool) eq).
unfold EqDec.
intros.
destruct x ; destruct y ; try destruct b ; try destruct b0 ; try (left ; reflexivity) ; try (right ; discriminate).
assert (EqDec Message eq).
unfold EqDec.
intros.
destruct x ; destruct y.
destruct (X0 sender_id sender_id0).
destruct (X0 receiver_id receiver_id0).
destruct (X0 m_round_no m_round_no0).
destruct (X1 vote vote0).
left.
congruence.
right.
congruence.
right.
congruence.
right.
congruence.
right.
congruence.
unfold EqDec.
intros.
destruct x ; destruct y.
destruct (X2 m m0).
left.
congruence.
right.
congruence.
right.
discriminate.
right.
discriminate.
left.
reflexivity.
Defined.
(* V = Validity
S' = Step
S = Steps
D = Decision
E = Estimate
R = Round
H = History
M = Message
L = Delivery
T = State
C = Condition
Q = Quorum
I = Initial
_ = Arrow
c? = exact step ? changed
l? = local ?
g? = global ?
?p = ?'s properties
eq = equality
*)
(* Misc *)
Lemma Lem_I_D : forall params i, extract_decision i (initGS params) = None.
Proof.
intros.
unfold extract_decision.
unfold initGS.
unfold initLS.
simpl.
destruct (i <? f_to_n (numf params)) ; auto.
Qed.
Lemma Lem_obp : forall s : option bool, s <> None -> exists b, s = Some b.
Proof.
intros.
destruct s.
exists b.
auto.
congruence.
Qed.
(* Quorum Operations *)
Lemma Lem_ch'f_i : forall n q b, check_quorum_infer' n q b = false ->
exists i, i < n /\ q i = true /\ b i = false.
Proof.
intros.
induction n.
- inversion H.
- unfold check_quorum_infer' in H.
remember (q n) as qn0.
remember (b n) as bn0.
destruct qn0.
destruct bn0.
fold check_quorum_infer' in H.
specialize (IHn H).
destruct IHn.
exists x.
crush.
exists n.
auto.
fold check_quorum_infer' in H.
specialize (IHn H).
destruct IHn.
exists x.
crush.
Qed.
Lemma Lem_ch't_i : forall n q b i, check_quorum_infer' n q b = true -> i < n -> q i = true ->
b i = true.
Proof. intros.
induction n.
- inversion H0.
- inversion H0.
unfold check_quorum_infer' in H.
rewrite H3 in H1.
rewrite H1 in H.
remember (b n) as bn0.
destruct bn0.
auto.
auto.
unfold check_quorum_infer' in H.
destruct (q n).
destruct (b n).
fold check_quorum_infer' in H.
apply IHn ; auto.
inversion H.
fold check_quorum_infer' in H.
apply IHn ; auto.
Qed.
Lemma Lem_ch_i : forall n q b b0, check_quorum_infer n q b = Some b0 ->
exists i, i < n /\ q i = true /\ b i = Some b0.
Proof.
intros.
unfold check_quorum_infer in H.
remember (fun i : nat => match b i with
| Some true => true
| Some false => false
| None => false
end) as bt.
remember (fun i : nat => match b i with
| Some true => false
| Some false => true
| None => false
end) as bf.
remember (check_quorum_infer' n q bt) as cbt.
remember (check_quorum_infer' n q bf) as cbf.
destruct cbt.
destruct cbf.
inversion H.
specialize (Lem_ch'f_i n q bf (eq_sym Heqcbf)).
intros.
destruct H0.
destruct H0.
destruct H1.
specialize (Lem_ch't_i n q bt x (eq_sym Heqcbt) H0 H1).
intros.
assert (b x = Some true).
rewrite Heqbt in H3.
destruct (b x) ; auto.
destruct b1 ; congruence.
inversion H3.
exists x.
crush.
destruct cbf.
specialize (Lem_ch'f_i n q bt (eq_sym Heqcbt)).
intros.
destruct H0.
destruct H0.
destruct H1.
specialize (Lem_ch't_i n q bf x (eq_sym Heqcbf) H0 H1).
intros.
assert (b x = Some false).
rewrite Heqbf in H3.
destruct (b x) ; auto.
destruct b1 ; congruence.
inversion H3.
exists x.
crush.
inversion H.
Qed.
Lemma Lem_chi_beq : forall n q b b0 k, check_quorum_infer n q b = Some b0 -> k < n -> q k = true ->
b k = Some b0.
Proof.
intros.
unfold check_quorum_infer in H.
remember (fun i : nat => match b i with
| Some true => true
| Some false => false
| None => false
end) as bt.
remember (fun i : nat => match b i with
| Some true => false
| Some false => true
| None => false
end) as bf.
remember (check_quorum_infer' n q bt) as cbt.
remember (check_quorum_infer' n q bf) as cbf.
destruct cbt.
destruct cbf.
inversion H.
specialize (Lem_ch't_i n q bt k (eq_sym Heqcbt) H0 H1).
intros.
rewrite Heqbt in H2.
destruct (b k) ; auto.
destruct b1 ; congruence.
inversion H2.
destruct cbf.
specialize (Lem_ch't_i n q bf k (eq_sym Heqcbf) H0 H1).
intros.
rewrite Heqbf in H2.
destruct (b k) ; auto.
destruct b1 ; congruence.
inversion H2.
inversion H.
Qed.
Lemma Lem_ich_tsab : forall n m sqs h b i, i < m -> check_quorum_infer n (sqs i) (filter h) = Some b -> exists b', testall n m sqs h = Some b'.
Proof.
intros.
induction m.
inversion H.
inversion H.
unfold testall.
unfold testone.
exists b.
rewrite H2 in H0.
rewrite H0.
auto.
unfold testall.
destruct (testone n (sqs m) h).
exists b0.
auto.
fold testall.
apply IHm ; auto.
Qed.
Lemma Lem_tsok_M : forall n b h sq k, testone n sq h = Some b -> k < n -> sq k = true ->
exists m, h k = Some m /\ vote m = Some b.
Proof.
intros.
unfold testone in H.
remember (filter h) as f.
specialize (Lem_chi_beq n sq f b k H H0 H1).
intros.
rewrite Heqf in H2.
unfold filter in H2.
destruct (h k).
exists m.
destruct m ; auto ; destruct vote ; auto.
inversion H2.
Qed.
Lemma Lem_tso_k : forall n sq h b, testone n sq h = Some b -> exists k, k < n /\ sq k = true.
Proof.
intros.
unfold testone in H.
specialize (Lem_ch_i n sq (filter h) b H).
intros.
destruct H0.
exists x.
tauto.
Qed.
Lemma Lem_tsa_i : forall n m sq h b, testall n m sq h = Some b -> exists i, i < m /\ testone n (sq i) h = Some b.
Proof.
intros.
unfold testall in H.
induction m.
- inversion H.
- rename sq into sq0.
remember (testone n (sq0 m) h) as sq.
destruct sq.
+ exists m.
crush.
+ remember (IHm H) as H1.
clear HeqH1.
destruct H1.
exists x.
crush.
Qed.
Lemma Lem_S_S' : forall gs gs', gs <<= gs' -> step gs <<= step gs'.
Proof.
intros.
induction H.
constructor.
constructor.
auto.
Qed.
Lemma Lem_S'_R : forall gs, round_no gs = round_no (step gs) \/ S (round_no gs) = round_no (step gs).
Proof.
intros.
unfold step.
destruct (get_undelivered (n gs) (message_archive gs (round_no gs)) (delivered gs (round_no gs)));
crush.
Qed.
Lemma Lem_S_R : forall gs gs', gs <<= gs' -> round_no gs <= round_no gs'.
Proof.
intros.
induction H.
auto.
pose proof (Lem_S'_R s').
crush.
Qed.
Lemma Lem_S_S : forall gs gs' gs'', gs <<= gs' -> gs <<= gs'' -> gs' <<= gs'' \/ gs'' <<= gs'.
Proof.
intros.
generalize dependent gs''.
induction H.
- intros.
left ; auto.
- intros.
specialize (IHLow_leq gs'' H0).
destruct IHLow_leq.
+ inversion H1.
right.
constructor.
constructor.
left.
apply (Lem_S_S' s' s'0 H2).
+ right.
constructor.
auto.
Qed.
Lemma Lem_Rlt_S : forall gs gs' gs'', gs <<= gs' -> gs <<= gs'' -> (round_no gs' < round_no gs'') -> gs' <<= gs''.
Proof.
intros.
pose proof (Lem_S_S gs gs' gs'' H H0).
destruct H2.
- auto.
- pose proof (Lem_S_R gs'' gs' H2).
crush.
Qed.
Lemma Lem_S'_M : forall gs ls i j eb, step_round (n gs) (CQ gs) (local_states gs) i = Some (Honest ls) -> estimation ls (hl_round_no ls) = Some eb ->
exists m, step_message (n gs) (step_round (n gs) (CQ gs) (local_states gs)) i j = Some m /\ vote m = Some eb.
Proof.
intros.
unfold step_message.
rewrite H.
exists (step_message_from_to (Honest ls) i j).
split.
reflexivity.
unfold step_message_from_to.
simpl.
auto.
Qed.
Lemma Lem_S'_Heq : forall gs r i, round_no gs < round_no (step gs) -> extract_historyr i gs r = extract_historyr i (step gs) r.
Proof.
intros.
remember (step gs) as gs'.
unfold step in Heqgs'.
destruct (get_undelivered (n gs) (message_archive gs (round_no gs)) (delivered gs (round_no gs))).
rewrite Heqgs' in H.
crush.
rewrite Heqgs'.
unfold extract_historyr.
simpl.
unfold step_round.
destruct (local_states gs i).
destruct l.
unfold step_round_loc.
destruct (estimation ls (hl_round_no ls + 1)).
auto.
auto.
auto.
Qed.
Lemma Lem_S_neq : forall gs gs', gs <<= gs' -> (n gs = n gs').
Proof.
intros.
specialize (Low_Level_Monotonicity gs gs' H).
unfold Low_mono.
tauto.
Qed.
Lemma Lem_S_Deq : forall gs gs' i b, gs <<= gs' -> extract_decision i gs = Some b -> extract_decision i gs' = Some b.
Proof.
intros.
specialize (Low_Level_Monotonicity gs gs' H).
intros.
destruct H1.
destruct H2.
destruct H3.
destruct H4.
destruct H5.
unfold extract_decision in H0.
unfold extract_decision.
remember (local_states gs i) as ls.
destruct ls.
destruct l.
specialize (H5 i (Honest ls) (eq_sym Heqls)).
destruct H5.
destruct H5.
rewrite H5.
unfold LowL_mono in H7.
destruct x.
crush.
congruence.
Qed.
Lemma Lem_S_Eeq : forall gs gs' r i b, gs <<= gs' -> extract_estimationr i gs r = Some b -> extract_estimationr i gs' r = Some b.
Proof.
intros.
specialize (Low_Level_Monotonicity gs gs' H).
intros.
destruct H1.
destruct H2.
destruct H3.
destruct H4.
destruct H5.
unfold extract_estimationr in H0.
unfold extract_estimationr.
remember (local_states gs i) as ls.
destruct ls.
destruct l.
specialize (H5 i (Honest ls) (eq_sym Heqls)).
destruct H5.
destruct H5.
rewrite H5.
destruct x.
unfold LowL_mono in H7.
destruct H7.
destruct H8.
destruct H9.
apply (H9 r b H0).
inversion H0.
Qed.
Lemma Lem_SR_Eeq : forall gs gs' r i b, gs <<= gs' -> round_no gs = round_no gs' -> extract_estimationr i gs' r = Some b -> extract_estimationr i gs r = Some b.
Proof.
intros.
induction H.
- auto.
- assert (round_no s = round_no s').
specialize (Lem_S'_R s').
intros.
assert (round_no s <= round_no s').
specialize (Low_Level_Monotonicity s s' H).
intros.
destruct H3.
auto.
destruct H2 ; crush.
rewrite IHLow_leq ; auto.
remember (step s') as s''.
unfold step in Heqs''.
destruct (get_undelivered (n s') (message_archive s' (round_no s')) (delivered s' (round_no s'))).
rewrite Heqs'' in H1.
rewrite <- H1.
unfold extract_estimationr.
unfold step_deliver.
simpl.
remember (i =? receiver_id m) as isreceiver.
destruct isreceiver.
assert (i = receiver_id m).
eapply (beq_nat_true).
auto.
rewrite <- H3.
destruct (local_states s' i).
destruct l.
unfold step_deliver_loc.
simpl.
auto.
auto.
auto.
rewrite Heqs'' in H0.
simpl in H0.
crush.
Qed.
Lemma Lem_S_gM0eq : forall gs gs' i j, gs <<= gs' -> message_archive gs 0 i j = message_archive gs' 0 i j.
Proof.
intros.
induction H.
- reflexivity.
- rewrite IHLow_leq.
unfold step.
destruct (get_undelivered (n s') (message_archive s' (round_no s')) (delivered s' (round_no s'))).
+ reflexivity.
+ simpl.
unfold update_messages.
assert (0 =? round_no s' + 1 = false).
apply (beq_nat_false_iff).
crush.
rewrite H0.
reflexivity.
Qed.
Lemma Lem_S_gE0eq : forall gs gs' i, gs <<= gs' -> extract_estimationr i gs 0 = extract_estimationr i gs' 0.
Proof.
intros.
induction H.
- reflexivity.
- rewrite IHLow_leq.
unfold step.
unfold extract_estimationr.
destruct (get_undelivered (n s') (message_archive s' (round_no s')) (delivered s' (round_no s'))).
+ simpl.
unfold step_deliver.
remember (i =? receiver_id m) as isreceiver.
destruct isreceiver.
assert (i = receiver_id m).
eapply (beq_nat_true).
auto.
rewrite <- H0.
destruct (local_states s' i).
destruct l.
unfold step_deliver_loc.
simpl.
auto.
auto.
auto.
+ simpl.
unfold step_round.
unfold step_round_loc.
destruct (local_states s' i).
destruct l.
assert (0 =? hl_round_no ls + 1 = false).
apply (beq_nat_false_iff).
crush.
destruct (estimation ls (hl_round_no ls + 1)).
auto.
simpl.
destruct (hl_round_no ls + 1).
inversion H0.
auto.
auto.
Qed.
Lemma Lem_S_Heq : forall gs gs' r i j m, gs <<= gs' -> extract_historyrj i gs r j = Some m -> extract_historyrj i gs' r j = Some m.
Proof.
intros.
specialize (Low_Level_Monotonicity gs gs' H).
intros.
destruct H1.
destruct H2.
destruct H3.
destruct H4.
destruct H5.
unfold extract_historyrj in H0.
unfold extract_historyrj.
remember (local_states gs i) as ls.
destruct ls.
destruct l.
specialize (H5 i (Honest ls) (eq_sym Heqls)).
destruct H5.
destruct H5.
rewrite H5.
destruct x.
unfold LowL_mono in H7.
destruct H7.
destruct H8.
destruct H9.
destruct H10.
apply (H10 r j m H0).
inversion H0.
Qed.
Lemma Lem_SR_cR : forall gs gs', gs <<= gs' -> (round_no gs < round_no gs') -> exists gs'', gs <<= gs'' /\ gs'' <<= gs' /\ (S (round_no gs) = round_no gs'').
Proof.
intros.
induction H.
crush.
inversion H0.
- exists (step s').
split.
apply (transit s s' (step s') H (succ s')).
split.
eapply reflex.
auto.
- assert (round_no s < (round_no s')).
specialize (Lem_S'_R s').
intros.
destruct H3.
crush.
crush.
specialize (IHLow_leq H3).
destruct IHLow_leq.
exists x.
crush.
apply (transit x s' (step s') H4 (succ s')).
Qed.
Lemma Lem_D_H : forall gs i b, extract_decision i gs = Some b -> exists h, extract_history i gs = Some h.
Proof.
intros.
unfold extract_decision in H.
unfold extract_history.
destruct (local_states gs i).
destruct l.
exists (history ls (hl_round_no ls)).
auto.
inversion H.
Qed.
Lemma Lem_cD_R : forall gs i b, extract_decision i gs = None -> extract_decision i (step gs) = Some b -> round_no gs = round_no (step gs).
Proof.
intros.
remember (step gs) as gs'.
unfold step in Heqgs'.
remember (get_undelivered (n gs) (message_archive gs (round_no gs)) (delivered gs (round_no gs))) as sm.
destruct sm.
- rewrite Heqgs'.
auto.
- rewrite Heqgs' in H0.
unfold extract_decision in H.
unfold extract_decision in H0.
simpl in H0.
unfold step_round in H0.
destruct (local_states gs i).
unfold step_round_loc in H0.
destruct l.
destruct (estimation ls (hl_round_no ls + 1)).
simpl in H0.
congruence.
simpl in H0.
congruence.
inversion H0.
Qed.
Lemma Lem_cDH_Q : forall gs i b h, extract_decision i gs = None -> extract_decision i (step gs) = Some b ->
extract_history i (step gs) = Some h ->
exists qi, qi < coq_m (CQ (step gs)) /\ testone (n (step gs)) (coq_sq (CQ (step gs)) qi) h = Some b.
Proof.
intros.
specialize (Lem_cD_R gs i b H H0).
intros.
assert (n gs = n (step gs)).
specialize (Low_Level_Monotonicity gs (step gs) (succ gs)).
intros.
unfold Low_mono in H3.
crush.
assert (CQ gs = CQ (step gs)).
specialize (Low_Level_Monotonicity gs (step gs) (succ gs)).
intros.
unfold Low_mono in H4.
crush.
rewrite <- H3.
rewrite <- H4.
clear H3 H4.
remember (step gs) as gs'.
unfold step in Heqgs'.
remember (get_undelivered (n gs) (message_archive gs (round_no gs)) (delivered gs (round_no gs))) as sm.
destruct sm.
- rewrite Heqgs' in H0.
unfold extract_decision in H0.
simpl in H0.
unfold extract_history in H1.
rewrite Heqgs' in H1.
simpl in H1.
remember (step_deliver (n gs) (CQ gs) (local_states gs) m i) as ls'.
destruct ls'.
+ destruct l.
unfold step_deliver in Heqls'.
remember (i =? receiver_id m) as is_receiver.
destruct is_receiver.
* assert ((i =? receiver_id m) = true).
auto.
specialize (beq_nat_true i (receiver_id m) H3).
intros.
rewrite <- H4 in Heqls'.
remember (local_states gs i) as ls0.
destruct ls0.
{
unfold step_deliver_loc in Heqls'.
unfold extract_decision in H.
rewrite <- Heqls0 in H.
destruct l.
rewrite H in Heqls'.
inversion Heqls'.
clear Heqls'.
rewrite H6 in H0.
simpl in H0.
rewrite H6 in H1.
simpl in H1.
inversion H1.
rewrite H7 in H0.
clear H1 H6.
rewrite H7.
unfold decide in H0.
destruct (CQ gs).
simpl.
eapply (Lem_tsa_i).
assumption.
}
inversion Heqls'.
* unfold extract_decision in H.
rewrite <- Heqls' in H.
congruence.
+ inversion H0.
- destruct gs'.
inversion Heqgs'.
simpl in H2.
crush.
Qed.
Lemma Lem_cD_Q : forall gs i b, extract_decision i gs = None -> extract_decision i (step gs) = Some b ->
exists h, extract_history i (step gs) = Some h
/\ exists qi, qi < coq_m (CQ (step gs)) /\ testone (n (step gs)) (coq_sq (CQ (step gs)) qi) h = Some b.
Proof.
intros.
destruct (Lem_D_H (step gs) i b H0) as [h].
exists h.
split.
auto.
eapply (Lem_cDH_Q gs i b h) ; auto.
Qed.
Lemma Lem_E_Q : forall n cq h b, estimate n cq h = Some b -> exists qi, qi < coq_k cq /\ testone n (coq_csq cq qi) h = Some b.
Proof.
intros.
unfold estimate in H.
destruct cq.
simpl.
induction coq_k.
inversion H.
unfold testall in H.
remember (testone n (coq_csq coq_k) h) as sb.
destruct sb.
exists coq_k.
crush.
fold testall in H.
specialize (IHcoq_k H).
destruct IHcoq_k.
exists x.
crush.
Qed.
Lemma Lem_cH_M :forall gs r i j m, extract_historyrj i gs r j = None -> extract_historyrj i (step gs) r j = Some m ->
get_undelivered (n gs) (message_archive gs (round_no gs)) (delivered gs (round_no gs)) = Some m /\
(i = receiver_id m) /\ (r = m_round_no m) /\ (j = sender_id m).
Proof.
intros.
remember (step gs) as gs'.
unfold step in Heqgs'.
remember (get_undelivered (n gs) (message_archive gs (round_no gs)) (delivered gs (round_no gs))) as sm.
destruct sm.
- rewrite Heqgs' in H0.
unfold extract_historyrj in H0.
simpl in H0.
unfold step_deliver in H0.
remember (i =? receiver_id m0) as isreceiver.
destruct isreceiver.
assert (i = receiver_id m0).
apply (beq_nat_true_iff i (receiver_id m0) ).
auto.
rewrite <- H1 in H0.
unfold extract_historyrj in H.
destruct (local_states gs i).
destruct l.
unfold step_deliver_loc in H0.
simpl in H0.
remember (r =? m_round_no m0) as isround.
destruct isround.
assert (r = m_round_no m0).
eapply (beq_nat_true_iff).
auto.
remember (j =? sender_id m0) as issender.
destruct issender.
assert (j = sender_id m0).
eapply (beq_nat_true_iff).
auto.
rewrite H2 in H.
rewrite H3 in H.
rewrite H in H0.
rewrite <- Heqissender in H0.
rewrite <- Heqisround in H0.
simpl in H0.
rewrite <- H2 in H.
rewrite <- H3 in H.
rewrite H in H0.
crush.
destruct (history ls (m_round_no m0) (sender_id m0)).
congruence.
rewrite <- Heqisround in H0.
rewrite <- Heqissender in H0.
simpl in H0.
congruence.
destruct (history ls (m_round_no m0) (sender_id m0)).
congruence.
rewrite <- Heqisround in H0.
simpl in H0.
congruence.
congruence.
unfold extract_historyrj in H.
destruct (local_states gs i) ; crush.
- rewrite Heqgs' in H0.
unfold extract_historyrj in H0.
unfold extract_historyrj in H.
simpl in H0.
unfold step_round in H0.
destruct (local_states gs i).
destruct l.
unfold step_round_loc in H0.
destruct (estimation ls (hl_round_no ls + 1)).
simpl in H0.
congruence.
simpl in H0.
congruence.
inversion H0.
Qed.
Lemma Lem_gH_C : forall params n h, (forall i, i < n -> (exists m b, h i = Some m /\ vote m = Some b)) -> cond params n (filter h).
Proof.
intros.
unfold cond.
intros.
specialize (H i).
destruct H.
auto.
destruct H.
destruct H.
destruct x0.
left.
unfold filter.
rewrite H.
destruct x.
simpl in H1.
rewrite H1.
auto.
right.
unfold filter.
rewrite H.
destruct x.
simpl in H1.
rewrite H1.
auto.
Qed.
Lemma Lem_1d_M : forall n msg dev m', get_undelivered1d n msg dev = Some m' -> exists i, msg i = Some m' /\ i < n.
Proof.
intros.
induction n.
- inversion H.
- unfold get_undelivered1d in H.
remember (msg n) as m0.
destruct m0.
+ remember (dev n) as d0.
destruct d0.
fold get_undelivered1d in H.
specialize (IHn H).
destruct IHn.
exists x.
crush.
exists n.
split.
congruence.
auto.
+ fold get_undelivered1d in H.
specialize (IHn H).
destruct IHn.
exists x.
crush.
Qed.
Lemma Lem_2d_M : forall n m msg dev m', get_undelivered2d n m msg dev = Some m' -> exists i j, msg i j = Some m' /\ i < n /\ j < m.
Proof.
intro n0.
induction n0 ; intros.
- inversion H.
- unfold get_undelivered2d in H.
remember (get_undelivered1d m (msg n0) (dev n0)) as m1d.
destruct m1d.
exists n0.
specialize (Lem_1d_M m (msg n0) (dev n0) m0 (eq_sym Heqm1d)).
intros.
destruct H0.
exists x.
crush.
fold get_undelivered2d in H.
specialize (IHn0 m msg dev m' H).
destruct IHn0.
destruct H0.
exists x.
exists x0.
crush.
Qed.
Lemma Lem_ud_M : forall n msg dev m, get_undelivered n msg dev = Some m ->
exists i j, msg i j = Some m /\ i < n /\ j < n.
Proof.
intros.
unfold get_undelivered in H.
apply (Lem_2d_M n n msg dev m H).
Qed.
Lemma Lem_M1d_L : forall n msg dev i m', i < n -> msg i = Some m' -> get_undelivered1d n msg dev = None -> dev i = true.
Proof.
intros.
induction n.
- inversion H.
- unfold get_undelivered1d in H.
inversion H.
unfold get_undelivered1d in H1.
rewrite H3 in H0.
rewrite H0 in H1.
destruct (dev n).
auto.
inversion H1.
unfold get_undelivered1d in H1.
destruct (msg n).
destruct (dev n).
fold get_undelivered1d in H1.
crush.
inversion H1.
fold get_undelivered1d in H1.
crush.
Qed.
Lemma Lem_M2d_L : forall n m msg dev i j m', i < n -> j < m -> msg i j = Some m' -> get_undelivered2d n m msg dev = None ->
dev i j = true.
Proof.
intro n.
induction n ; intros.
- inversion H.
- unfold get_undelivered2d in H2.
remember (get_undelivered1d m (msg n) (dev n)) as m1d.
destruct m1d.
inversion H2.