pub struct GateChip<F: ScalarField> {
    pub pow_of_two: Vec<F>,
    pub field_element_cache: Vec<F>,
    /* private fields */
}
Expand description

A chip that implements the GateInstructions trait supporting basic arithmetic operations.

Fields

pow_of_two: Vec<F>

The field elements 2^i for i in 0..F::NUM_BITS.

field_element_cache: Vec<F>

To avoid Montgomery conversion in F::from for common small numbers, we keep a cache of field elements.

Implementations

Returns a new GateChip with the given GateStrategy.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Returns the GateStrategy the GateChip.

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

Returns the the value of n as a ScalarField element.

  • n: the u64 value to convert

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 returns a tuple of the last item of a after it is assigned and the item to its left (left_a, last_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. Assumes range_bits > 0.
Bitwise right rotate a by BIT bits. BIT and NUM_BITS must be determined at compile time. Read more
Bitwise left rotate a by BIT bits. BIT and NUM_BITS must be determined at compile time. Read more
Constrains and returns a + b * 1 = out. Read more
Constrains and returns a + b * (-1) = out. Read more
Constrains and returns a * (-1) = out. Read more
Constrains and returns 0 + a * b = out. Read more
Constrains and returns a * b + c = out. Read more
Constrains and returns (1 - a) * b = b - a * b. Read more
Constrains that x is boolean (e.g. 0 or 1). Read more
Constrains and returns a / b = 0. Read more
Constrains that a is equal to constant value. Read more
Constrains and returns the sum of QuantumCell’s in iterator a. Read more
Calculates and constrains the sum of the elements of a. Read more
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 Read more
Constrains and returns a || b, assuming a and b are boolean. Read more
Constrains and returns a & b, assumeing a and b are boolean. Read more
Constrains and returns a ^ b, assuming a and b are boolean. Read more
Constrains and returns !a assumeing a is boolean. Read more
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. Read more
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. Read more
Constrains the inner product of a and indicator and returns a[idx] (e.g. the value of a at idx). Read more
Constrains and returns cells[idx] if idx < cells.len(), otherwise return 0. Read more
Constrains that a cell is equal to 0 and returns 1 if a = 0, otherwise 0. Read more
Constrains that the value of two cells are equal: b - a = 0, returns 1 if a = b, otherwise 0. Read more
Performs and constrains Lagrange interpolation on coords and evaluates the resulting polynomial at x. 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
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted. Read more
Causes self to use its LowerExp implementation when Debug-formatted. Read more
Causes self to use its LowerHex implementation when Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted. Read more
Causes self to use its UpperExp implementation when Debug-formatted. Read more
Causes self to use its UpperHex implementation when Debug-formatted. Read more
Formats each item in a sequence. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
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
Should always be Self
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Attempts to convert self into T using TryInto<T>. 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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more