auth.v 4.18 KB
Newer Older
1 2
From iris.program_logic Require Export pviewshifts.
From iris.algebra Require Export auth.
3
From iris.algebra Require Import gmap.
4
From iris.proofmode Require Import invariants.
5
Import uPred.
6

7
(* The CMRA we need. *)
8 9
Class authG Σ (A : ucmraT) := AuthG {
  auth_inG :> inG Σ (authR A);
10
  auth_discrete :> CMRADiscrete A;
11
}.
12
Definition authΣ (A : ucmraT) : gFunctors := #[ GFunctor (constRF (authR A)) ].
13

14 15
Instance subG_authΣ Σ A : subG (authΣ A) Σ  CMRADiscrete A  authG Σ A.
Proof. intros ?%subG_inG ?. by split. Qed.
16

17
Section definitions.
18 19
  Context `{irisG Λ Σ, authG Σ A} (γ : gname).
  Definition auth_own (a : A) : iProp Σ :=
20
    own γ ( a).
21
  Definition auth_inv (φ : A  iProp Σ) : iProp Σ :=
22
    ( a, own γ ( a)  φ a)%I.
23
  Definition auth_ctx (N : namespace) (φ : A  iProp Σ) : iProp Σ :=
24 25 26 27
    inv N (auth_inv φ).

  Global Instance auth_own_ne n : Proper (dist n ==> dist n) auth_own.
  Proof. solve_proper. Qed.
28
  Global Instance auth_own_proper : Proper (() ==> ()) auth_own.
29 30 31
  Proof. solve_proper. Qed.
  Global Instance auth_own_timeless a : TimelessP (auth_own a).
  Proof. apply _. Qed.
32 33 34 35 36 37
  Global Instance auth_inv_ne n : 
    Proper (pointwise_relation A (dist n) ==> dist n) (auth_inv).
  Proof. solve_proper. Qed.
  Global Instance auth_ctx_ne n N :
    Proper (pointwise_relation A (dist n) ==> dist n) (auth_ctx N).
  Proof. solve_proper. Qed.
38
  Global Instance auth_ctx_persistent N φ : PersistentP (auth_ctx N φ).
39 40
  Proof. apply _. Qed.
End definitions.
Ralf Jung's avatar
Ralf Jung committed
41

42
Typeclasses Opaque auth_own auth_ctx.
43 44 45
Instance: Params (@auth_inv) 6.
Instance: Params (@auth_own) 6.
Instance: Params (@auth_ctx) 7.
46

47
Section auth.
48 49
  Context `{irisG Λ Σ, authG Σ A}.
  Context (φ : A  iProp Σ) {φ_proper : Proper (() ==> ()) φ}.
50
  Implicit Types N : namespace.
51
  Implicit Types P Q R : iProp Σ.
52 53 54
  Implicit Types a b : A.
  Implicit Types γ : gname.

55
  Lemma auth_own_op γ a b : auth_own γ (a  b)  auth_own γ a  auth_own γ b.
56
  Proof. by rewrite /auth_own -own_op auth_frag_op. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
57

Zhen Zhang's avatar
Zhen Zhang committed
58
  Global Instance from_sep_own_authM γ a b :
59
    FromSep (auth_own γ (a  b)) (auth_own γ a) (auth_own γ b) | 90.
Zhen Zhang's avatar
Zhen Zhang committed
60 61
  Proof. by rewrite /FromSep auth_own_op. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
62 63 64
  Lemma auth_own_mono γ a b : a  b  auth_own γ b  auth_own γ a.
  Proof. intros [? ->]. by rewrite auth_own_op sep_elim_l. Qed.

Robbert Krebbers's avatar
Robbert Krebbers committed
65 66 67 68
  Global Instance auth_own_persistent γ a :
    Persistent a  PersistentP (auth_own γ a).
  Proof. rewrite /auth_own. apply _. Qed.

69
  Lemma auth_own_valid γ a : auth_own γ a   a.
70
  Proof. by rewrite /auth_own own_valid auth_validI. Qed.
71

72
  Lemma auth_alloc_strong N E a (G : gset gname) :
73
     a   φ a ={E}=>  γ,  (γ  G)  auth_ctx γ N φ  auth_own γ a.
74
  Proof.
75 76
    iIntros (?) "Hφ". rewrite /auth_own /auth_ctx.
    iVs (own_alloc_strong (Auth (Excl' a) a) G) as (γ) "[% Hγ]"; first done.
77
    iRevert "Hγ"; rewrite auth_both_op; iIntros "[Hγ Hγ']".
78
    iVs (inv_alloc N _ (auth_inv γ φ) with "[-Hγ']").
79
    { iNext. iExists a. by iFrame. }
80
    iVsIntro; iExists γ. iSplit; first by iPureIntro. by iFrame.
81 82 83
  Qed.

  Lemma auth_alloc N E a :
84
     a   φ a ={E}=>  γ, auth_ctx γ N φ  auth_own γ a.
85
  Proof.
86 87
    iIntros (?) "Hφ".
    iVs (auth_alloc_strong N E a  with "Hφ") as (γ) "[_ ?]"; eauto.
88 89
  Qed.

90 91
  Lemma auth_empty γ : True =r=> auth_own γ .
  Proof. by rewrite /auth_own -own_empty. Qed.
92

93 94 95 96 97
  Lemma auth_open E N γ a :
    nclose N  E 
    auth_ctx γ N φ   auth_own γ a ={E,EN}=>  af,
        (a  af)   φ (a  af)   b,
       (a ~l~> b @ Some af)   φ (b  af) ={EN,E}= auth_own γ b.
Ralf Jung's avatar
Ralf Jung committed
98
  Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
99 100
    iIntros (?) "(#? & >Hγf)". rewrite /auth_ctx /auth_own.
    iInv N as (a') "[>Hγ Hφ]" "Hclose". iCombine "Hγ" "Hγf" as "Hγ".
101 102 103 104 105 106
    iDestruct (own_valid with "#Hγ") as % [[af Ha'] ?]%auth_valid_discrete.
    simpl in Ha'; rewrite ->(left_id _ _) in Ha'; setoid_subst.
    iVsIntro. iExists af; iFrame "Hφ"; iSplit; first done.
    iIntros (b) "[% Hφ]".
    iVs (own_update with "Hγ") as "[Hγ Hγf]"; first eapply auth_update; eauto.
    iVs ("Hclose" with "[Hφ Hγ]") as "_"; auto.
107
    iNext. iExists (b  af). by iFrame.
108
  Qed.
109
End auth.