-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunicity_double_spend.ec
More file actions
237 lines (194 loc) · 8.37 KB
/
Copy pathunicity_double_spend.ec
File metadata and controls
237 lines (194 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
(* ==================================================================== *)
(* EasyCrypt Formalization: Unicity Security against Double-Spending *)
(* Unicity Execution Layer
TL;DR: A party can double-spend his token in Unicity system only if he is able to
either break the collision resistance of the hash function or break the
binding property of the commitment scheme.
See the paper, section 5.2 Security against Double-Spending
Double-spending is creating two independent valid transactions from the same
token source state which share the same slot in the Unicity Service's R.
Adversary A has oracle access to US.
The attack scenario:
1. (T, σ, h_tx, d, π_inc), (T', σ', h_tx', d', π_inc'), (pk, h) <- A^US
2. A suceeds if both transactions are valid and share the same US slot (pk,h):
V_cert(T, σ, h_tx, d, π_inc; pk, h) = 1 AND
V_cert(T', σ', h_tx', d', π_inc'; pk, h) = 1
Theorem: Security against Double-Spending
A successful double-spend stores in the global variables:
DoubleSpendGame.result = (T, T', c, d, d') with T ≠ T'
DoubleSpendGame.m1 = open(c, d) = Some(hash T)
DoubleSpendGame.m2 = open(c, d') = Some(hash T')
Case (a): hash T = hash T'
CollisionReduction(A) outputs (T, T') --> CollisionGame wins.
Case (b): hash T ≠ hash T'
Some(hash T) ≠ Some(hash T'), so DoubleSpendGame.m1 ≠ DoubleSpendGame.m2
with both non-None --> BindingReduction(A) wins.
Hence Adv[DS] ≤ Adv[Coll] + Adv[Bind].
EasyCrypt steps:
1. byequiv (using A_attack_coupling):
Pr[CollisionGame(CollisionReduction(A))] =
Pr[DoubleSpendGame(A) on DoubleSpendGame.result collision sub-event]
2. byequiv (using A_attack_coupling):
Pr[BindingGame(BindingReduction(A))] =
Pr[DoubleSpendGame(A) on DoubleSpendGame.m1/m2 binding-break sub-event]
3. Pr[mu_le]: res ==> (collision \/ binding-break)
4. Pr[mu_or_le]: union bound
5. Rewrite via Steps 1-2.
*)
require import AllCore.
(* --- Basic Types --- *)
type pubkey.
type state_hash.
type tx_hash.
type signature.
type commitment.
type decommitment.
type transaction_data.
(* --- Protocol Operations --- *)
op verify : pubkey -> state_hash * tx_hash -> signature -> bool.
op hash : transaction_data -> state_hash.
op open : commitment -> decommitment -> state_hash option.
(* ==================================================================== *)
(* 1. Pure Mathematical Logic *)
(* ==================================================================== *)
op is_collision (t1 t2 : transaction_data) : bool =
t1 <> t2 /\ hash t1 = hash t2.
op is_binding_break (m1 m2 : state_hash option) : bool =
m1 <> None /\ m2 <> None /\ m1 <> m2.
op is_double_spend (t1 t2 : transaction_data) (m1 m2 : state_hash option) : bool =
t1 <> t2 /\ m1 = Some (hash t1) /\ m2 = Some (hash t2).
(* Pure lemma: A double spend mathematically guarantees a broken primitive *)
lemma ds_implies_coll_or_bind t1 t2 m1 m2 :
is_double_spend t1 t2 m1 m2 =>
is_collision t1 t2 \/ is_binding_break m1 m2.
proof. smt(). qed.
(* ==================================================================== *)
(* 2. Cryptographic Games *)
(* ==================================================================== *)
module type CollisionAdversary = {
proc find() : transaction_data * transaction_data
}.
module CollisionGame(A : CollisionAdversary) = {
proc main() : bool = {
var result : transaction_data * transaction_data;
result <@ A.find();
return is_collision result.`1 result.`2;
}
}.
module type BindingAdversary = {
proc attack() : commitment * decommitment * decommitment
}.
module BindingGame(A : BindingAdversary) = {
proc main() : bool = {
var result : commitment * decommitment * decommitment;
var m1, m2 : state_hash option;
result <@ A.attack();
m1 <- open result.`1 result.`2;
m2 <- open result.`1 result.`3;
return is_binding_break m1 m2;
}
}.
module type DoubleSpendAdversary = {
proc attack() : transaction_data * transaction_data * commitment * decommitment * decommitment
}.
module DoubleSpendGame(A : DoubleSpendAdversary) = {
var result : transaction_data * transaction_data * commitment * decommitment * decommitment
var m1, m2 : state_hash option
proc main() : bool = {
result <@ A.attack();
m1 <- open result.`3 result.`4;
m2 <- open result.`3 result.`5;
return is_double_spend result.`1 result.`2 m1 m2;
}
}.
(* ==================================================================== *)
(* 3. Security Reductions & Main Theorem *)
(* ==================================================================== *)
section DoubleSpendSecurity.
declare module A <: DoubleSpendAdversary.
module CollisionReduction(B : DoubleSpendAdversary) : CollisionAdversary = {
proc find() : transaction_data * transaction_data = {
var result : transaction_data * transaction_data * commitment * decommitment * decommitment;
result <@ B.attack();
return (result.`1, result.`2);
}
}.
module BindingReduction(B : DoubleSpendAdversary) : BindingAdversary = {
proc attack() : commitment * decommitment * decommitment = {
var result : transaction_data * transaction_data * commitment * decommitment * decommitment;
result <@ B.attack();
return (result.`3, result.`4, result.`5);
}
}.
(* pRHL reflexivity: running the adversary from identical states yields identical results *)
declare axiom A_attack_coupling :
equiv[A.attack ~ A.attack : ={glob A} ==> ={glob A, res}].
(* Main Security Theorem *)
lemma double_spend_security &m :
Pr[DoubleSpendGame(A).main() @ &m : res] <=
Pr[CollisionGame(CollisionReduction(A)).main() @ &m : res] +
Pr[BindingGame(BindingReduction(A)).main() @ &m : res].
proof.
(* Step 1: Relate CollisionGame to DoubleSpendGame's collision sub-event *)
have hcoll : Pr[CollisionGame(CollisionReduction(A)).main() @ &m : res] =
Pr[DoubleSpendGame(A).main() @ &m : is_collision DoubleSpendGame.result.`1 DoubleSpendGame.result.`2].
- byequiv => //;
proc;
inline *;
wp;
call A_attack_coupling;
skip => />.
(* Step 2: Relate BindingGame to DoubleSpendGame's binding sub-event *)
have hbind : Pr[BindingGame(BindingReduction(A)).main() @ &m : res] =
Pr[DoubleSpendGame(A).main() @ &m : is_binding_break DoubleSpendGame.m1 DoubleSpendGame.m2].
- byequiv => //;
proc;
inline *;
wp;
call A_attack_coupling;
skip => />.
(* Step 3: Probability monotonicity (Winning DS implies one of the sub-events) *)
have hmon : Pr[DoubleSpendGame(A).main() @ &m : res] <=
Pr[DoubleSpendGame(A).main() @ &m :
is_collision DoubleSpendGame.result.`1 DoubleSpendGame.result.`2 \/
is_binding_break DoubleSpendGame.m1 DoubleSpendGame.m2].
- byequiv (: ={glob A} ==>
res{1} =>
is_collision DoubleSpendGame.result{2}.`1 DoubleSpendGame.result{2}.`2 \/
is_binding_break DoubleSpendGame.m1{2} DoubleSpendGame.m2{2}) => //.
proc;
wp;
call A_attack_coupling;
skip => />.
smt(ds_implies_coll_or_bind). (* Apply our pure mathematical lemma *)
(* Step 4: Union bound on the disjunctive event *)
have hunion :
Pr[DoubleSpendGame(A).main() @ &m :
is_collision DoubleSpendGame.result.`1 DoubleSpendGame.result.`2 \/
is_binding_break DoubleSpendGame.m1 DoubleSpendGame.m2] <=
Pr[DoubleSpendGame(A).main() @ &m : is_collision DoubleSpendGame.result.`1 DoubleSpendGame.result.`2] +
Pr[DoubleSpendGame(A).main() @ &m : is_binding_break DoubleSpendGame.m1 DoubleSpendGame.m2].
- rewrite Pr[mu_or].
(* Prove the intersection is >= 0 by bounding it below by Pr[false] *)
have h_ge0 : 0%r <= Pr[DoubleSpendGame(A).main() @ &m :
is_collision DoubleSpendGame.result.`1 DoubleSpendGame.result.`2 /\
is_binding_break DoubleSpendGame.m1 DoubleSpendGame.m2].
+ have Hzero : Pr[DoubleSpendGame(A).main() @ &m : false] = 0%r by rewrite Pr[mu_false].
rewrite -Hzero.
byequiv => //;
proc;
wp;
call A_attack_coupling;
skip => />.
smt().
(* Step 5: Chain the inequalities hmon hunion hcoll hbind together *)
smt().
qed.
end section DoubleSpendSecurity.
(*
Security bounds: For any double-spending adversary A:
Adv^ds_Unicity(A) <= Adv^coll_H(CollisionReduction(A)) + Adv^bind_Com(BindingReduction(A))
Double-spending security reduces to:
1. Collision resistance of the hash function H
2. Computational binding of the commitment scheme
*)