Secret
The Secret data type is used for inputs that need to be kept confidential during computation. These input values are not visible to the program.
SecretInteger
SecretInteger
represents a user input secret integer value. This value can be a negative integer, a positive integer, or zero.
- Nada program
- Test file
src/multiplication.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))
product = num_1 * num_2
return [Output(product, "product", party_charlie)]
tests/multiplication_test.yaml
---
program: multiplication
inputs:
num_1: 3
num_2: -2
expected_outputs:
product: -6
Run and test the multiplication program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run multiplication_test
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test multiplication_test
SecretUnsignedInteger
SecretUnsignedInteger
represents a user input secret unsigned integer value. This value can be zero or a positive integer.
- Nada program
- Test file
src/addition_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))
sum = num_1 + num_2
return [Output(sum, "sum", party_charlie)]
tests/addition_unsigned_test.yaml
---
program: addition_unsigned
inputs:
num_1: 5
num_2: 3
expected_outputs:
sum: 8
Run and test the addition_unsigned program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run addition_unsigned_test
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test addition_unsigned_test
SecretBoolean
SecretBoolean
represents a user input secret boolean value. This value can be true or false.
- Nada program
- Test file
src/secret_conditional.py
from nada_dsl import *
def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
# Alice inputs a secret boolean that determines whether or not to double Bob's secret input
should_double = SecretBoolean(Input(name="should_double", party=party_alice))
secret_num = SecretInteger(Input(name="secret_num", party=party_bob))
result = should_double.if_else(secret_num * Integer(2), secret_num)
# Charlie receives the result, but doesn't know
# whether Bob's original input has doubled
return [Output(result, "result", party_charlie)]
tests/secret_conditional_test.yaml
---
program: secret_conditional
inputs:
should_double: true
secret_num: 3
expected_outputs:
result: 6
Run and test the secret_conditional program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run secret_conditional_test
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test secret_conditional_test