Skip to content

Commit 28a25f6

Browse files
committed
Prove key to group
1 parent 5cc033a commit 28a25f6

File tree

12 files changed

+110
-43
lines changed

12 files changed

+110
-43
lines changed

external/Goose/github_com/mit_pdos/tulip/txn.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ Definition Txn__resetwrs: val :=
7171
struct.storeF Txn "wrsp" "txn" (NewMap stringT (struct.t tulip.Value) #());;
7272
#().
7373

74-
Definition KeyToGroup: val :=
75-
rec: "KeyToGroup" "key" :=
76-
(StringLength "key") `rem` #2.
74+
Definition Txn__keyToGroup: val :=
75+
rec: "Txn__keyToGroup" "txn" "key" :=
76+
(StringLength "key") `rem` (MapLen (struct.loadF Txn "wrs" "txn")).
7777

7878
Definition Txn__setwrs: val :=
7979
rec: "Txn__setwrs" "txn" "key" "value" :=
80-
let: "gid" := KeyToGroup "key" in
80+
let: "gid" := Txn__keyToGroup "txn" "key" in
8181
let: "pwrs" := Fst (MapGet (struct.loadF Txn "wrs" "txn") "gid") in
8282
MapInsert "pwrs" "key" "value";;
8383
MapInsert (struct.loadF Txn "wrsp" "txn") "key" "value";;
8484
#().
8585

8686
Definition Txn__getwrs: val :=
8787
rec: "Txn__getwrs" "txn" "key" :=
88-
let: "gid" := KeyToGroup "key" in
88+
let: "gid" := Txn__keyToGroup "txn" "key" in
8989
let: "pwrs" := Fst (MapGet (struct.loadF Txn "wrs" "txn") "gid") in
9090
let: ("v", "ok") := MapGet "pwrs" "key" in
9191
("v", "ok").
@@ -177,7 +177,7 @@ Definition Txn__Read: val :=
177177
(if: "hit"
178178
then ("vlocal", #true)
179179
else
180-
let: "gid" := KeyToGroup "key" in
180+
let: "gid" := Txn__keyToGroup "txn" "key" in
181181
let: "gcoord" := Fst (MapGet (struct.loadF Txn "gcoords" "txn") "gid") in
182182
let: ("v", "ok") := gcoord.GroupCoordinator__Read "gcoord" (struct.loadF Txn "ts" "txn") "key" in
183183
(if: (~ "ok")

src/program_proof/rsm/pure/fin_sets.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ Section fin_set.
1515
filter P X ⊆ filter Q X.
1616
Proof. set_solver. Qed.
1717

18+
Lemma filter_subseteq_mono X Y (P : A -> Prop) `{!∀ x, Decision (P x)} :
19+
X ⊆ Y ->
20+
filter P X ⊆ filter P Y.
21+
Proof. set_solver. Qed.
22+
1823
End fin_set.

src/program_proof/tulip/base.v

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ From Perennial.base_logic Require Import ghost_map mono_nat saved_prop.
44
From Perennial.program_proof Require Import grove_prelude.
55
From Perennial.Helpers Require finite.
66

7+
Local Ltac Zify.zify_post_hook ::= Z.div_mod_to_equations.
8+
79
Definition dbkey := string.
810
Definition dbval := option string.
911
Definition dbhist := list dbval.
@@ -46,7 +48,7 @@ Definition txnst_to_u64 (s : txnst) :=
4648
Definition gids_all : gset u64 := list_to_set (fmap W64 (seqZ 0 2)).
4749

4850
Lemma size_gids_all :
49-
size gids_all < 2 ^ 64 - 1.
51+
0 < size gids_all < 2 ^ 64 - 1.
5052
Proof.
5153
rewrite /gids_all size_list_to_set; last first.
5254
{ apply seq_U64_NoDup; lia. }
@@ -160,8 +162,8 @@ Qed.
160162
Definition dblog := list ccommand.
161163

162164
(** Converting keys to group IDs. *)
163-
Definition key_to_group (key : dbkey) : u64.
164-
Admitted.
165+
Definition key_to_group (key : dbkey) : u64 :=
166+
String.length key `mod` size gids_all.
165167

166168
(** Participant groups. *)
167169
Definition ptgroups (keys : gset dbkey) : gset u64 :=
@@ -185,7 +187,14 @@ Definition valid_pwrs (gid : u64) (pwrs : dbmap) :=
185187

186188
Lemma elem_of_key_to_group key :
187189
key_to_group key ∈ gids_all.
188-
Admitted.
190+
Proof.
191+
rewrite /key_to_group /gids_all.
192+
rewrite size_list_to_set; last first.
193+
{ apply seq_U64_NoDup; lia. }
194+
rewrite length_fmap length_seqZ.
195+
apply elem_of_list_to_set, elem_of_list_fmap_1, elem_of_seqZ.
196+
lia.
197+
Qed.
189198

190199
Lemma elem_of_key_to_group_ptgroups key keys :
191200
key ∈ keys ->
@@ -284,6 +293,16 @@ Definition valid_wrs (wrs : dbmap) := dom wrs ⊆ keys_all.
284293

285294
Definition valid_key (key : dbkey) := key ∈ keys_all.
286295

296+
Lemma valid_key_length key :
297+
valid_key key ->
298+
String.length key < 2 ^ 64.
299+
Proof.
300+
intros Hvk.
301+
rewrite /valid_key /keys_all in Hvk.
302+
apply elem_of_list_to_set, elem_of_list_fmap_2 in Hvk.
303+
by destruct Hvk as ([k Hk] & -> & _).
304+
Qed.
305+
287306
Definition valid_ccommand gid (c : ccommand) :=
288307
match c with
289308
| CmdCommit ts pwrs => valid_ts ts ∧ valid_pwrs gid pwrs

src/program_proof/tulip/inv_group.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
From Perennial.program_proof Require Import grove_prelude.
2-
From Perennial.program_proof.rsm.pure Require Import list quorum fin_maps.
2+
From Perennial.program_proof.rsm.pure Require Import list quorum fin_maps fin_sets.
33
From Perennial.program_proof.tulip Require Import base cmd res stability.
44

55
Lemma tpls_group_keys_group_dom gid tpls :
@@ -447,7 +447,13 @@ Section lemma.
447447
iPureIntro.
448448
split; first done.
449449
rewrite /valid_pwrs Hwg wrs_group_keys_group_dom.
450-
set_solver.
450+
rewrite /valid_wrs in Hvw.
451+
rewrite /keys_group.
452+
(* [set_solver] is able to solve this directly when [key_to_group] is
453+
admitted, but is unable to solve this after it is defined, so we apply an
454+
additional lemma [filter_subseteq_mono]. *)
455+
(* set_solver. *)
456+
by apply filter_subseteq_mono.
451457
}
452458
{ by iDestruct "Hsafec" as "[_ %Hvts]". }
453459
Qed.

src/program_proof/tulip/program/txn/key_to_group.v

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/program_proof/tulip/program/txn/txn_delete.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Section program.
55
Context `{!heapGS Σ, !tulip_ghostG Σ}.
66

77
Theorem wp_Txn__Delete txn tid key rds γ τ :
8+
valid_key key ->
89
{{{ own_txn txn tid rds γ τ ∗ (∃ vprev, txnmap_ptsto τ key vprev) }}}
910
Txn__Delete #txn #(LitString key)
1011
{{{ RET #(); own_txn txn tid rds γ τ ∗ txnmap_ptsto τ key None }}}.
1112
Proof.
12-
iIntros (Φ) "[Htxn [%v Hpt]] HΦ".
13+
iIntros (Hvk Φ) "[Htxn [%v Hpt]] HΦ".
1314
wp_rec.
1415

1516
(*@ func (txn *Txn) Delete(key string) { @*)
@@ -21,6 +22,7 @@ Section program.
2122
iNamed "Htxn".
2223
wp_pures.
2324
wp_apply (wp_Txn__setwrs _ _ None with "Hwrs").
25+
{ apply Hvk. }
2426
iIntros "Hwrs".
2527
wp_pures.
2628
iApply "HΦ".

src/program_proof/tulip/program/txn/txn_getwrs.v

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
From Perennial.program_proof.tulip.program Require Import prelude.
2-
From Perennial.program_proof.tulip.program.txn Require Import txn_repr key_to_group.
2+
From Perennial.program_proof.tulip.program.txn Require Import txn_repr txn_key_to_group.
33

44
Section program.
55
Context `{!heapGS Σ, !tulip_ghostG Σ}.
66

7-
Theorem wp_Txn__getwrs (txn : loc) (key : string) q wrs :
7+
Theorem wp_Txn__getwrs (txn : loc) (key : string) q wrs :
8+
valid_key key ->
89
{{{ own_txn_wrs txn q wrs }}}
910
Txn__getwrs #txn #(LitString key)
1011
{{{ (v : dbval) (ok : bool), RET (dbval_to_val v, #ok);
1112
own_txn_wrs txn q wrs ∗ ⌜wrs !! key = if ok then Some v else None⌝
1213
}}}.
1314
Proof.
14-
iIntros (Φ) "Hwrs HΦ".
15+
iIntros (Hvk Φ) "Hwrs HΦ".
1516
wp_rec.
1617

1718
(*@ func (txn *Txn) getwrs(key string) (Value, bool) { @*)
1819
(*@ gid := KeyToGroup(key) @*)
1920
(*@ pwrs := txn.wrs[gid] @*)
2021
(*@ @*)
21-
wp_apply wp_KeyToGroup.
22-
iIntros (gid Hgid).
22+
wp_apply (wp_Txn__keyToGroup with "Hwrs").
23+
{ apply Hvk. }
24+
iIntros (gid) "[Hwrs %Hgid]".
2325
do 2 iNamed "Hwrs".
2426
wp_loadField.
2527
wp_apply (wp_MapGet with "HpwrsmP").
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From Perennial.program_proof.tulip.program Require Import prelude.
2+
From Perennial.program_proof.tulip.program.txn Require Import txn_repr.
3+
4+
Local Ltac Zify.zify_post_hook ::= Z.div_mod_to_equations.
5+
6+
Section program.
7+
Context `{!heapGS Σ, !tulip_ghostG Σ}.
8+
9+
Theorem wp_Txn__keyToGroup (txn : loc) (key : string) q wrs :
10+
valid_key key ->
11+
{{{ own_txn_wrs txn q wrs }}}
12+
Txn__keyToGroup #txn #(LitString key)
13+
{{{ (gid : u64), RET #gid; own_txn_wrs txn q wrs ∗ ⌜key_to_group key = gid⌝ }}}.
14+
Proof.
15+
iIntros (Hvk Φ) "Htxn HΦ".
16+
wp_rec.
17+
18+
(*@ func (txn *Txn) keyToGroup(key string) uint64 { @*)
19+
(*@ return uint64(len(key)) % uint64(len(txn.gcoords)) @*)
20+
(*@ } @*)
21+
iNamed "Htxn".
22+
wp_loadField.
23+
iNamed "Hwrs".
24+
wp_apply (wp_MapLen with "HpwrsmP").
25+
iIntros "[%Hnoof HpwrsmP]".
26+
wp_pures.
27+
iApply "HΦ".
28+
iFrame "∗ %".
29+
iPureIntro.
30+
rewrite /key_to_group.
31+
rewrite -size_dom Hdomwrs.
32+
pose proof size_gids_all as Hszall.
33+
set x := String.length key.
34+
set y := size gids_all.
35+
apply valid_key_length in Hvk.
36+
word.
37+
Qed.
38+
39+
End program.

src/program_proof/tulip/program/txn/txn_read.v

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From Perennial.program_proof.tulip.invariance Require Import read.
22
From Perennial.program_proof.tulip.program Require Import prelude.
33
From Perennial.program_proof.tulip.program.txn Require Import
4-
res txn_repr txn_getwrs proph key_to_group.
4+
res txn_repr txn_getwrs proph txn_key_to_group.
55
From Perennial.program_proof.tulip.program.gcoord Require Import gcoord_read.
66

77
Section program.
@@ -26,6 +26,7 @@ Section program.
2626
(*@ @*)
2727
iNamed "Htxn".
2828
wp_apply (wp_Txn__getwrs with "Hwrs").
29+
{ apply Hvk. }
2930
iIntros (vlocal ok) "[Hwrs %Hv]".
3031
iDestruct (txnmap_lookup with "Htxnmap Hpt") as %Hvalue.
3132
wp_if_destruct.
@@ -43,8 +44,9 @@ Section program.
4344
(*@ gcoord := txn.gcoords[gid] @*)
4445
(*@ v, ok := gcoord.Read(txn.ts, key) @*)
4546
(*@ @*)
46-
wp_apply wp_KeyToGroup.
47-
iIntros (gid Hgid).
47+
wp_apply (wp_Txn__keyToGroup with "Hwrs").
48+
{ apply Hvk. }
49+
iIntros (gid) "[Hwrs %Hgid]".
4850
iNamed "Hgcoords".
4951
wp_loadField.
5052
wp_apply (wp_MapGet with "Hgcoords").

src/program_proof/tulip/program/txn/txn_setwrs.v

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
From Perennial.program_proof.tulip.program Require Import prelude.
2-
From Perennial.program_proof.tulip.program.txn Require Import txn_repr key_to_group.
2+
From Perennial.program_proof.tulip.program.txn Require Import txn_repr txn_key_to_group.
33

44
Section program.
55
Context `{!heapGS Σ, !tulip_ghostG Σ}.
66

77
Theorem wp_Txn__setwrs (txn : loc) (key : string) (value : dbval) wrs :
8+
valid_key key ->
89
{{{ own_txn_wrs txn (DfracOwn 1) wrs }}}
910
Txn__setwrs #txn #(LitString key) (dbval_to_val value)
1011
{{{ RET #(); own_txn_wrs txn (DfracOwn 1) (<[key := value]> wrs) }}}.
1112
Proof.
12-
iIntros (Φ) "Hwrs HΦ".
13+
iIntros (Hvk Φ) "Hwrs HΦ".
1314
wp_rec.
1415

1516
(*@ func (txn *Txn) setwrs(key string, value Value) { @*)
1617
(*@ gid := KeyToGroup(key) @*)
1718
(*@ pwrs := txn.wrs[gid] @*)
1819
(*@ @*)
19-
wp_apply wp_KeyToGroup.
20-
iIntros (gid Hgid).
20+
wp_apply (wp_Txn__keyToGroup with "Hwrs").
21+
{ apply Hvk. }
22+
iIntros (gid) "[Hwrs %Hgid]".
2123
do 2 iNamed "Hwrs".
2224
wp_loadField.
2325
wp_apply (wp_MapGet with "HpwrsmP").

0 commit comments

Comments
 (0)