logo
pub struct TurboComposer { /* private fields */ }
Expand description

The TurboComposer is the circuit-builder tool that the dusk-plonk repository provides so that circuit descriptions can be written, stored and transformed into a Proof at some point.

A TurboComposer stores all of the circuit information, this one being all of the witness and circuit descriptors info (values, positions in the circuits, gates and Wires that occupy..), the public inputs, the connection relationships between the witnesses and how they’re represented as Wires (so basically the Permutation argument etc..).

The TurboComposer also grants us a way to introduce our secret witnesses in into the circuit description as well as the public inputs. We can do this with methods like TurboComposer::append_witness.

The TurboComposer also contains as associated functions all the necessary tools to be able to instrument the circuits that the user needs through the addition of gates. There are functions that may add a single gate to the circuit as for example TurboComposer::gate_add and others that can add several gates to the circuit description such as TurboComposer::component_select.

Each gate or group of gates adds a specific functionality or operation to the circuit description, and so, that’s why we can understand the TurboComposer as a builder.

Implementations

Returns a Witness representation of zero.

Every TurboComposer is initialized with a circuit description containing a representation of zero. This function will return the index of that representation.

Return the number of gates in the circuit

Evaluate the runtime value of a witness

Safety

Witness evaluation inside a gadget isn’t expected and could produce an unsound circuit (different circuit representation for the same code).

Calling this function performs operations outside the circuit.

Returns the positions that the Public Inputs occupy in this Composer instance.

Constrain a scalar into the circuit description and return an allocated Witness with its value

Allocate a witness value into the composer and return its index.

Allocate a witness value into the composer and return its index.

Create a public input with the scalar

Adds a width-4 poly gate.

The final constraint added will enforce the following: q_m · a · b + q_l · a + q_r · b + q_o · o + q_4 · d + q_c + PI = 0.

Constrain a to be equal to constant + pi.

constant will be defined as part of the public circuit description.

Asserts a == b by appending a gate

Conditionally selects a Witness based on an input bit.

bit == 1 => a, bit == 0 => b,

bit is expected to be constrained by TurboComposer::component_boolean

Conditionally selects a Witness based on an input bit.

bit == 1 => value, bit == 0 => 0,

bit is expected to be constrained by TurboComposer::component_boolean

Conditionally selects a Witness based on an input bit.

bit == 1 => value, bit == 0 => 1,

bit is expected to be constrained by TurboComposer::component_boolean

Decomposes scalar into an array truncated to N bits (max 256).

Asserts the reconstruction of the bits to be equal to scalar.

Consume 2 · N + 1 gates

This function is used to add a blinding factor to the witness polynomials. It essentially adds two dummy gates to the circuit description which are guaranteed to always satisfy the gate equation.

Adds two curve points by consuming 2 gates.

Evaluate jubjub · Generator as a WitnessPoint

generator will be appended to the circuit description as constant

Evaluate jubjub · point as a WitnessPoint

Appends a point in affine form as WitnessPoint

Appends a point in affine form as WitnessPoint

Creates two public inputs as (x, y)

Constrain a point into the circuit description and return an allocated WitnessPoint with its coordinates

Create an identity WitnessPoint constrained by the circuit description

Asserts point == public.

Will add public affine coordinates (x,y) as public inputs

Asserts a == b by appending two gates

Conditionally selects a WitnessPoint based on an input bit.

bit == 1 => a, bit == 0 => b,

bit is expected to be constrained by TurboComposer::component_boolean

Conditionally selects identity as WitnessPoint based on an input bit.

bit == 1 => a, bit == 0 => identity,

bit is expected to be constrained by TurboComposer::component_boolean

Adds a logical XOR gate that performs the XOR between two values for the specified first num_bits returning a Witness holding the result.

Panics

If the num_bits specified in the fn params is odd.

Adds a logical AND gate that performs the bitwise AND between two values for the specified first num_bits returning a Witness holding the result.

Panics

If the num_bits specified in the fn params is odd.

Adds a range-constraint gate that checks and constrains a Witness to be inside of the range [0,num_bits].

This function adds num_bits/4 gates to the circuit description in order to add the range constraint.

Panics

This function will panic if the num_bits specified is not even, ie. num_bits % 2 != 0.

Evaluate and return o by appending a new constraint into the circuit.

Set q_o = (-1) and override the output of the constraint with: o := q_l · a + q_r · b + q_4 · d + q_c + PI

Evaluate and return o by appending a new constraint into the circuit.

Set q_o = (-1) and override the output of the constraint with: o := q_m · a · b + q_4 · d + q_c + PI

Adds a boolean constraint (also known as binary constraint) where the gate eq. will enforce that the Witness received is either 0 or 1 by adding a constraint in the circuit.

Note that using this constraint with whatever Witness that is not representing a value equalling 0 or 1, will always force the equation to fail.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.