From 1fc9a4861e39175a776dc8da109a0bdc1ebb1c5c Mon Sep 17 00:00:00 2001 From: chancharles92 Date: Mon, 4 Apr 2022 10:31:43 -0700 Subject: [PATCH] Refactor lookup table creation api (#47) --- plonk/src/circuit/customized/ecc/msm.rs | 3 +++ .../src/circuit/customized/ultraplonk/lookup_table.rs | 6 ++++++ .../customized/ultraplonk/plonk_verifier/gadgets.rs | 6 +++--- .../customized/ultraplonk/plonk_verifier/poly.rs | 4 ++-- plonk/src/proof_system/verifier.rs | 10 +++++----- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/plonk/src/circuit/customized/ecc/msm.rs b/plonk/src/circuit/customized/ecc/msm.rs index 0238237eb..a2bd425f2 100644 --- a/plonk/src/circuit/customized/ecc/msm.rs +++ b/plonk/src/circuit/customized/ecc/msm.rs @@ -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) diff --git a/plonk/src/circuit/customized/ultraplonk/lookup_table.rs b/plonk/src/circuit/customized/ultraplonk/lookup_table.rs index c516b2805..b723c4f16 100644 --- a/plonk/src/circuit/customized/ultraplonk/lookup_table.rs +++ b/plonk/src/circuit/customized/ultraplonk/lookup_table.rs @@ -20,6 +20,12 @@ impl PlonkCircuit { /// 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, diff --git a/plonk/src/circuit/customized/ultraplonk/plonk_verifier/gadgets.rs b/plonk/src/circuit/customized/ultraplonk/plonk_verifier/gadgets.rs index 0bae1b802..f6242852e 100644 --- a/plonk/src/circuit/customized/ultraplonk/plonk_verifier/gadgets.rs +++ b/plonk/src/circuit/customized/ultraplonk/plonk_verifier/gadgets.rs @@ -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, )?; @@ -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, )?; @@ -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, )?; diff --git a/plonk/src/circuit/customized/ultraplonk/plonk_verifier/poly.rs b/plonk/src/circuit/customized/ultraplonk/plonk_verifier/poly.rs index 589096f9e..a8af4aa00 100644 --- a/plonk/src/circuit/customized/ultraplonk/plonk_verifier/poly.rs +++ b/plonk/src/circuit/customized/ultraplonk/plonk_verifier/poly.rs @@ -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, )?; @@ -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; diff --git a/plonk/src/proof_system/verifier.rs b/plonk/src/proof_system/verifier.rs index 08556fdb2..aaf18eaa2 100644 --- a/plonk/src/proof_system/verifier.rs +++ b/plonk/src/proof_system/verifier.rs @@ -722,7 +722,7 @@ where &mut result, v_and_uv_basis .next() - .ok_or_else(|| PlonkError::IteratorOutOfRange)?, + .ok_or(PlonkError::IteratorOutOfRange)?, wire_eval, ); } @@ -731,7 +731,7 @@ where &mut result, v_and_uv_basis .next() - .ok_or_else(|| PlonkError::IteratorOutOfRange)?, + .ok_or(PlonkError::IteratorOutOfRange)?, sigma_eval, ); } @@ -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, ); @@ -753,7 +753,7 @@ where &mut result, v_and_uv_basis .next() - .ok_or_else(|| PlonkError::IteratorOutOfRange)?, + .ok_or(PlonkError::IteratorOutOfRange)?, eval, ); } @@ -763,7 +763,7 @@ where &mut result, v_and_uv_basis .next() - .ok_or_else(|| PlonkError::IteratorOutOfRange)?, + .ok_or(PlonkError::IteratorOutOfRange)?, next_eval, ); }