Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nillion Task submissioni #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions nohup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ℹ️ cluster id is 9e68173f-9c23-4acc-ba81-4f079b639964
ℹ️ using 256 bit prime
ℹ️ storing state in /tmp/.tmpHzFClx (80.04Gbs available)
🏃 starting nilchain node in: /tmp/.tmpHzFClx/nillion-chain
⛓ nilchain JSON RPC available at http://127.0.0.1:48102
⛓ nilchain REST API available at http://localhost:26650
⛓ nilchain gRPC available at localhost:26649
🏃 starting node 12D3KooWMvw1hEqm7EWSDEyqTb6pNetUVkepahKY6hixuAuMZfJS
⏳ waiting until bootnode is up...
🏃 starting node 12D3KooWAiwGZUwSUaT2bYVxGS8jmfMrfsanZYkHwH3uL7WJPsFq
🏃 starting node 12D3KooWM3hsAswc7ZT6VpwQ1TCZU4GCYY55nLhcsxCcfjuixW57
👛 funding nilchain keys
📝 nillion CLI configuration written to /root/.config/nillion/nillion-cli.yaml
🌄 environment file written to /root/.config/nillion/nillion-devnet.env
59 changes: 59 additions & 0 deletions quickstart/client_code/run_my_first_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from nada_dsl import *

def create_parties(num_managers):
parties = []
for i in range(num_managers):
parties.append(Party(name="Manager" + str(i)))
return parties

def initialize_inputs(num_managers, num_employees, parties):
employee_scores = []
for e in range(num_employees):
employee_scores.append([])
for m in range(num_managers):
employee_scores[e].append(
SecretUnsignedInteger(
Input(name="m" + str(m) + "_e" + str(e), party=parties[m])
)
)
return employee_scores

def calculate_average_scores(num_managers, num_employees, employee_scores, output_party):
avg_scores = []
for e in range(num_employees):
total_score = employee_scores[e][0]
for m in range(1, num_managers):
total_score += employee_scores[e][m]
average_score = total_score / UnsignedInteger(num_managers)
avg_scores.append(Output(average_score, "avg_score_e" + str(e), output_party))
return avg_scores

def validate_scores(num_managers, num_employees, employee_scores, max_score, output_party):
score_validations = []
reveal_cheating = []
for e in range(num_employees):
for m in range(num_managers):
score = employee_scores[e][m]
is_valid = score <= UnsignedInteger(max_score)
score_validations.append(Output(is_valid, "check_score_m" + str(m) + "_e" + str(e), output_party))
reveal_cheat = is_valid.if_else(UnsignedInteger(0), score)
reveal_cheating.append(Output(reveal_cheat, "if_cheat_open_m" + str(m) + "_e" + str(e), output_party))
return score_validations, reveal_cheating

def nada_main():
num_managers = 3
num_employees = 2
max_allowed_score = 10

parties = create_parties(num_managers)
output_party = Party(name="OutputParty")

employee_scores = initialize_inputs(num_managers, num_employees, parties)

avg_scores = calculate_average_scores(num_managers, num_employees, employee_scores, output_party)
score_validations, reveal_cheating = validate_scores(num_managers, num_employees, employee_scores, max_allowed_score, output_party)

results = avg_scores + score_validations + reveal_cheating
return results

nada_main()
7 changes: 7 additions & 0 deletions quickstart/nada_quickstart_programs/nada-project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "nada_quickstart_programs"
version = "0.1.0"
authors = [""]

[[programs]]
path = "src/main.py"
prime_size = 128
12 changes: 12 additions & 0 deletions quickstart/nada_quickstart_programs/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from nada_dsl import *

def nada_main():
party1 = Party(name="Party1")
party2 = Party(name="Party2")
party3 = Party(name="Party3")
a = SecretInteger(Input(name="A", party=party1))
b = SecretInteger(Input(name="B", party=party2))

result = a + b

return [Output(result, "my_output", party3)]
Binary file not shown.
Binary file not shown.