nada_dsl.nada_types

function.py

Nada function definitions and utilities.

class NadaFunctionArg(function_id: int, name: str, arg_type: T, source_ref: SourceRef)[source]

Bases: Generic[T]

Represents a Nada function argument.

function_id: int
name: str
type: T
source_ref: SourceRef
store_in_ast(ty)[source]

Store object in AST.

__orig_bases__ = (typing.Generic[~T],)
__parameters__ = (~T,)
class NadaFunction(function_id: int, args: List[NadaFunctionArg], function: Callable[[T], R], return_type: R, source_ref: SourceRef, inner: NadaType)[source]

Bases: Generic[T, R]

Nada Function.

Represents a Nada Function. Nada functions are special types of functions that are used in map / reduce operations.

They are decorated using the @nada_fn decorator.

id: int
args: List[NadaFunctionArg]
function: Callable[[T], R]
return_type: R
source_ref: SourceRef
store_in_ast()[source]

Store this Nada Function in AST.

__call__(*args, **kwargs) R[source]

Call self as a function.

__orig_bases__ = (typing.Generic[~T, ~R],)
__parameters__ = (~T, ~R)
class NadaFunctionCall(nada_function, args, source_ref)[source]

Bases: Generic[R]

Represents a call to a Nada Function.

__eq__(other)

Return self==value.

__orig_bases__ = (typing.Generic[~R],)
__parameters__ = (~R,)
args: List[NadaType]
fn: NadaFunction
source_ref: SourceRef
store_in_ast(ty)[source]

Store this function call in the AST.

inner_type(ty)[source]

Utility function that calculates the inner type for a function argument.

nada_fn(fn, args_ty=None, return_ty=None) NadaFunction[T, R][source]

Can be used also for lambdas ```python array.map(

nada_fn(

lambda x: x.cast(SecretInteger), args_ty={‘x’: SecretInteger}, return_ty=SecretInteger))

```

Generic type definitions for Nada.

The Nada Scalar type definitions.

class ScalarType(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal, base_type: BaseType, mode: Mode)[source]

Bases: NadaType

The Nada Scalar type. This is the super class for all scalar types in Nada. These are:

  • Boolean, PublicBoolean, SecretBoolean

  • Integer, PublicInteger, SecretInteger

  • UnsignedInteger, PublicUnsignedInteger, SecretUnsignedInteger

ScalarType provides common operation implementations for all the scalar types based on the typing rules of the Nada model.

value: Any
base_type: BaseType
mode: Mode
__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

__ne__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self!=value.

to_public() Self[source]

Convert this scalar type into a public variable.

equals_operation(operation, operator, left: ScalarType, right: ScalarType, f) Boolean | PublicBoolean | SecretBoolean[source]

This function is an abstraction for the equality operations

register_scalar_type(mode: Mode, base_type: BaseType)[source]

Decorator used to register a new scalar type in the SCALAR_TYPES dictionary.

new_scalar_type(mode: Mode, base_type: BaseType) type[Integer | UnsignedInteger | Boolean | PublicInteger | PublicUnsignedInteger | PublicBoolean | SecretInteger | SecretUnsignedInteger | SecretBoolean][source]

Returns the corresponding MIR Nada Type

class NumericType(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal, base_type: BaseType, mode: Mode)[source]

Bases: ScalarType

The superclass of all the numeric types in Nada: - Integer, PublicInteger, SecretInteger - UnsignedInteger, PublicUnsignedInteger, SecretUnsignedInteger It provides common operation implementations for all the numeric types based on the typing rules of the Nada model.

value: int
__add__(other)[source]
__sub__(other)[source]
__mul__(other)[source]
__truediv__(other)[source]
__mod__(other)[source]
__pow__(other)[source]
__lshift__(other)[source]
__rshift__(other)[source]
__lt__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self<value.

__gt__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self>value.

__le__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self<=value.

__ge__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self>=value.

__radd__(other)[source]

This adds support for builtin sum operation for numeric types.

binary_arithmetic_operation(operation, operator, left: ScalarType, right: ScalarType, f) ScalarType[source]

This function is an abstraction for the binary arithmetic operations.

Arithmetic operations apply to Numeric types only in Nada.

shift_operation(operation, operator, left: ScalarType, right: ScalarType, f) ScalarType[source]

This function is an abstraction for the shift operations

binary_relational_operation(operation, operator, left: ScalarType, right: ScalarType, f) Boolean | PublicBoolean | SecretBoolean[source]

This function is an abstraction for the binary relational operations

public_equals_operation(left: ScalarType, right: ScalarType) PublicBoolean[source]

This function is an abstraction for the public_equals operation for all types.

class BooleanType(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal, base_type: BaseType, mode: Mode)[source]

Bases: ScalarType

This abstraction represents all boolean types: - Boolean, PublicBoolean, SecretBoolean It provides common operation implementations for all the boolean types, defined above.

