Skip to main content

Public

The Public data type is used for inputs that are not sensitive and can be shown in the clear during computation. These input values are visible to the program.

PublicInteger

PublicInteger represents a user input public integer value. This value can be a negative integer, a positive integer, or zero.

src/addition_public.py
from nada_dsl import *

def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
num_1 = SecretInteger(Input(name="num_1", party=party_alice))
num_2 = SecretInteger(Input(name="num_2", party=party_bob))
public_num = PublicInteger(Input(name="public_num", party=party_charlie))
sum = num_1 + num_2 + public_num
return [Output(sum, "sum", party_charlie)]

Run and test the addition_public program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run addition_public_test

3. Test the program with inputs from the test file against the expected_outputs from the test file

nada test addition_public_test

PublicUnsignedInteger

PublicUnsignedInteger represents a user input public unsigned integer value. This value can be zero or a positive integer.

src/addition_public_unsigned.py
from nada_dsl import *

def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
num_1 = SecretUnsignedInteger(Input(name="num_1", party=party_alice))
num_2 = SecretUnsignedInteger(Input(name="num_2", party=party_bob))
public_num = PublicUnsignedInteger(Input(name="public_num", party=party_charlie))
sum = num_1 + num_2 + public_num
return [Output(sum, "sum", party_charlie)]

Run and test the addition_public_unsigned program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run addition_public_unsigned_test

3. Test the program with inputs from the test file against the expected_outputs from the test file

nada test addition_public_unsigned_test

PublicBoolean

PublicBoolean represents a user input public boolean value. This value can be true or false.

src/public_conditional.py
from nada_dsl import *

def nada_main():
party_weatherman = Party(name="Weather Man")
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")

# The Weather Man inputs a public boolean
is_raining = PublicBoolean(Input(name="is_raining", party=party_weatherman))

num_1 = SecretInteger(Input(name="num_1", party=party_alice))
num_2 = SecretInteger(Input(name="num_2", party=party_bob))
sum = num_1 + num_2

# If is raining is true, add 1 to the sum
result = is_raining.if_else(sum + Integer(1), sum)

# Charlie receives the result, but doesn't know
# whether Bob's original input has doubled
return [Output(result, "result", party_charlie)]

Run and test the public_conditional program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run public_conditional_test

3. Test the program with inputs from the test file against the expected_outputs from the test file

nada test public_conditional_test
Feedback