auth.v 6.62 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 *)
Robbert Krebbers's avatar
Robbert Krebbers committed
19 20 21
Definition auth_own_aux : { x | x = @auth_own_def }. by eexists. Qed.
Definition auth_own {Λ Σ A Ae a} := proj1_sig auth_own_aux Λ Σ A Ae a.
Definition auth_own_eq : @auth_own = @auth_own_def := proj2_sig auth_own_aux.
Ralf Jung's avatar
Ralf Jung committed
22

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

30 31 32
Instance: Params (@auth_inv) 6.
Instance: Params (@auth_own) 6.
Instance: Params (@auth_ctx) 7.
33

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

42
  Global Instance auth_own_ne n γ : Proper (dist n ==> dist n) (auth_own γ).
43
  Proof. rewrite auth_own_eq; solve_proper. Qed.
44
  Global Instance auth_own_proper γ : Proper (() ==> ()) (auth_own γ).
Robbert Krebbers's avatar
Robbert Krebbers committed
45
  Proof. by rewrite auth_own_eq; solve_proper. Qed.
Ralf Jung's avatar
Ralf Jung committed
46 47 48
  Global Instance auth_own_timeless γ a : TimelessP (auth_own γ a).
  Proof. rewrite auth_own_eq. apply _. Qed.

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

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

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

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

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

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

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