Skip to main content

Literals

Literals are constant values defined within the program rather than provided by a party.

Integer

Integer represents a literal integer value. This value can be a negative integer, a positive integer, or zero.

src/addition_literal.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))
literal = Integer(7)
sum = num_1 + num_2 + literal
return [Output(sum, "sum", party_charlie)]

Run and test the addition_literal program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run addition_literal_test

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

nada test addition_literal_test

UnsignedInteger

UnsignedInteger represents a literal unsigned integer value. This value can be zero or a positive integer.

src/addition_literal_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))
literal = UnsignedInteger(7)
sum = num_1 + num_2 + literal
return [Output(sum, "sum", party_charlie)]

Run and test the addition_literal_unsigned program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run addition_literal_unsigned_test

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

nada test addition_literal_unsigned_test

Boolean

Boolean represents a literal boolean value defined within the program rather than provided by a party. This value can be true or false.

src/literal_boolean.py
from nada_dsl import *

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

# Start value for literal boolean
is_sum_greater_than_five = Boolean(False)

public_num_1 = PublicInteger(Input(name="public_num_1", party=party_alice))
public_num_2 = PublicInteger(Input(name="public_num_2", party=party_bob))
is_sum_greater_than_five = (public_num_1 + public_num_2) > Integer(5)

return [Output(is_sum_greater_than_five, "result", party_charlie)]

Run and test the literal_boolean program

1. Open "Nada by Example"

Open in Gitpod

2. Run the program with inputs from the test file

nada run literal_boolean_test

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

nada test literal_boolean_test
Feedback