auth.v 6.15 KB
Newer Older
Ralf Jung's avatar
Ralf Jung committed
1
From algebra Require Export auth upred_tactics.
2
From program_logic Require Export invariants global_functor.
3
Import uPred.
4

5
Class authG Λ Σ (A : cmraT) `{Empty A} := AuthG {
6
  auth_inG :> inG Λ Σ (authR A);
7
  auth_identity :> CMRAIdentity A;
8
  auth_timeless :> CMRADiscrete A;
9 10
}.

11
Definition authGF (A : cmraT) : iFunctor := constF (authR A).
12
Instance authGF_inGF (A : cmraT) `{inGF Λ Σ (authGF A)}
13
  `{CMRAIdentity A, CMRADiscrete A} : authG Λ Σ A.
14
Proof. split; try apply _. apply: inGF_inG. Qed.
15

16
Definition auth_own `{authG Λ Σ A} (γ : gname) (a : A) : iPropG Λ Σ :=
Ralf Jung's avatar
Ralf Jung committed
17
  own γ ( a).
18
Typeclasses Opaque auth_own.
Ralf Jung's avatar
Ralf Jung committed
19

20 21
Definition auth_inv `{authG Λ Σ A}
    (γ : gname) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
Ralf Jung's avatar
Ralf Jung committed
22
  ( a, own γ ( a)  φ a)%I.
23 24
Definition auth_ctx`{authG Λ Σ A}
    (γ : gname) (N : namespace) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
Ralf Jung's avatar
Ralf Jung committed
25 26
  inv N (auth_inv γ φ).

27 28 29
Instance: Params (@auth_inv) 6.
Instance: Params (@auth_own) 6.
Instance: Params (@auth_ctx) 7.
30

31
Section auth.
32
  Context `{AuthI : authG Λ Σ A}.
33
  Context (φ : A  iPropG Λ Σ) {φ_proper : Proper (() ==> ()) φ}.
34
  Implicit Types N : namespace.
35
  Implicit Types P Q R : iPropG Λ Σ.
36 37 38
  Implicit Types a b : A.
  Implicit Types γ : gname.

39
  Global Instance auth_own_ne n γ : Proper (dist n ==> dist n) (auth_own γ).
40
  Proof. solve_proper. Qed.
41
  Global Instance auth_own_proper γ : Proper (() ==> ()) (auth_own γ).
42
  Proof. solve_proper. Qed.
Ralf Jung's avatar
Ralf Jung committed
43
  Global Instance auth_own_timeless γ a : TimelessP (auth_own γ a).
44
  Proof. rewrite /auth_own. apply _. Qed.
Ralf Jung's avatar
Ralf Jung committed
45

Ralf Jung's avatar
Ralf Jung committed
46
  Lemma auth_own_op γ a b :
47
    auth_own γ (a  b)  (auth_own γ a  auth_own γ b)%I.
48
  Proof. by rewrite /auth_own -own_op auth_frag_op. Qed.
Ralf Jung's avatar
Ralf Jung committed
49
  Lemma auth_own_valid γ a : auth_own γ a   a.
50
  Proof. by rewrite /auth_own own_valid auth_validI. Qed.
51

52 53
  Lemma auth_alloc E N a :
     a  nclose N  E 
54
     φ a  (|={E}=>  γ, auth_ctx γ N φ  auth_own γ a).
55
  Proof.
56
    intros Ha HN. eapply sep_elim_True_r.
57
    { by eapply (own_alloc (Auth (Excl a) a) N). }
58
    rewrite pvs_frame_l. rewrite -(pvs_mask_weaken N E) //. apply pvs_strip_pvs.
59
    rewrite sep_exist_l. apply exist_elim=>γ. rewrite -(exist_intro γ).
60
    trans ( auth_inv γ φ  auth_own γ a)%I.
61
    { rewrite /auth_inv -(exist_intro a) later_sep.
Ralf Jung's avatar
Ralf Jung committed
62
      ecancel [ φ _]%I.
63
      by rewrite -later_intro -own_op auth_both_op. }
64
    rewrite (inv_alloc N) /auth_ctx pvs_frame_r. apply pvs_mono.
65
    by rewrite always_and_sep_l.
66 67
  Qed.

68
  Lemma auth_empty γ E : True  (|={E}=> auth_own γ ).
69
  Proof. by rewrite -own_update_empty. Qed.
70

71
  Lemma auth_opened E γ a :
72
    ( auth_inv γ φ  auth_own γ a)
73
     (|={E}=>  a',  (a  a')   φ (a  a')  own γ ( (a  a')   a)).
Ralf Jung's avatar
Ralf Jung committed
74
  Proof.
75
    rewrite /auth_inv. rewrite later_exist sep_exist_r. apply exist_elim=>b.
Ralf Jung's avatar
Ralf Jung committed
76 77
    rewrite later_sep [( own _ _)%I]pvs_timeless !pvs_frame_r. apply pvs_mono.
    rewrite own_valid_l discrete_valid -!assoc. apply const_elim_sep_l=>Hv.
78
    rewrite [(▷φ _  _)%I]comm assoc -own_op.
79 80
    rewrite own_valid_r auth_validI /= and_elim_l sep_exist_l sep_exist_r /=.
    apply exist_elim=>a'.
81
    rewrite left_id -(exist_intro a').
82 83
    apply (eq_rewrite b (a  a') (λ x,  x   φ x  own γ ( x   a))%I).
    { by move=>n x y /timeless_iff ->. }
84
    { by eauto with I. }
Ralf Jung's avatar
Ralf Jung committed
85 86
    rewrite -valid_intro; last by apply Hv.
    rewrite left_id comm. auto with I.
Ralf Jung's avatar
Ralf Jung committed
87
  Qed.
Ralf Jung's avatar
Ralf Jung committed
88

89
  Lemma auth_closing `{!LocalUpdate Lv L} E γ a a' :
