pub trait GateInstructions<F: ScalarField> {
Show 36 methods
// Required methods
fn pow_of_two(&self) -> &[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_left<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>,
) -> (AssignedValue<F>, Vec<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 pow_var(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>,
exp: AssignedValue<F>,
max_bits: usize,
) -> AssignedValue<F>;
// Provided methods
fn add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
) -> AssignedValue<F> { ... }
fn inc(
&self,
ctx: &mut Context<F>,
a: 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 dec(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
) -> AssignedValue<F> { ... }
fn sub_mul(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: 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 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 select_array_by_indicator<AR, AV>(
&self,
ctx: &mut Context<F>,
array2d: &[AR],
indicator: &[AssignedValue<F>],
) -> Vec<AssignedValue<F>>
where AR: AsRef<[AV]>,
AV: AsRef<AssignedValue<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§
Sourcefn pow_of_two(&self) -> &[F]
fn pow_of_two(&self) -> &[F]
Returns a slice of the ScalarField field elements 2^i for i in 0..F::NUM_BITS.
Sourcefn 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<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>,
) -> AssignedValue<F>where
QA: Into<QuantumCell<F>>,
Constrains and returns the inner product of <a, b>.
Assumes ‘a’ and ‘b’ are the same length.
ctx: Context to add the constraints toa: Iterator of QuantumCell valuesb: Iterator of QuantumCell values to take inner product ofaby
Sourcefn 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_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>>,
Returns the inner product of <a, b> and the last element of a after it has been assigned.
NOT encouraged for general usage.
This is a low-level function, where you want to avoid first assigning a and then copying the last element into the
correct cell for this computation.
Assumes ‘a’ and ‘b’ are the same length.
ctx: Context of the circuita: Iterator of QuantumCellsb: Iterator of QuantumCells to take inner product ofaby
Sourcefn inner_product_left<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>,
) -> (AssignedValue<F>, Vec<AssignedValue<F>>)where
QA: Into<QuantumCell<F>>,
fn inner_product_left<QA>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QuantumCell<F>>,
) -> (AssignedValue<F>, Vec<AssignedValue<F>>)where
QA: Into<QuantumCell<F>>,
Returns (<a,b>, a_assigned). See inner_product for more details.
NOT encouraged for general usage.
This is a low-level function, useful for when you want to simultaneously compute an inner product while assigning
private witnesses for the first time. This avoids first assigning a and then copying into the correct cells
for this computation. We do not return the assignments of a in inner_product as an optimization to avoid
the memory allocation of having to collect the vectors.
Assumes ‘a’ and ‘b’ are the same length.
Sourcefn 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 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>>,
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 toa: Iterator of QuantumCell valuesb: Iterator of QuantumCell values to calculate the partial sums of the inner product ofaby.
Sourcefn 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 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>
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)wherecoeffis a field element,aandbare QuantumCell’s.var: QuantumCell that represents the value of a variable added to the sum.
Sourcefn select(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
sel: impl Into<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>
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.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.sel: QuantumCell that contains a boolean value.
Sourcefn 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 or_and( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, c: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
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.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.c: QuantumCell that contains a boolean value.
Sourcefn num_to_bits(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>,
range_bits: usize,
) -> Vec<AssignedValue<F>>
fn num_to_bits( &self, ctx: &mut Context<F>, a: AssignedValue<F>, range_bits: usize, ) -> Vec<AssignedValue<F>>
Constrains and returns little-endian bit vector representation of a.
Assumes range_bits >= bit_length(a).
a: QuantumCell of the value to convertrange_bits: range of bits needed to representa
Sourcefn pow_var(
&self,
ctx: &mut Context<F>,
a: AssignedValue<F>,
exp: AssignedValue<F>,
max_bits: usize,
) -> AssignedValue<F>
fn pow_var( &self, ctx: &mut Context<F>, a: AssignedValue<F>, exp: AssignedValue<F>, max_bits: usize, ) -> AssignedValue<F>
Constrains and computes aexp where both a, exp are witnesses. The exponent is computed in the native field F.
Constrains that exp has at most max_bits bits.
Provided Methods§
Sourcefn add(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn add( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns a + b * 1 = out.
Defines a vertical gate of form | a | b | 1 | a + b | where (a + b) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to add to ’a`
Sourcefn inc(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn inc( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns out = a + 1.
ctx: Context to add the constraints toa: QuantumCell value
Sourcefn sub(
&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>
Constrains and returns a + b * (-1) = out.
Defines a vertical gate of form | a - b | b | 1 | a |, where (a - b) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to subtract from ‘a’
Sourcefn dec(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn dec( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns out = a - 1.
ctx: Context to add the constraints toa: QuantumCell value
Sourcefn sub_mul(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
c: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn sub_mul( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, c: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns a - b * c = out.
Defines a vertical gate of form | a - b * c | b | c | a |, where (a - b * c) = out.
ctx: Context to add the constraints toa: QuantumCell value to subtract ‘b * c’ fromb: QuantumCell valuec: QuantumCell value
Sourcefn neg(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn neg( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns a * (-1) = out.
Defines a vertical gate of form | a | -a | 1 | 0 |, where (-a) = out.
ctx: the Context to add the constraints toa: QuantumCell value to negate
Sourcefn mul(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: 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>
Constrains and returns 0 + a * b = out.
Defines a vertical gate of form | 0 | a | b | a * b |, where (a * b) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to multiply ‘a’ by
Sourcefn 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_add( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, c: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns a * b + c = out.
Defines a vertical gate of form | c | a | b | a * b + c |, where (a * b + c) = out.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to multiply ‘a’ byc: QuantumCell value to add to ‘a * b’
Sourcefn mul_not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: 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>
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.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to multiply ‘a’ by
Sourcefn assert_bit(&self, ctx: &mut Context<F>, x: AssignedValue<F>)
fn assert_bit(&self, ctx: &mut Context<F>, x: AssignedValue<F>)
Constrains that x is boolean (e.g. 0 or 1).
Defines a vertical gate of form | 0 | x | x | x |.
ctx: Context to add the constraints tox: QuantumCell value to constrain
Sourcefn div_unsafe(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn div_unsafe( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns a / b = out.
Defines a vertical gate of form | 0 | a / b | b | a |, where a / b = out.
Assumes b != 0.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to divide ‘a’ by
Sourcefn assert_is_const(
&self,
ctx: &mut Context<F>,
a: &AssignedValue<F>,
constant: &F,
)
fn assert_is_const( &self, ctx: &mut Context<F>, a: &AssignedValue<F>, constant: &F, )
Constrains that a is equal to constant value.
ctx: Context to add the constraints toa: QuantumCell valueconstant: constant value to constrainato be equal to
Sourcefn sum<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>,
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
fn sum<Q>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = Q>,
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
Constrains and returns the sum of QuantumCell’s in iterator a.
ctx: Context to add the constraints toa: Iterator of QuantumCell values to sum
Sourcefn 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 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>>,
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].
ctx: Context to add the constraints toa: Iterator of QuantumCell values to sum
Sourcefn accumulated_product<QA, QB>(
&self,
ctx: &mut Context<F>,
a: impl IntoIterator<Item = QA>,
b: impl IntoIterator<Item = QB>,
) -> Vec<AssignedValue<F>>
fn accumulated_product<QA, QB>( &self, ctx: &mut Context<F>, a: impl IntoIterator<Item = QA>, b: impl IntoIterator<Item = QB>, ) -> Vec<AssignedValue<F>>
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 toa: Iterator of QuantumCell valuesb: Iterator of QuantumCell values to take the accumulated product ofaby
Sourcefn or(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn or( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
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.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.
Sourcefn and(
&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>
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.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.b: QuantumCell that contains a boolean value.
Sourcefn not(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn not( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains and returns !a assumeing a is boolean.
Defines a vertical gate of form | 1 - a | a | 1 | 1 |, where 1 - a = out.
ctx: Context to add the constraints to.a: QuantumCell that contains a boolean value.
Sourcefn bits_to_indicator(
&self,
ctx: &mut Context<F>,
bits: &[AssignedValue<F>],
) -> Vec<AssignedValue<F>>
fn bits_to_indicator( &self, ctx: &mut Context<F>, bits: &[AssignedValue<F>], ) -> Vec<AssignedValue<F>>
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 tobits: slice of QuantumCell’s that contains boolean values
§Assumptions
bitsis non-empty
Sourcefn idx_to_indicator(
&self,
ctx: &mut Context<F>,
idx: impl Into<QuantumCell<F>>,
len: usize,
) -> Vec<AssignedValue<F>>
fn idx_to_indicator( &self, ctx: &mut Context<F>, idx: impl Into<QuantumCell<F>>, len: usize, ) -> Vec<AssignedValue<F>>
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 toidx: QuantumCell index of the indicator vector to be set to 1len: length of theindicatorvector
Sourcefn 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_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>>,
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 toa: Iterator of QuantumCell’s that contains field elementsindicator: Iterator of AssignedValue’s whereindicator[i] == 1ifi == idx, otherwise0
Sourcefn 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 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>>,
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 tocells: Iterator of QuantumCells to select fromidx: QuantumCell with valueidxwhereidxis the index of the cell to be selected
Sourcefn select_array_by_indicator<AR, AV>(
&self,
ctx: &mut Context<F>,
array2d: &[AR],
indicator: &[AssignedValue<F>],
) -> Vec<AssignedValue<F>>
fn select_array_by_indicator<AR, AV>( &self, ctx: &mut Context<F>, array2d: &[AR], indicator: &[AssignedValue<F>], ) -> Vec<AssignedValue<F>>
array2d is an array of fixed length arrays.
Assumes:
array2d.len() == indicator.len()array2d[i].len() == array2d[j].len()for alli,j.- the values of
indicatorare boolean and thatindicatorhas at most one1bit. - the lengths of
array2dandindicatorare the same.
Returns the “dot product” of array2d with indicator as a fixed length (1d) array of length array2d[0].len().
Sourcefn is_zero(&self, ctx: &mut Context<F>, a: AssignedValue<F>) -> AssignedValue<F>
fn is_zero(&self, ctx: &mut Context<F>, a: AssignedValue<F>) -> AssignedValue<F>
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.
ctx: Context to add the constraints toa: QuantumCell value to be constrained
Sourcefn is_equal(
&self,
ctx: &mut Context<F>,
a: impl Into<QuantumCell<F>>,
b: impl Into<QuantumCell<F>>,
) -> AssignedValue<F>
fn is_equal( &self, ctx: &mut Context<F>, a: impl Into<QuantumCell<F>>, b: impl Into<QuantumCell<F>>, ) -> AssignedValue<F>
Constrains that the value of two cells are equal: b - a = 0, returns 1 if a = b, otherwise 0.
ctx: Context to add the constraints toa: QuantumCell valueb: QuantumCell value to compare toa
Sourcefn lagrange_and_eval(
&self,
ctx: &mut Context<F>,
coords: &[(AssignedValue<F>, AssignedValue<F>)],
x: AssignedValue<F>,
) -> (AssignedValue<F>, AssignedValue<F>)
fn lagrange_and_eval( &self, ctx: &mut Context<F>, coords: &[(AssignedValue<F>, AssignedValue<F>)], x: AssignedValue<F>, ) -> (AssignedValue<F>, AssignedValue<F>)
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 tocoords: immutable reference to a slice of tuples of AssignedValues representing the points to interpolate over such thatcoords[i] = (x_i, y_i)x: x-coordinate of the point to evaluatefat
§Assumptions
coordsis non-empty
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.