forked from NillionNetwork/nillion-python-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoting_honest_1.py
38 lines (31 loc) · 1.12 KB
/
voting_honest_1.py
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
"""
PROGRAM 1
nr of voters: m = 3
nr of candidates: n = 2
"""
from nada_dsl import *
def nada_main():
# 1. Parties initialization
voter0 = Party(name="Voter0")
voter1 = Party(name="Voter1")
voter2 = Party(name="Voter2")
outparty = Party(name="OutParty")
# 2. Inputs initialization
## Votes from voter 0
v0_c0 = SecretUnsignedInteger(Input(name="v0_c0", party=voter0))
v0_c1 = SecretUnsignedInteger(Input(name="v0_c1", party=voter0))
## Votes from voter 1
v1_c0 = SecretUnsignedInteger(Input(name="v1_c0", party=voter1))
v1_c1 = SecretUnsignedInteger(Input(name="v1_c1", party=voter1))
## Votes from voter 2
v2_c0 = SecretUnsignedInteger(Input(name="v2_c0", party=voter2))
v2_c1 = SecretUnsignedInteger(Input(name="v2_c1", party=voter2))
# 3. Computation
## Add votes for candidate 0
result_c0 = v0_c0 + v1_c0 + v2_c0
## Add votes for candidate 1
result_c1 = v0_c1 + v1_c1 + v2_c1
# 4. Output
result_c0 = Output(result_c0, "final_vote_count_c0", outparty)
result_c1 = Output(result_c1, "final_vote_count_c1", outparty)
return [result_c0, result_c1]