90
    Lv a   (L a  a') 
91
    ( φ (L a  a')  own γ ( (a  a')   a))
92
     (|={E}=>  auth_inv γ φ  auth_own γ (L a)).
Ralf Jung's avatar
Ralf Jung committed
93
  Proof.
94
    intros HL Hv. rewrite /auth_inv -(exist_intro (L a  a')).
Ralf Jung's avatar
Ralf Jung committed
95
    (* TODO it would be really nice to use cancel here *)
96
    rewrite later_sep [(_  ▷φ _)%I]comm -assoc.
97
    rewrite -pvs_frame_l. apply sep_mono_r.
Ralf Jung's avatar
Ralf Jung committed
98
    rewrite -later_intro -own_op.
99
    by apply own_update, (auth_local_update_l L).
Ralf Jung's avatar
Ralf Jung committed
100 101
  Qed.

102 103
  Context {V} (fsa : FSA Λ (globalF Σ) V) `{!FrameShiftAssertion fsaV fsa}.

104
  Lemma auth_fsa E N P (Ψ : V  iPropG Λ Σ) γ a :
105
    fsaV 
Ralf Jung's avatar
Ralf Jung committed
106
    nclose N  E 
107 108
    P  auth_ctx γ N φ 
    P  ( auth_own γ a   a',
109
            (a  a')   φ (a  a') -
110 111
          fsa (E  nclose N) (λ x,  L Lv (Hup : LocalUpdate Lv L),
             (Lv a   (L a  a'))   φ (L a  a') 
112 113
            (auth_own γ (L a) - Ψ x))) 
    P  fsa E Ψ.
Ralf Jung's avatar
Ralf Jung committed
114
  Proof.
115
    rewrite /auth_ctx=>? HN Hinv Hinner.
116
    eapply (inv_fsa fsa); eauto. rewrite Hinner=>{Hinner Hinv P HN}.
117
    apply wand_intro_l. rewrite assoc.
118 119
    rewrite (pvs_timeless (E  N)) pvs_frame_l pvs_frame_r.
    apply (fsa_strip_pvs fsa).
120
    rewrite (auth_opened (E  N)) !pvs_frame_r !sep_exist_r.
121
    apply (fsa_strip_pvs fsa). apply exist_elim=>a'.
122
    rewrite (forall_elim a'). rewrite [(_  _)%I]comm.
123
    eapply wand_apply_r; first (by eapply (wand_frame_l (own γ _))); last first.
124
    { rewrite assoc [(_  own _ _)%I]comm -assoc discrete_valid.  done. }
125
    rewrite fsa_frame_l.
Ralf Jung's avatar
Ralf Jung committed
126
    apply (fsa_mono_pvs fsa)=> x.
127 128 129
    rewrite sep_exist_l; apply exist_elim=> L.
    rewrite sep_exist_l; apply exist_elim=> Lv.
    rewrite sep_exist_l; apply exist_elim=> ?.
130
    rewrite comm -!assoc. apply const_elim_sep_l=>-[HL Hv].
131
    rewrite assoc [(_  (_ - _))%I]comm -assoc.
132 133
    rewrite (auth_closing (E  N)) //; [].
    rewrite pvs_frame_l. apply pvs_mono.
134
    by rewrite assoc [(_  _)%I]comm -assoc wand_elim_l.
Ralf Jung's avatar
Ralf Jung committed
135
  Qed.
136
  Lemma auth_fsa' L `{!LocalUpdate Lv L} E N P (Ψ : V  iPropG Λ Σ) γ a :
137 138
    fsaV 
    nclose N  E 
139 140
    P  auth_ctx γ N φ 
    P  ( auth_own γ a  ( a',
141
            (a  a')   φ (a  a') -
142 143
          fsa (E  nclose N) (λ x,
             (Lv a   (L a  a'))   φ (L a  a') 
144 145
            (auth_own γ (L a) - Ψ x)))) 
    P  fsa E Ψ.
146 147
  Proof.
    intros ??? HP. eapply auth_fsa with N γ a; eauto.
Ralf Jung's avatar
Ralf Jung committed
148
    rewrite HP; apply sep_mono_r, forall_mono=> a'.
149 150 151
    apply wand_mono; first done. apply (fsa_mono fsa)=> b.
    rewrite -(exist_intro L). by repeat erewrite <-exist_intro by apply _.
  Qed.
152
End auth.