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

my new nada program #66

Open
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions nillion-python-starter
Submodule nillion-python-starter added at 15e9fe
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/.tmp9lvTYz (80.01Gbs available)
🏃 starting nilchain node in: /tmp/.tmp9lvTYz/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
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
81 changes: 81 additions & 0 deletions quickstart/nada_quickstart_programs/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from nada_dsl import *


def initialize_participants(nr_participants):
"""
Initialize participants with unique identifiers.

Parameters:
- nr_participants (int): Number of participants.

Returns:
- participants (list): List of Party objects representing participants.
"""
participants = []
for i in range(nr_participants):
participants.append(Party(name="Participant" + str(i)))
return participants


def inputs_initialization(nr_participants, participants):
"""
Initialize inputs for each participant's chosen number.

Parameters:
- nr_participants (int): Number of participants.

Returns:
- chosen_numbers (list): List representing chosen numbers for each participant.
"""
chosen_numbers = []
for p in range(nr_participants):
chosen_numbers.append(
SecretUnsignedInteger(Input(name="chosen_number_p" + str(p), party=participants[p]))
)
return chosen_numbers


def determine_winner(nr_participants, chosen_numbers, winning_number, outparty):
"""
Determine the winner based on the closest match to the winning number.

Parameters:
- nr_participants (int): Number of participants.
- chosen_numbers (list): List representing chosen numbers for each participant.
- winning_number (UnsignedInteger): The predetermined winning number.

Returns:
- winner_output (Output): Output object representing the winner's identifier.
"""
closest_diff = UnsignedInteger(2**32 - 1) # Initialize with a large number
winner_id = UnsignedInteger(0)

for p in range(nr_participants):
diff = (chosen_numbers[p] - winning_number).abs()
is_closer = diff < closest_diff
closest_diff = is_closer.if_else(diff, closest_diff)
winner_id = is_closer.if_else(UnsignedInteger(p), winner_id)

winner_output = Output(winner_id, "winner_id", outparty)
return winner_output


def nada_main():
# Number of participants
nr_participants = 3

# Predetermined winning number
winning_number = UnsignedInteger(50) # You can set this to any number

# Parties initialization
participants = initialize_participants(nr_participants)
outparty = Party(name="OutParty")

# Inputs initialization
chosen_numbers = inputs_initialization(nr_participants, participants)

# Determine the winner
winner_output = determine_winner(nr_participants, chosen_numbers, winning_number, outparty)

# Output the result
return [winner_output]
Binary file not shown.
Binary file not shown.