Skip to content

Commit 2ccf700

Browse files
authored
Merge pull request #48 from OpenMined/pryvote_shamir_protocol
Pryvote shamir protocol
2 parents ee22cd2 + df2f325 commit 2ccf700

File tree

3 files changed

+607
-21
lines changed

3 files changed

+607
-21
lines changed

projects/pryvote/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,28 @@ The project is in early development.
1515

1616
## Examples
1717

18-
#### [Secure Multi-Party Voting](./demo/secure_multi_party_voting.ipynb)
18+
#### [Secure Multi-Party Voting](./demo/1_secure_multi_party_voting.ipynb)
1919

2020
POC of secure multi-party voting.
21-
No credential verification/SSI in place at the moment.
21+
Each vote is encrypted and split
22+
between multiple vote counters.
23+
At the end of voting,
24+
the vote counters combine
25+
their encrypted shares
26+
to reveal the aggregate result.
27+
28+
**No credential verification/SSI in place at the moment.**
29+
30+
#### [Shamir Secret Sharing](./demo/2_shamir_secret_sharing_voting.ipynb)
31+
32+
The Shamir Secret Sharing protocol
33+
is similar to SMPV,
34+
however only a subset of vote counters
35+
are required for the aggregate result
36+
to be decrypted.
37+
Therefore,
38+
this protocol is somewhat robust
39+
to malicious
40+
vote counters.
41+
42+
**No credential verification/SSI in place at the moment.**

projects/pryvote/demo/secure_multi_party_voting.ipynb renamed to projects/pryvote/demo/1_secure_multi_party_voting.ipynb

