TurboComposer

Struct TurboComposer 

Source
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, being this one 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 repesented as Wires (so basically the Permutation argument etc..).

The TurboComposer also grants us a way to introduce our secret witnesses in a for of a Witness 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 neccessary tools to be able to istrument 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 an specific functionallity or operation to de circuit description, and so, that’s why we can understand the TurboComposer as a builder.

Implementations§

Source§

impl TurboComposer

Source

pub const fn constant_zero() -> Witness

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.

Source

pub const fn gates(&self) -> u32

Return the number of gates in the circuit

Source

pub unsafe fn evaluate_witness(&self, witness: &Witness) -> &BlsScalar

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.

Source

pub fn public_input_indexes(&self) -> Vec<u32>

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

Source§

impl TurboComposer

Source

pub fn append_constant(&mut self, value: BlsScalar) -> Witness

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

Source

pub fn append_witness<T: Into<BlsScalar>>(&mut self, scalar: T) -> Witness

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

Source

pub fn append_gate(&mut self, s: Constraint)

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.

Source

pub fn assert_equal_constant( &mut self, a: Witness, constant: BlsScalar, pi: Option<BlsScalar>, )

Constrain a to be equal to constant + pi.

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

Source

pub fn assert_equal(&mut self, a: Witness, b: Witness)

Asserts a == b by appending a gate

Source

pub fn component_select( &mut self, bit: Witness, a: Witness, b: Witness, ) -> Witness

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

Source

pub fn component_select_zero(&mut self, bit: Witness, value: Witness) -> Witness

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

Source

pub fn component_select_one(&mut self, bit: Witness, value: Witness) -> Witness

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

Source

pub fn component_decomposition<const N: usize>( &mut self, scalar: Witness, ) -> [Witness; N]

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

Source

pub fn append_dummy_gates(&mut self)

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.

Source

pub fn append_plonkup_gate( &mut self, a: Witness, b: Witness, c: Witness, d: Witness, pi: Option<BlsScalar>, ) -> Witness

Adds a plonkup gate to the circuit with its corresponding gates.

This type of gate is usually used when we need to have the largest amount of performance and the minimum circuit-size possible. Since it allows the end-user to set every selector coefficient as scaling value on the gate eq.

Source

pub fn append_plonkup_table(&mut self, table: &LookupTable)

When TurboComposer is initialised, it spawns a dummy table with 3 entries that should not be removed. This function appends its input table to the composer’s dummy table

Source§

impl TurboComposer

Source

pub fn component_add_point( &mut self, a: WitnessPoint, b: WitnessPoint, ) -> WitnessPoint

Adds two curve points by consuming 2 gates.

Source§

impl TurboComposer

Source

pub fn component_mul_generator<P: Into<JubJubExtended>>( &mut self, jubjub: Witness, generator: P, ) -> WitnessPoint

Evaluate jubjub · Generator as a WitnessPoint

generator will be appended to the circuit description as constant

Source§

impl TurboComposer

Source

pub fn component_mul_point( &mut self, jubjub: Witness, point: WitnessPoint, ) -> WitnessPoint

Evaluate jubjub · point as a WitnessPoint

Source§

impl TurboComposer

Source

pub fn append_point<P: Into<JubJubAffine>>(&mut self, affine: P) -> WitnessPoint

Appends a point in affine form as WitnessPoint

Source

pub fn append_public_point<P: Into<JubJubAffine>>( &mut self, affine: P, ) -> WitnessPoint

Appends a point in affine form as WitnessPoint

Creates two public inputs as (x, y)

Source

pub fn append_constant_point<P: Into<JubJubAffine>>( &mut self, affine: P, ) -> WitnessPoint

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

Source

pub fn append_constant_identity(&mut self) -> WitnessPoint

Create an identity WitnessPoint constrained by the circuit description

Source

pub fn assert_equal_public_point<P: Into<JubJubAffine>>( &mut self, point: WitnessPoint, public: P, )

Asserts point == public.

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

Source

pub fn assert_equal_point(&mut self, a: WitnessPoint, b: WitnessPoint)

Asserts a == b by appending two gates

Source

pub fn component_select_point( &mut self, a: WitnessPoint, b: WitnessPoint, bit: Witness, ) -> WitnessPoint

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

Source

pub fn component_select_identity( &mut self, bit: Witness, a: WitnessPoint, ) -> WitnessPoint

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

Source§

impl TurboComposer

Source

pub fn component_xor( &mut self, a: Witness, b: Witness, num_bits: usize, ) -> Witness

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.

Source

pub fn component_and( &mut self, a: Witness, b: Witness, num_bits: usize, ) -> Witness

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.

Source§

impl TurboComposer

Source

pub fn component_range(&mut self, witness: Witness, num_bits: usize)

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.

Source§

impl TurboComposer

Source

pub fn gate_add(&mut self, s: Constraint) -> Witness

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

The output of the constraint will be overwritten with o := q_l · a + q_r · b + q_4 · d + q_c + PI

Source

pub fn gate_mul(&mut self, s: Constraint) -> Witness

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

The output of the constraint will be overwritten with o := q_m · a · b + q_4 · d + q_c + PI

Source§

impl TurboComposer

Source

pub fn component_boolean(&mut self, a: Witness)

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§

Source§

impl Debug for TurboComposer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TurboComposer

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.