Skip to main content

Built-In Operations

Overview of the primitive and the array Nada operations.

Primitive Operations​

NameSyntaxSupported Types
(P: Public, S: Secret)
Additionx + yP ← P + P,
S ← P + S,
S ← S + P,
S ← S + S
Subtractionx - yP ← P - P,
S ← P - S,
S ← S - P,
S ← S - S
Multiplicationx * yP ← P * P,
S ← P * S,
S ← S * P,
S ← S * S
Powerx ** yP ← P ** P
Divisionx / yP ← P / P,
S ← P / S,
S ← S / P,
S ← S / S
Modulox % yP ← P % P,
S ← P % S,
S ← S % P,
S ← S % S
Comparisonsx < y,
x <= y,
x > y,
x >= y
P ← P < P,
S ← P < S,
S ← S < P,
S ← S < S
Ternary "if else"
(public condition)
cond.if_else(x, y)P ← P.if_else(P, P),
S ← P.if_else(P, S),
S ← P.if_else(S, P),
S ← P.if_else(S, S)
Ternary "if else"
(secret condition)
cond.if_else(x, y)S ← S.if_else(P, P),
S ← S.if_else(P, S),
S ← S.if_else(S, P),
S ← S.if_else(S, S)
Reveal (convert a private
value into a public value)
x.reveal()P ← S.reveal()
Public Equality (publicly output
if two secrets are equal)
x.public_equals(y)P ← S.public_equals(S)

Array Operations (Experimental Feature)​

warning

Arrays are a new feature in the Nada language. We hope you find them handy, though there might still be undiscovered bugs. If you encounter anything, please flag them by opening an issue in nillion-python-starter.

NameSyntaxDescription
nada_fnnada_fn(lambda x: x, args_ty={'x': SecretInteger}, return_ty=SecretInteger)Inline function, only to be used with map and reduce.
map()array.map(nada_fn(...))Applies the provided nada_fn to every element in the array.
reduce()array.reduce(nada_fn(...), acc)The reduce() method executes a provided function (nada_fn) once for each element in the array, resulting in a single output value. The nada_fn accepts two arguments: 1. The accumulator acc accumulates the return values. 2. Each element of the array.
zip()array_1.zip(array_2)Combines two arrays into an array of Tuples.
unzip()unzip(array_1.zip(array_2))Returns a tuple of two arrays.