Skip to content

Commit

Permalink
Refactor lookup table creation api (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
chancharles92 committed Apr 4, 2022
1 parent 9590fac commit 1fc9a48
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions plonk/src/circuit/customized/ecc/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ where

// create circuit
let range_size = F::from((1 << c) as u32);
for &var in decomposed_scalar_vars.iter() {
circuit.range_gate(var, c)?;
}
circuit.decompose_vars_gate(decomposed_scalar_vars.clone(), scalar_var, range_size)?;

Ok(decomposed_scalar_vars)
Expand Down
6 changes: 6 additions & 0 deletions plonk/src/circuit/customized/ultraplonk/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ impl<F: PrimeField> PlonkCircuit<F> {
/// and create a list of variable tuples to be looked up:
/// [lookup_vars\[0\], ..., lookup_vars[m - 1]];
///
/// **For each variable tuple `(lookup_var.0, lookup_var.1, lookup_var.2)`
/// to be looked up, the index variable `lookup_var.0` is required to be
/// in range [0, n) (either constrained by a range-check gate or other
/// circuits), so that one can't set it out of bounds and thus do a
/// lookup into one of the *other* tables. **
///
/// w.l.o.g we assume n = m as we can pad with dummy tuples when n != m
pub fn create_table_and_lookup_variables(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
wire_eval,
&non_native_field_info.modulus_fp_elem,
)?;
Expand All @@ -161,7 +161,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
sigma_eval,
&non_native_field_info.modulus_fp_elem,
)?;
Expand All @@ -172,7 +172,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
&poly_evals.perm_next_eval,
&non_native_field_info.modulus_fp_elem,
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ where
let r_0_component = circuit.mod_mul(
alpha_bases_elem_var
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
&r_plonk_j_fp_elem_var,
&non_native_field_info.modulus_fp_elem,
)?;
Expand Down Expand Up @@ -533,7 +533,7 @@ where

let current_alpha_bases = alpha_bases_elem_var
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?;
.ok_or(PlonkError::IteratorOutOfRange)?;

let mut coeff_fp_elem_var = alpha_2_mul_l1;
let w_evals = &batch_proof.poly_evals_vec[i].wires_evals;
Expand Down
10 changes: 5 additions & 5 deletions plonk/src/proof_system/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
wire_eval,
);
}
Expand All @@ -731,7 +731,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
sigma_eval,
);
}
Expand All @@ -740,7 +740,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
poly_evals.perm_next_eval,
);

Expand All @@ -753,7 +753,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
eval,
);
}
Expand All @@ -763,7 +763,7 @@ where
&mut result,
v_and_uv_basis
.next()
.ok_or_else(|| PlonkError::IteratorOutOfRange)?,
.ok_or(PlonkError::IteratorOutOfRange)?,
next_eval,
);
}
Expand Down

0 comments on commit 1fc9a48

Please sign in to comment.