auth.v 5.91 KB
Newer Older
Robbert Krebbers's avatar
Robbert Krebbers committed
1
From algebra Require Export auth.
2
From program_logic Require Export invariants ghost_ownership.
3
Import uPred.
4

5 6 7 8 9 10
Class AuthInG Λ Σ (i : gid) (A : cmraT) `{Empty A} := {
  auth_inG :> InG Λ Σ i (authRA A);
  auth_identity :> CMRAIdentity A;
  auth_timeless (a : A) :> Timeless a;
}.

11 12
(* TODO: Once we switched to RAs, it is no longer necessary to remember that a is
   constantly valid. *)
13
Definition auth_inv {Λ Σ A} (i : gid) `{AuthInG Λ Σ i A}
14 15
    (γ : gname) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
  ( a, (  a  own i γ ( a))  φ a)%I.
16 17 18 19 20 21 22 23
Definition auth_own {Λ Σ A} (i : gid) `{AuthInG Λ Σ i A}
  (γ : gname) (a : A) : iPropG Λ Σ := own i γ ( a).
Definition auth_ctx {Λ Σ A} (i : gid) `{AuthInG Λ Σ i A}
    (γ : gname) (N : namespace) (φ : A  iPropG Λ Σ) : iPropG Λ Σ :=
  inv N (auth_inv i γ φ).
Instance: Params (@auth_inv) 7.
Instance: Params (@auth_own) 7.
Instance: Params (@auth_ctx) 8.
24

25
Section auth.
26
  Context `{AuthInG Λ Σ AuthI A}.
27
  Context (φ : A  iPropG Λ Σ) {φ_proper : Proper (() ==> ()) φ}.
28
  Implicit Types N : namespace.
29
  Implicit Types P Q R : iPropG Λ Σ.
30 31 32
  Implicit Types a b : A.
  Implicit Types γ : gname.

33 34 35 36
  Lemma auto_own_op γ a b :
    auth_own AuthI γ (a  b)  (auth_own AuthI γ a  auth_own AuthI γ b)%I.
  Proof. by rewrite /auth_own -own_op auth_frag_op. Qed.

37 38
  Lemma auth_alloc N a :
     a  φ a  pvs N N ( γ, auth_ctx AuthI γ N φ  auth_own AuthI γ a).
39
  Proof.
40 41
    intros Ha. eapply sep_elim_True_r.
    { by eapply (own_alloc AuthI (Auth (Excl a) a) N). }
42 43
    rewrite pvs_frame_l. apply pvs_strip_pvs.
    rewrite sep_exist_l. apply exist_elim=>γ. rewrite -(exist_intro γ).
44
    transitivity ( auth_inv AuthI γ φ  auth_own AuthI γ a)%I.
45
    { rewrite /auth_inv -later_intro -(exist_intro a).
46
      rewrite const_equiv // left_id.
47
      rewrite [(_  φ _)%I]comm -assoc. apply sep_mono; first done.
48 49
      rewrite /auth_own -own_op auth_both_op. done. }
    rewrite (inv_alloc N) /auth_ctx pvs_frame_r. apply pvs_mono.
50
    by rewrite always_and_sep_l.
51 52
  Qed.

53
  Lemma auth_empty E γ : True  pvs E E (auth_own AuthI γ ).
54 55
  Proof. by rewrite own_update_empty /auth_own. Qed.

56
  Lemma auth_opened E γ a :
57
    ( auth_inv AuthI γ φ  auth_own AuthI γ a)
58
     pvs E E ( a',   (a  a')   φ (a  a')  own AuthI γ ( (a  a')   a)).
Ralf Jung's avatar
Ralf Jung committed
59
  Proof.
60
    rewrite /auth_inv. rewrite later_exist sep_exist_r. apply exist_elim=>b.
61 62 63
    rewrite later_sep [((_  _))%I]pvs_timeless !pvs_frame_r. apply pvs_mono.
    rewrite always_and_sep_l -!assoc. apply const_elim_sep_l=>Hv.
    rewrite /auth_own [(▷φ _  _)%I]comm assoc -own_op.
64 65
    rewrite own_valid_r auth_validI /= and_elim_l sep_exist_l sep_exist_r /=.
    apply exist_elim=>a'.
66
    rewrite left_id -(exist_intro a').
67
    apply (eq_rewrite b (a  a') (λ x, ■✓x  ▷φ x  own AuthI γ ( x   a))%I).
68
    { by move=>n ? ? /timeless_iff ->. }
69
    { by eauto with I. }
70
    rewrite const_equiv // left_id comm.
Ralf Jung's avatar
Ralf Jung committed
71 72 73
    apply sep_mono; first done.
    by rewrite sep_elim_l.
  Qed.
Ralf Jung's avatar
Ralf Jung committed
74

75
  Lemma auth_closing `{!LocalUpdate Lv L} E γ a a' :
