Skip to content

Commit

Permalink
feat: add docs and assert with non-empty array checks (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed May 23, 2023
1 parent fb7352a commit 096e370
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions halo2-base/src/gates/flex_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,16 @@ pub trait GateInstructions<F: ScalarField> {
/// 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
fn bits_to_indicator(
&self,
ctx: &mut Context<F>,
bits: &[AssignedValue<F>],
) -> Vec<AssignedValue<F>> {
let k = bits.len();
assert!(k > 0, "bits_to_indicator: bits must be non-empty");

// (inv_last_bit, last_bit) = (1, 0) if bits[k - 1] = 0
let (inv_last_bit, last_bit) = {
Expand Down Expand Up @@ -766,12 +770,16 @@ pub trait GateInstructions<F: ScalarField> {
/// * `ctx`: [Context] to add the constraints to
/// * `coords`: immutable reference to a slice of tuples of [AssignedValue]s 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
fn lagrange_and_eval(
&self,
ctx: &mut Context<F>,
coords: &[(AssignedValue<F>, AssignedValue<F>)],
x: AssignedValue<F>,
) -> (AssignedValue<F>, AssignedValue<F>) {
assert!(!coords.is_empty(), "coords should not be empty");
let mut z = self.sub(ctx, Existing(x), Existing(coords[0].0));
for coord in coords.iter().skip(1) {
let sub = self.sub(ctx, Existing(x), Existing(coord.0));
Expand Down

0 comments on commit 096e370

Please sign in to comment.