pub trait GateInstructions<F: ScalarField> {
Show 35 methods fn strategy(&self) -> GateStrategy; fn pow_of_two(&self) -> &[F]Notable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]; fn get_field_element(&self, n: u64) -> F; fn inner_product<QA>(
        &self,
        ctx: &mut Context<F>,
        a: impl IntoIterator<Item = QA>,
        b: impl IntoIterator<Item = QuantumCell<F>>
    ) -> AssignedValue<F>
    where
        QA: Into<QuantumCell<F>>
; fn inner_product_left_last<QA>(
        &self,
        ctx: &mut Context<F>,
        a: impl IntoIterator<Item = QA>,
        b: impl IntoIterator<Item = QuantumCell<F>>
    ) -> (AssignedValue<F>, AssignedValue<F>)
    where
        QA: Into<QuantumCell<F>>
; fn inner_product_with_sums<'thread, QA>(
        &self,
        ctx: &'thread mut Context<F>,
        a: impl IntoIterator<Item = QA>,
        b: impl IntoIterator<Item = QuantumCell<F>>
    ) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>
    where
        QA: Into<QuantumCell<F>>
; fn sum_products_with_coeff_and_var(
        &self,
        ctx: &mut Context<F>,
        values: impl IntoIterator<Item = (F, QuantumCell<F>, QuantumCell<F>)>,
        var: QuantumCell<F>
    ) -> AssignedValue<F>; fn select(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>,
        sel: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F>; fn or_and(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>,
        c: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F>; fn num_to_bits(
        &self,
        ctx: &mut Context<F>,
        a: AssignedValue<F>,
        range_bits: usize
    ) -> Vec<AssignedValue<F>>; fn const_right_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
        &self,
        ctx: &mut Context<F>,
        a: AssignedValue<F>
    ) -> AssignedValue<F>; fn const_left_rotate_unsafe<const BIT: usize, const NUM_BITS: usize>(
        &self,
        ctx: &mut Context<F>,
        a: AssignedValue<F>
    ) -> AssignedValue<F>; fn add(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn sub(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn neg(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn mul(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn mul_add(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>,
        c: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn mul_not(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn assert_bit(&self, ctx: &mut Context<F>, x: AssignedValue<F>) { ... } fn div_unsafe(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn assert_is_const(
        &self,
        ctx: &mut Context<F>,
        a: &AssignedValue<F>,
        constant: &F
    ) { ... } fn sum<Q>(
        &self,
        ctx: &mut Context<F>,
        a: impl IntoIterator<Item = Q>
    ) -> AssignedValue<F>
    where
        Q: Into<QuantumCell<F>>
, { ... } fn partial_sums<'thread, Q>(
        &self,
        ctx: &'thread mut Context<F>,
        a: impl IntoIterator<Item = Q>
    ) -> Box<dyn Iterator<Item = AssignedValue<F>> + 'thread>
    where
        Q: Into<QuantumCell<F>>
, { ... } fn accumulated_product<QA, QB>(
        &self,
        ctx: &mut Context<F>,
        a: impl IntoIterator<Item = QA>,
        b: impl IntoIterator<Item = QB>
    ) -> Vec<AssignedValue<F>>
    where
        QA: Into<QuantumCell<F>>,
        QB: Into<QuantumCell<F>>
, { ... } fn or(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn and(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn xor(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn not(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn bits_to_indicator(
        &self,
        ctx: &mut Context<F>,
        bits: &[AssignedValue<F>]
    ) -> Vec<AssignedValue<F>> { ... } fn idx_to_indicator(
        &self,
        ctx: &mut Context<F>,
        idx: impl Into<QuantumCell<F>>,
        len: usize
    ) -> Vec<AssignedValue<F>> { ... } fn select_by_indicator<Q>(
        &self,
        ctx: &mut Context<F>,
        a: impl IntoIterator<Item = Q>,
        indicator: impl IntoIterator<Item = AssignedValue<F>>
    ) -> AssignedValue<F>
    where
        Q: Into<QuantumCell<F>>
, { ... } fn select_from_idx<Q>(
        &self,
        ctx: &mut Context<F>,
        cells: impl IntoIterator<Item = Q>,
        idx: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F>
    where
        Q: Into<QuantumCell<F>>
, { ... } fn is_zero(
        &self,
        ctx: &mut Context<F>,
        a: AssignedValue<F>
    ) -> AssignedValue<F> { ... } fn is_equal(
        &self,
        ctx: &mut Context<F>,
        a: impl Into<QuantumCell<F>>,
        b: impl Into<QuantumCell<F>>
    ) -> AssignedValue<F> { ... } fn lagrange_and_eval(
        &self,
        ctx: &mut Context<F>,
        coords: &[(AssignedValue<F>, AssignedValue<F>)],
        x: AssignedValue<F>
    ) -> (AssignedValue<F>, AssignedValue<F>) { ... }
}
Expand description

Trait that defines basic arithmetic operations for a gate.

Required Methods

Returns the GateStrategy for the gate.

Returns a slice of the ScalarField field elements 2^i for i in 0..F::NUM_BITS.

Converts a u64 into a scalar field element ScalarField.

Constrains and returns the inner product of <a, b>.

Assumes ‘a’ and ‘b’ are the same length.

Returns the inner product of <a, b> and the last element of a now assigned, i.e. (inner_product_<a, b>, last_element_a).

Assumes ‘a’ and ‘b’ are the same length.

Calculates and constrains the inner product.

Returns the assignment trace where output[i] has the running sum sum_{j=0..=i} a[j] * b[j].

Assumes ‘a’ and ‘b’ are the same length.

  • ctx: Context to add the constraints to
  • a: Iterator of QuantumCell values
  • b: Iterator of QuantumCell values to calculate the partial sums of the inner product of a by.

Constrains and returns the sum of products of coeff * (a * b) defined in values plus a variable var e.g. x = var + values[0].0 * (values[0].1 * values[0].2) + values[1].0 * (values[1].1 * values[1].2) + ... + values[n].0 * (values[n].1 * values[n].2).

  • ctx: Context to add the constraints to.
  • values: Iterator of tuples (coeff, a, b) where coeff is a field element, a and b are QuantumCell’s.
  • var: QuantumCell that represents the value of a variable added to the sum.

Constrains and returns sel ? a : b assuming sel is boolean.

Defines a vertical gate of form | 1 - sel | sel | 1 | a | 1 - sel | sel | 1 | b | out |, where out = sel * a + (1 - sel) * b.

Constains and returns a || (b && c), assuming a, b and c are boolean.

Defines a vertical gate of form | 1 - b c | b | c | 1 | a - 1 | 1 - b c | out | a - 1 | 1 | 1 | a |, where out = a + b * c - a * b * c.

Constrains and returns little-endian bit vector representation of a.

Assumes range_bits <= number of bits in a.

  • a: QuantumCell of the value to convert
  • range_bits: range of bits needed to represent a

Bitwise right rotate a by BIT bits. BIT and NUM_BITS must be determined at compile time.

Assumes ‘a’ is a NUM_BITS bit integer and NUM_BITS <= 128.

Bitwise left rotate a by BIT bits. BIT and NUM_BITS must be determined at compile time.

Assumes ‘a’ is a NUM_BITS bit integer and NUM_BITS <= 128.

Provided Methods

Constrains and returns a + b * 1 = out.

Defines a vertical gate of form | a | b | 1 | a + b | where (a + b) = out.

Constrains and returns a + b * (-1) = out.

Defines a vertical gate of form | a - b | b | 1 | a |, where (a - b) = out.

Constrains and returns a * (-1) = out.

Defines a vertical gate of form | a | -a | 1 | 0 |, where (-a) = out.

Constrains and returns 0 + a * b = out.

Defines a vertical gate of form | 0 | a | b | a * b |, where (a * b) = out.

Constrains and returns a * b + c = out.

Defines a vertical gate of form | c | a | b | a * b + c |, where (a * b + c) = out.

Constrains and returns (1 - a) * b = b - a * b.

Defines a vertical gate of form | (1 - a) * b | a | b | b |, where (1 - a) * b = out.

Constrains that x is boolean (e.g. 0 or 1).

Defines a vertical gate of form | 0 | x | x | x |.

Constrains and returns a / b = 0.

Defines a vertical gate of form | 0 | b^1 * a | b | a |, where b^1 * a = out.

Assumes b != 0.

Constrains that a is equal to constant value.

  • ctx: Context to add the constraints to
  • a: QuantumCell value
  • constant: constant value to constrain a to be equal to

Constrains and returns the sum of QuantumCell’s in iterator a.

Calculates and constrains the sum of the elements of a.

Returns the assignment trace where output[i] has the running sum sum_{j=0..=i} a[j].

Calculates and constrains the accumulated product of ‘a’ and ‘b’ i.e. x_i = b_1 * (a_1...a_{i - 1}) + b_2 * (a_2...a_{i - 1}) + ... + b_i

Returns the assignment trace where output[i] is the running accumulated product x_i.

Assumes ‘a’ and ‘b’ are the same length.

  • ctx: Context to add the constraints to
  • a: Iterator of QuantumCell values
  • b: Iterator of QuantumCell values to take the accumulated product of a by

Constrains and returns a || b, assuming a and b are boolean.

Defines a vertical gate of form | 1 - b | 1 | b | 1 | b | a | 1 - b | out |, where out = a + b - a * b.

Constrains and returns a & b, assumeing a and b are boolean.

Defines a vertical gate of form | 0 | a | b | out |, where out = a * b.

Constrains and returns a ^ b, assuming a and b are boolean.

Defines a vertical gate of form | 1 - 2 * b | 2 | b | 1 | b | a | 1 - 2 * b | out |, where out = a + b - 2 * a * b.

Constrains and returns !a assumeing a is boolean.

Defines a vertical gate of form | 1 - a | a | 1 | 1 |, where 1 - a = out.

Constrains and returns an indicator vector from a slice of boolean values, where output[idx] = 1 iff idx = (the number represented by bits in binary little endian), otherwise output[idx] = 0.

  • ctx: Context to add the constraints to
  • bits: slice of QuantumCell’s that contains boolean values
Assumptions
  • bits is non-empty

Constrains and returns a Vec indicator of length len, where indicator[i] == 1 if i == idx otherwise 0, if idx >= len then indicator is all zeros.

Assumes len is greater than 0.

  • ctx: Context to add the constraints to
  • idx: QuantumCell index of the indicator vector to be set to 1
  • len: length of the indicator vector

Constrains the inner product of a and indicator and returns a[idx] (e.g. the value of a at idx).

Assumes that a and indicator are non-empty iterators of the same length, the values of indicator are boolean, and that indicator has at most one 1 bit.

  • ctx: Context to add the constraints to
  • a: Iterator of QuantumCell’s that contains field elements
  • indicator: Iterator of AssignedValue’s where indicator[i] == 1 if i == idx, otherwise 0

Constrains and returns cells[idx] if idx < cells.len(), otherwise return 0.

Assumes that cells and idx are non-empty iterators of the same length.

  • ctx: Context to add the constraints to
  • cells: Iterator of QuantumCells to select from
  • idx: QuantumCell with value idx where idx is the index of the cell to be selected

Constrains that a cell is equal to 0 and returns 1 if a = 0, otherwise 0.

Defines a vertical gate of form | out | a | inv | 1 | 0 | a | out | 0 |, where out = 1 if a = 0, otherwise out = 0.

Constrains that the value of two cells are equal: b - a = 0, returns 1 if a = b, otherwise 0.

Performs and constrains Lagrange interpolation on coords and evaluates the resulting polynomial at x.

Given pairs coords[i] = (x_i, y_i), let f be the unique degree len(coords) - 1 polynomial such that f(x_i) = y_i for all i.

Returns: (f(x), Prod_i(x - x_i))

  • ctx: Context to add the constraints to
  • coords: immutable reference to a slice of tuples of AssignedValues representing the points to interpolate over such that coords[i] = (x_i, y_i)
  • x: x-coordinate of the point to evaluate f at
Assumptions
  • coords is non-empty

Implementors