76
    Lv a   (L a  a') 
77
    ( φ (L a  a')  own AuthI γ ( (a  a')   a))
78
     pvs E E ( auth_inv AuthI γ φ  auth_own AuthI γ (L a)).
Ralf Jung's avatar
Ralf Jung committed
79
  Proof.
80
    intros HL Hv. rewrite /auth_inv /auth_own -(exist_intro (L a  a')).
81
    rewrite later_sep [(_  ▷φ _)%I]comm -assoc.
Ralf Jung's avatar
Ralf Jung committed
82
    rewrite -pvs_frame_l. apply sep_mono; first done.
83
    rewrite const_equiv // left_id -later_intro -own_op.
84
    by apply own_update, (auth_local_update_l L).
Ralf Jung's avatar
Ralf Jung committed
85 86
  Qed.

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

89
  (* Notice how the user has to prove that `ba'` is valid at all
90
     step-indices. However, since A is timeless, that should not be
91 92
     a restriction. *)
  Lemma auth_fsa E N P (Q : V  iPropG Λ Σ) γ a :
93
    fsaV 
Ralf Jung's avatar
Ralf Jung committed
94
    nclose N  E 
95
    P  auth_ctx AuthI γ N φ 
96
    P  (auth_own AuthI γ a   a',
97
            (a  a')   φ (a  a') -
98 99 100
          fsa (E  nclose N) (λ x,  L Lv (Hup : LocalUpdate Lv L),
             (Lv a   (L a  a'))   φ (L a  a') 
            (auth_own AuthI γ (L a) - Q x))) 
101
    P  fsa E Q.
Ralf Jung's avatar
Ralf Jung committed
102
  Proof.
103 104
    rewrite /auth_ctx=>? HN Hinv Hinner.
    eapply (inv_fsa fsa); eauto. rewrite Hinner=>{Hinner Hinv P}.
105 106
    apply wand_intro_l. rewrite assoc.
    rewrite (auth_opened (E  N)) !pvs_frame_r !sep_exist_r.
107
    apply (fsa_strip_pvs fsa). apply exist_elim=>a'.
108
    rewrite (forall_elim a'). rewrite [(_  _)%I]comm.
109 110 111
    (* Getting this wand eliminated is really annoying. *)
    rewrite [(_  _)%I]comm -!assoc [(▷φ _  _  _)%I]assoc [(▷φ _  _)%I]comm.
    rewrite wand_elim_r fsa_frame_l.
112 113 114 115
    apply (fsa_mono_pvs fsa)=> b.
    rewrite sep_exist_l; apply exist_elim=> L.
    rewrite sep_exist_l; apply exist_elim=> Lv.
    rewrite sep_exist_l; apply exist_elim=> ?.
116
    rewrite comm -!assoc. apply const_elim_sep_l=>-[HL Hv].
117
    rewrite assoc [(_  (_ - _))%I]comm -assoc.
118 119
    rewrite (auth_closing (E  N)) //; [].
    rewrite pvs_frame_l. apply pvs_mono.
120
    by rewrite assoc [(_  _)%I]comm -assoc wand_elim_l.
Ralf Jung's avatar
Ralf Jung committed
121
  Qed.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  Lemma auth_fsa' L `{!LocalUpdate Lv L} E N P (Q: V  iPropG Λ Σ) γ a :
    fsaV 
    nclose N  E 
    P  auth_ctx AuthI γ N φ 
    P  (auth_own AuthI γ a  ( a',
            (a  a')   φ (a  a') -
          fsa (E  nclose N) (λ x,
             (Lv a   (L a  a'))   φ (L a  a') 
            (auth_own AuthI γ (L a) - Q x)))) 
    P  fsa E Q.
  Proof.
    intros ??? HP. eapply auth_fsa with N γ a; eauto.
    rewrite HP; apply sep_mono; first done; apply forall_mono=> a'.
    apply wand_mono; first done. apply (fsa_mono fsa)=> b.
    rewrite -(exist_intro L). by repeat erewrite <-exist_intro by apply _.
  Qed.
138
End auth.