Lines changed: 104 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": null,
39+
"execution_count": 1,
4040
"metadata": {},
4141
"outputs": [],
4242
"source": [
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"cell_type": "code",
60-
"execution_count": null,
60+
"execution_count": 2,
6161
"metadata": {},
6262
"outputs": [],
6363
"source": [
@@ -82,7 +82,7 @@
8282
},
8383
{
8484
"cell_type": "code",
85-
"execution_count": null,
85+
"execution_count": 3,
8686
"metadata": {},
8787
"outputs": [],
8888
"source": [
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"cell_type": "code",
112-
"execution_count": null,
112+
"execution_count": 4,
113113
"metadata": {},
114114
"outputs": [],
115115
"source": [
@@ -124,7 +124,7 @@
124124
" vote_class = pricon_vote.get_vote_class(vote_value)\n",
125125
"\n",
126126
" onehot_votes = [0] * len(pricon_vote)\n",
127-
" onehot_votes[vote_class] = 1\n",
127+
" onehot_votes[vote_class] = 1 # [1, 0, 0]\n",
128128
" \n",
129129
" vote_shares = [self._encrypt_vote(binary_vote) for binary_vote in onehot_votes]\n",
130130
"\n",
@@ -134,9 +134,9 @@
134134
" self._vote_shares = None\n",
135135
"\n",
136136
" def _encrypt_vote(self, vote: int):\n",
137-
" share_a = random.randint(-Q,Q)\n",
138-
" share_b = random.randint(-Q,Q)\n",
139-
" share_c = (vote - share_a - share_b) % Q\n",
137+
" share_a = random.randint(-self._Q,self._Q)\n",
138+
" share_b = random.randint(-self._Q,self._Q)\n",
139+
" share_c = (vote - share_a - share_b) % self._Q\n",
140140
" return (share_a, share_b, share_c)\n",
141141
"\n",
142142
" def send_vote(self, parties) -> None:\n",
@@ -152,7 +152,7 @@
152152
},
153153
{
154154
"cell_type": "code",
155-
"execution_count": null,
155+
"execution_count": 5,
156156
"metadata": {},
157157
"outputs": [],
158158
"source": [
@@ -183,7 +183,7 @@
183183
},
184184
{
185185
"cell_type": "code",
186-
"execution_count": null,
186+
"execution_count": 6,
187187
"metadata": {},
188188
"outputs": [],
189189
"source": [
@@ -201,7 +201,7 @@
201201
},
202202
{
203203
"cell_type": "code",
204-
"execution_count": null,
204+
"execution_count": 7,
205205
"metadata": {},
206206
"outputs": [],
207207
"source": [
@@ -212,7 +212,7 @@
212212
},
213213
{
214214
"cell_type": "code",
215-
"execution_count": null,
215+
"execution_count": 8,
216216
"metadata": {},
217217
"outputs": [],
218218
"source": [
@@ -244,7 +244,7 @@
244244
},
245245
{
246246
"cell_type": "code",
247-
"execution_count": null,
247+
"execution_count": 9,
248248
"metadata": {},
249249
"outputs": [],
250250
"source": [
@@ -254,19 +254,74 @@
254254
"dan.update_vote(\"PryVote\")\n",
255255
"eve.update_vote(\"PyDP\")\n",
256256
"fran.update_vote(\"PyVertical\")\n",
257-
"greg.update_vote(\"PrivacyRaven\")"
257+
"greg.update_vote(\"PyVertical\")"
258258
]
259259
},
260260
{
261261
"cell_type": "code",
262-
"execution_count": null,
262+
"execution_count": 10,
263263
"metadata": {},
264-
"outputs": [],
264+
"outputs": [
265+
{
266+
"name": "stdout",
267+
"output_type": "stream",
268+
"text": [
269+
"red: Adding vote for 3a29334a-cff6-4a73-b681-29aa0bd3be41\n",
270+
"blue: Adding vote for 3a29334a-cff6-4a73-b681-29aa0bd3be41\n",
271+
"yellow: Adding vote for 3a29334a-cff6-4a73-b681-29aa0bd3be41\n",
272+
"red: Adding vote for c33db94b-8e5b-488f-ac39-91c74491f123\n",
273+
"blue: Adding vote for c33db94b-8e5b-488f-ac39-91c74491f123\n",
274+
"yellow: Adding vote for c33db94b-8e5b-488f-ac39-91c74491f123\n",
275+
"red: Adding vote for 0347145d-dd85-4ef8-930f-12dcff90190e\n",
276+
"blue: Adding vote for 0347145d-dd85-4ef8-930f-12dcff90190e\n",
277+
"yellow: Adding vote for 0347145d-dd85-4ef8-930f-12dcff90190e\n",
278+
"red: Adding vote for 5d88aa47-a73a-4e04-9111-fa0f0fef189d\n",
279+
"blue: Adding vote for 5d88aa47-a73a-4e04-9111-fa0f0fef189d\n",
280+
"yellow: Adding vote for 5d88aa47-a73a-4e04-9111-fa0f0fef189d\n",
281+
"red: Adding vote for 7e41730d-4270-490f-b227-a3ee719373eb\n",
282+
"blue: Adding vote for 7e41730d-4270-490f-b227-a3ee719373eb\n",
283+
"yellow: Adding vote for 7e41730d-4270-490f-b227-a3ee719373eb\n",
284+
"red: Adding vote for eb09cd17-166f-4fa4-8a89-ac7a199119e3\n",
285+
"blue: Adding vote for eb09cd17-166f-4fa4-8a89-ac7a199119e3\n",
286+
"yellow: Adding vote for eb09cd17-166f-4fa4-8a89-ac7a199119e3\n",
287+
"red: Adding vote for fd992cfa-bb52-4fdd-b42f-90c2b1107ac4\n",
288+
"blue: Adding vote for fd992cfa-bb52-4fdd-b42f-90c2b1107ac4\n",
289+
"yellow: Adding vote for fd992cfa-bb52-4fdd-b42f-90c2b1107ac4\n"
290+
]
291+
}
292+
],
265293
"source": [
266294
"for voter in [alice, bob, charlie, dan, eve, fran, greg]:\n",
267295
" voter.send_vote([red, blue, yellow])"
268296
]
269297
},
298+
{
299+
"cell_type": "markdown",
300+
"metadata": {},
301+
"source": [
302+
"What do the votes look like to a vote counter?"
303+
]
304+
},
305+
{
306+
"cell_type": "code",
307+
"execution_count": 11,
308+
"metadata": {},
309+
"outputs": [
310+
{
311+
"data": {
312+
"text/plain": [
313+
"[-1689120296584, -1384865635954, -859978157999]"
314+
]
315+
},
316+
"execution_count": 11,
317+
"metadata": {},
318+
"output_type": "execute_result"
319+
}
320+
],
321+
"source": [
322+
"red._vote_sum"
323+
]
324+
},
270325
{
271326
"cell_type": "markdown",
272327
"metadata": {},
@@ -287,9 +342,18 @@
287342
},
288343
{
289344
"cell_type": "code",
290-
"execution_count": null,
345+
"execution_count": 12,
291346
"metadata": {},
292-
"outputs": [],
347+
"outputs": [
348+
{
349+
"name": "stdout",
350+
"output_type": "stream",
351+
"text": [
352+
"Vote counts are [3, 2, 2]\n",
353+
"PryVote is the winner!\n"
354+
]
355+
}
356+
],
293357
"source": [
294358
"total_sums = []\n",
295359
"\n",
@@ -344,6 +408,27 @@
344408
"This could be solved by policy,\n",
345409
"such as frequent, independent auditing of a running vote aggregation during the lifetime of a vote session."
346410
]
411+
},
412+
{
413+
"cell_type": "code",
414+
"execution_count": null,
415+
"metadata": {},
416+
"outputs": [],
417+
"source": []
418+
},
419+
{
420+
"cell_type": "code",
421+
"execution_count": null,
422+
"metadata": {},
423+
"outputs": [],
424+
"source": []
425+
},
426+
{
427+
"cell_type": "code",
428+
"execution_count": null,
429+
"metadata": {},
430+
"outputs": [],
431+
"source": []
347432
}
348433
],
349434
"metadata": {
@@ -362,7 +447,7 @@
362447
"name": "python",
363448
"nbconvert_exporter": "python",
364449
"pygments_lexer": "ipython3",
365-
"version": "3.8.5"
450+
"version": "3.7.9"
366451
}
367452
},
368453
"nbformat": 4,

0 commit comments

Comments
 (0)