Skip to content

Commit 170f303

Browse files
committed
Demonstrate that the two styles of CRDTs are equivalent
1 parent 3c30d39 commit 170f303

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

proofs/crdt/equivalence.v

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
(**************************************************************************)
2+
(**************************************************************************)
3+
(**** ****)
4+
(**** Equivalence of state-based and operation-based conflict-free ****)
5+
(**** replicated data types ****)
6+
(**** ****)
7+
(**************************************************************************)
8+
(**************************************************************************)
9+
10+
Require Import main.tactics.
11+
12+
Require main.crdt.operation_crdt.
13+
14+
(* We can emulate a state-based CRDT with an operation-based CRDT. *)
15+
16+
Definition operation_crdt_data_from_state_crdt
17+
[A Q]
18+
(crdt : state_crdt.Crdt A Q)
19+
: operation_crdt.CrdtData A Q
20+
:=
21+
{|
22+
operation_crdt.State := crdt.(state_crdt.State);
23+
operation_crdt.Operation := crdt.(state_crdt.State);
24+
operation_crdt.initial := crdt.(state_crdt.initial);
25+
operation_crdt.update x s := crdt.(state_crdt.update) x s;
26+
operation_crdt.interpret o s := crdt.(state_crdt.merge) o s;
27+
operation_crdt.query s := crdt.(state_crdt.query) s;
28+
operation_crdt.Precondition _ _ := True;
29+
|}.
30+
31+
Program Definition operation_crdt_from_state_crdt
32+
[A Q]
33+
(crdt : state_crdt.Crdt A Q)
34+
: operation_crdt.Crdt (operation_crdt_data_from_state_crdt crdt)
35+
:= {| operation_crdt.commutativity := _ |}.
36+
Next Obligation.
37+
clean.
38+
pose proof (crdt.(state_crdt.semilattice _ _)).
39+
rewrite state_crdt.associativity
40+
with (initial := crdt.(state_crdt.initial)); search.
41+
rewrite state_crdt.commutativity
42+
with (initial := crdt.(state_crdt.initial)) (x := o1); search.
43+
Qed.
44+
45+
(*
46+
We can emulate an operation-based CRDT with a state-based CRDT if the
47+
delivery precondition and equality of operations are decidable.
48+
*)
49+
50+
Program Definition state_crdt_from_operation_crdt
51+
[A Q]
52+
[crdt_data : operation_crdt.CrdtData A Q]
53+
(crdt : operation_crdt.Crdt crdt_data)
54+
(precondition :
55+
forall s o,
56+
{crdt_data.(operation_crdt.Precondition) s o} +
57+
{~ crdt_data.(operation_crdt.Precondition) s o}
58+
)
59+
(equal :
60+
forall o1 o2 : crdt_data.(operation_crdt.Operation),
61+
{o1 = o2} + {o1 <> o2}
62+
)
63+
: state_crdt.Crdt A Q :=
64+
{|
65+
state_crdt.State := _;
66+
state_crdt.initial := _;
67+
state_crdt.merge := _;
68+
state_crdt.update _ _ := _;
69+
state_crdt.query := _;
70+
|}.
71+
Next Obligation.
72+
Admitted.
73+
Next Obligation.
74+
Admitted.

0 commit comments

Comments
 (0)