floating_point.extended_coroutine module

Module that extends the coroutine module in MPyC to support Secure Floating Point objects

floating_point.extended_coroutine.mpc_coro_extended(func)[source]

A wrapper for an MPC coroutine that ensures that the behaviour of the code is unaffected by the type annotations and supports secure floating points.

Parameters:

func (Callable[[ParamSpec(P, bound= None)], Coroutine[Any, Any, TypeVar(T)]]) – The async function to be wrapped

Return type:

Callable[[ParamSpec(P, bound= None)], TypeVar(T)]

Returns:

A new sync function that returns a placeholder for which a result will automatically be set when the coroutine has finished running

floating_point.extended_coroutine.mpc_coro_generic(reconciliation_function_task, reconciliation_function_result, func, apply_program_counter_wrapper=True, ignore_type_hints=False)[source]

Decorator turning coroutine func into an MPyC coroutine. An MPyC coroutine is evaluated asynchronously, returning empty placeholders. The type of the placeholders is defined either by a return annotation of the form “-> expression” or by the first await expression in func. Return annotations can only be used for static types.

Parameters:
  • reconciliation_function_task (Callable[[TypeVar(SecureNumberT, bound= SecureNumber), Task[TypeVar(SecureNumberT, bound= SecureNumber)]], None]) – function that takes a task and assigns its result to a dummy value

  • reconciliation_function_result (Callable[[TypeVar(SecureNumberT, bound= SecureNumber), TypeVar(SecureNumberT, bound= SecureNumber)], None]) – function that assigns a result to a dummy value

  • func (Callable[[ParamSpec(P, bound= None)], Coroutine[Any, Any, TypeVar(SecureNumberT, bound= SecureNumber)]]) – The async function to be wrapped

  • apply_program_counter_wrapper (bool) – A boolean value indicating whether a program counter wrapper should be applied

  • ignore_type_hints (bool) – A boolean indicating whether type annotations should be used by the code to deduce the type of the placeholder

Return type:

Callable[[ParamSpec(P, bound= None)], TypeVar(SecureNumberT, bound= SecureNumber)]

Returns:

A new sync function that returns a placeholder for which a result will automatically be set when the coroutine has finished running

floating_point.extended_coroutine.reconcile_placeholder_result(placeholder, result)[source]

Update a dummy variable with the result of a task.

Parameters:
  • placeholder (SecureNumber | Future[bool] | Future[SecureNumber] | list[SecureNumber | Future[SecureNumber]] | tuple[SecureNumber | Future[SecureNumber], ...]) – Dummy variable that needs to be updated with the result.

  • result (SecureNumber | Future[bool] | Future[PrimeFieldElement] | list[SecureNumber | Future[PrimeFieldElement]] | tuple[SecureNumber | Future[PrimeFieldElement], ...]) – A SecureObject that was the result of a Task.

Raises:
  • TypeError – If the types of placeholder and result are inconsistent.

  • ValueError – If the placeholder is already set

Return type:

None

floating_point.extended_coroutine.reconcile_placeholder_task(placeholder, task)[source]

Wait until the task has finished and then set the results to the correct objects.

Parameters:
  • placeholder (TypeVar(SecureNumberT, bound= SecureNumber)) – A Dummy variable that needs to be updated with the tasks’s result.

  • task (Task[TypeVar(SecureNumberT, bound= SecureNumber)]) – The task that is running computations.

Raises:

Exception – when an exception is raised inside the task.

Return type:

None