__and__(other)[source]
__or__(other)[source]

Return self|value.

__xor__(other)[source]
if_else(arg_0: _AnyScalarType, arg_1: _AnyScalarType) _AnyScalarType[source]

This function implements the function ‘if_else’ for every class that extends ‘BooleanType’.

binary_logical_operation(operation, operator, left: ScalarType, right: ScalarType, f) ScalarType[source]

This function is an abstraction for the logical operations.

class Integer(value)[source]

Bases: NumericType

The Nada Integer type.

Represents a constant (literal) integer.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

base_type: BaseType = 2
mode: Mode = 1
class UnsignedInteger(value)[source]

Bases: NumericType

The Nada Unsigned Integer type.

Represents a constant (literal) unsigned integer.

value: int
__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

base_type: BaseType = 3
mode: Mode = 1
class Boolean(value)[source]

Bases: BooleanType

The Nada Boolean type.

Represents a constant (literal) boolean.

value: bool
__bool__() bool[source]
__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

__invert__() Boolean[source]
base_type: BaseType = 1
mode: Mode = 1
class PublicInteger(inner: NadaType)[source]

Bases: NumericType

The Nada Public Unsigned Integer type.

Represents a public unsigned integer in a program. This is a public variable evaluated at runtime.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

public_equals(other: PublicInteger | SecretInteger) PublicBoolean[source]

Implementation of public equality for Public integer types.

base_type: BaseType = 2
mode: Mode = 2
class PublicUnsignedInteger(inner: NadaType)[source]

Bases: NumericType

The Nada Public Integer type.

Represents a public integer in a program. This is a public variable evaluated at runtime.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

public_equals(other: PublicUnsignedInteger | SecretUnsignedInteger) PublicBoolean[source]

Implementation of public equality for Public unsigned integer types.

base_type: BaseType = 3
mode: Mode = 2
class PublicBoolean(inner: NadaType)[source]

Bases: BooleanType

The Nada Public Boolean type.

Represents a public boolean in a program. This is a public variable evaluated at runtime.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

__invert__() PublicBoolean[source]
public_equals(other: PublicUnsignedInteger | SecretUnsignedInteger) PublicBoolean[source]

Implementation of public equality for Public boolean types.

base_type: BaseType = 1
mode: Mode = 2
class SecretInteger(inner: NadaType)[source]

Bases: NumericType

The Nada secret integer type.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

public_equals(other: PublicInteger | SecretInteger) PublicBoolean[source]

Implementation of public equality for secret integer types.

trunc_pr(other: PublicUnsignedInteger | UnsignedInteger) SecretInteger[source]

Probabilistic truncation for secret integers.

classmethod random() SecretInteger[source]

Random operation for Secret integers.

to_public() PublicInteger[source]

Convert this secret integer into a public variable.

base_type: BaseType = 2
mode: Mode = 3
class SecretUnsignedInteger(inner: NadaType)[source]

Bases: NumericType

The Nada Secret Unsigned integer type.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

public_equals(other: PublicUnsignedInteger | SecretUnsignedInteger) PublicBoolean[source]

The public equality operation.

trunc_pr(other: PublicUnsignedInteger | UnsignedInteger) SecretUnsignedInteger[source]

Probabilistic truncation operation.

classmethod random() SecretUnsignedInteger[source]

Generate a random secret unsigned integer.

to_public() PublicUnsignedInteger[source]

Convert this secret into a public variable.

base_type: BaseType = 3
mode: Mode = 3
class SecretBoolean(inner: NadaType)[source]

Bases: BooleanType

The SecretBoolean Nada MIR type.

__eq__(other) Boolean | PublicBoolean | SecretBoolean[source]

Return self==value.

__invert__() SecretBoolean[source]
to_public() PublicBoolean[source]

Convert this secret into a public variable.

classmethod random() SecretBoolean[source]

Generate a random secret boolean.

base_type: BaseType = 1
mode: Mode = 3
class EcdsaSignature(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal)[source]

Bases: NadaType

The EcdsaSignature Nada MIR type.

__eq__(other)

Return self==value.

class EcdsaDigestMessage(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal)[source]

Bases: NadaType

The EcdsaDigestMessage Nada MIR type.

__eq__(other)

Return self==value.

class EcdsaPrivateKey(inner: Addition | Subtraction | Multiplication | Division | Modulo | Power | RightShift | LeftShift | LessThan | GreaterThan | LessOrEqualThan | GreaterOrEqualThan | Equals | Input | Cast | Map | Zip | Reduce | Unzip | Literal)[source]

Bases: NadaType

The EcdsaPrivateKey Nada MIR type.

__eq__(other)

Return self==value.

ecdsa_sign(digest: EcdsaDigestMessage) EcdsaSignature[source]

Random operation for Secret integers.