Skip to main content

task

Attribute Macro task 

Source
#[task]
Expand description

Attribute macro to transform a sequential function into a multi-round task state machine.

This macro allows writing multi-round MPC tasks as sequential functions, using open! macro calls to mark round boundaries. The macro transforms the function into:

  • Round state structs for each round
  • A task enum with Round variants + Resolving
  • Constructor from function parameters
  • State transition methods
  • Round logic methods
  • Task trait implementation

§Arguments

The macro takes the task name as its argument: #[task(TaskName)]

§Example

#[task(MulTask)]
fn mul<F: FieldExtension>(
    x: FieldShare<F>,
    y: FieldShare<F>,
    triple: Triple<F>,
) -> FieldShare<F>
where
    FieldShare<F>: Into<Share>,
    Secret: TryInto<SubfieldElement<F>>,
{
    let Triple { a, b, c: _ } = &triple;
    let epsilon = &x - a;
    let delta = &y - b;

    // open_field! marks a round boundary - variables used after become state
    let (delta, epsilon): (SubfieldElement<F>, SubfieldElement<F>) = open_field!(delta, epsilon);

    let Triple { a, b: _, c } = &triple;
    c + &y * epsilon + a * delta
}

§Communication Macros

  • open_field!(share) - Opens a single field share, returning the reconstructed value
  • open_field!(share1, share2) - Opens multiple field shares, returning a tuple
  • open_binary!(share1, share2) - Opens binary (Gf2_128) shares; emits Share::Binary directly with no Into<Share<F>> or Secret<F>: Into<T> bounds

Type annotations on the let binding tell the macro what types to extract from Secret.