auth.v 6.72 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
6
Class authG Λ Σ (A : cmraT) `{Empty A} := AuthG {
  auth_inG :> inG Λ Σ (authRA A);
7
  auth_identity :> CMRAIdentity A;
8
  auth_timeless :> CMRADiscrete A;
9
10
}.

11
12
Definition authGF (A : cmraT) : iFunctor := constF (authRA A).
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

Ralf Jung's avatar
Ralf Jung committed
16
17
18
Definition auth_own_def `{authG Λ Σ A} (γ : gname) (a : A) : iPropG Λ Σ :=
  own γ ( a).
(* Perform sealing *)
19
20
21
22
23
Definition auth_own_aux : { x : _ & x = @auth_own_def }.
  exact (existT _ Logic.eq_refl). Qed.
Definition auth_own := projT1 auth_own_aux.
Definition auth_own_eq : @auth_own = @auth_own_def := projT2 auth_own_aux.
Arguments auth_own {_ _ _ _ _} _ _.
Ralf Jung's avatar
Ralf Jung committed
24

25
26
27
28
29
Definition auth_inv `{authG Λ Σ A}
    (γ : gname) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
  ( a, ( a  own γ ( a))  φ a)%I.
Definition auth_ctx`{authG Λ Σ A}
    (γ : gname) (N : namespace) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
Ralf Jung's avatar
Ralf Jung committed
30
31
  inv N (auth_inv γ φ).

32
33
34
Instance: Params (@auth_inv) 6.
Instance: Params (@auth_own) 6.
Instance: Params (@auth_ctx) 7.
35

36
Section auth.
37
  Context `{AuthI : authG Λ Σ A}.
38
  Context (φ : A  iPropG Λ Σ) {φ_proper : Proper (() ==> ()) φ}.
39
  Implicit Types N : namespace.
40
  Implicit Types P Q R : iPropG Λ Σ.
41
42
43
  Implicit Types a b : A.
  Implicit Types γ : gname.

44
  Global Instance auth_own_ne n γ : Proper (dist n ==> dist n) (auth_own γ).
Ralf Jung's avatar
Ralf Jung committed
45
  Proof. by rewrite auth_own_eq /auth_own_def=> a b ->. Qed.
46
  Global Instance auth_own_proper γ : Proper (() ==> ()) (auth_own γ).
Ralf Jung's avatar
Ralf Jung committed
47
48
49
50
  Proof. by rewrite auth_own_eq /auth_own_def=> a b ->. Qed.
  Global Instance auth_own_timeless γ a : TimelessP (auth_own γ a).
  Proof. rewrite auth_own_eq. apply _. Qed.

Ralf Jung's avatar
Ralf Jung committed
51
  Lemma auth_own_op γ a b :
52
    auth_own γ (a  b)  (auth_own γ a  auth_own γ b)%I.
Ralf Jung's avatar
Ralf Jung committed
53
  Proof. by rewrite auth_own_eq /auth_own_def -own_op auth_frag_op. Qed.
Ralf Jung's avatar
Ralf Jung committed
54
  Lemma auth_own_valid γ a : auth_own γ a   a.
Ralf Jung's avatar
Ralf Jung committed
55
  Proof. by rewrite auth_own_eq /auth_own_def own_valid auth_validI. Qed.
56

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

73
  Lemma auth_empty γ E : True  (|={E}=> auth_own γ ).
Ralf Jung's avatar
Ralf Jung committed
74
  Proof. by rewrite auth_own_eq -own_update_empty. Qed.
75

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

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

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

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