From f9a57edcb7f6465e3614db4fd279850a81f43373 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Mon, 19 Feb 2024 09:54:13 +0100 Subject: [PATCH 1/3] Try to support orchard vanilla circuits generated from orchard_zsa crate --- Cargo.lock | 21 +++ Cargo.toml | 1 + halo2_gadgets/src/sinsemilla/chip.rs | 6 +- .../src/sinsemilla/chip/generator_table.rs | 117 ++++++------ .../src/utilities/lookup_range_check.rs | 168 +++++++++++------- halo2_proofs/src/dev/cost.rs | 3 + 6 files changed, 189 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f8bc71dfb..7b48b4f4a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -864,6 +864,27 @@ dependencies = [ "uint", ] +[[package]] +name = "halo2_gadgets_zsa" +version = "0.3.0" +dependencies = [ + "arrayvec", + "bitvec", + "criterion", + "ff", + "group", + "halo2_proofs", + "inferno", + "lazy_static", + "pasta_curves", + "plotters", + "pprof", + "proptest", + "rand", + "subtle", + "uint", +] + [[package]] name = "halo2_legacy_pdqsort" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b7878ae843..dbb7735770 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,6 @@ members = [ "halo2", "halo2_gadgets", + "halo2_gadgets_zsa", "halo2_proofs", ] diff --git a/halo2_gadgets/src/sinsemilla/chip.rs b/halo2_gadgets/src/sinsemilla/chip.rs index c55efd1105..222886a867 100644 --- a/halo2_gadgets/src/sinsemilla/chip.rs +++ b/halo2_gadgets/src/sinsemilla/chip.rs @@ -153,7 +153,7 @@ where advices: [Column; 5], witness_pieces: Column, fixed_y_q: Column, - lookup: (TableColumn, TableColumn, TableColumn, TableColumn), + lookup: (TableColumn, TableColumn, TableColumn, Option), range_check: LookupRangeCheckConfig, ) -> >::Config { // Enable equality on all advice columns @@ -204,7 +204,9 @@ where // https://p.z.cash/halo2-0.1:sinsemilla-constraints?partial meta.create_gate("Initial y_Q", |meta| { let q_s4 = meta.query_selector(config.q_sinsemilla4); - let y_q = meta.query_advice(config.double_and_add.x_p, Rotation::prev()); + let y_q = meta.query_fixed(config.fixed_y_q); + // FIXME: restore zsa version: + //let y_q = meta.query_advice(config.double_and_add.x_p, Rotation::prev()); // Y_A = (lambda_1 + lambda_2) * (x_a - x_r) let Y_A_cur = Y_A(meta, Rotation::cur()); diff --git a/halo2_gadgets/src/sinsemilla/chip/generator_table.rs b/halo2_gadgets/src/sinsemilla/chip/generator_table.rs index e77928b128..3d8943d5e7 100644 --- a/halo2_gadgets/src/sinsemilla/chip/generator_table.rs +++ b/halo2_gadgets/src/sinsemilla/chip/generator_table.rs @@ -15,7 +15,7 @@ pub struct GeneratorTableConfig { pub table_idx: TableColumn, pub table_x: TableColumn, pub table_y: TableColumn, - pub table_range_check_tag: TableColumn, + pub table_range_check_tag: Option, } impl GeneratorTableConfig { @@ -107,65 +107,68 @@ impl GeneratorTableConfig { )?; table.assign_cell(|| "table_x", self.table_x, index, || Value::known(*x))?; table.assign_cell(|| "table_y", self.table_y, index, || Value::known(*y))?; - table.assign_cell( - || "table_range_check_tag", - self.table_range_check_tag, - index, - || Value::known(pallas::Base::zero()), - )?; - if index < (1 << 4) { - let new_index = index + (1 << K); - table.assign_cell( - || "table_idx", - self.table_idx, - new_index, - || Value::known(pallas::Base::from(index as u64)), - )?; - table.assign_cell( - || "table_x", - self.table_x, - new_index, - || Value::known(*x), - )?; - table.assign_cell( - || "table_y", - self.table_y, - new_index, - || Value::known(*y), - )?; - table.assign_cell( - || "table_range_check_tag", - self.table_range_check_tag, - new_index, - || Value::known(pallas::Base::from(4_u64)), - )?; - } - if index < (1 << 5) { - let new_index = index + (1 << 10) + (1 << 4); - table.assign_cell( - || "table_idx", - self.table_idx, - new_index, - || Value::known(pallas::Base::from(index as u64)), - )?; - table.assign_cell( - || "table_x", - self.table_x, - new_index, - || Value::known(*x), - )?; - table.assign_cell( - || "table_y", - self.table_y, - new_index, - || Value::known(*y), - )?; + + if let Some(table_range_check_tag) = self.table_range_check_tag { table.assign_cell( || "table_range_check_tag", - self.table_range_check_tag, - new_index, - || Value::known(pallas::Base::from(5_u64)), + table_range_check_tag, + index, + || Value::known(pallas::Base::zero()), )?; + if index < (1 << 4) { + let new_index = index + (1 << K); + table.assign_cell( + || "table_idx", + self.table_idx, + new_index, + || Value::known(pallas::Base::from(index as u64)), + )?; + table.assign_cell( + || "table_x", + self.table_x, + new_index, + || Value::known(*x), + )?; + table.assign_cell( + || "table_y", + self.table_y, + new_index, + || Value::known(*y), + )?; + table.assign_cell( + || "table_range_check_tag", + table_range_check_tag, + new_index, + || Value::known(pallas::Base::from(4_u64)), + )?; + } + if index < (1 << 5) { + let new_index = index + (1 << 10) + (1 << 4); + table.assign_cell( + || "table_idx", + self.table_idx, + new_index, + || Value::known(pallas::Base::from(index as u64)), + )?; + table.assign_cell( + || "table_x", + self.table_x, + new_index, + || Value::known(*x), + )?; + table.assign_cell( + || "table_y", + self.table_y, + new_index, + || Value::known(*y), + )?; + table.assign_cell( + || "table_range_check_tag", + table_range_check_tag, + new_index, + || Value::known(pallas::Base::from(5_u64)), + )?; + } } } Ok(()) diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 64b4ce4c90..e03e39dce9 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -54,17 +54,24 @@ impl RangeConstrained> { } } +// FIXME: add a proper doc +/// ZsaExtension +#[derive(Eq, PartialEq, Debug, Clone, Copy)] +pub struct ZsaExtension { + q_range_check_4: Selector, + q_range_check_5: Selector, + table_range_check_tag: TableColumn, +} + /// Configuration that provides methods for a lookup range check. #[derive(Eq, PartialEq, Debug, Clone, Copy)] pub struct LookupRangeCheckConfig { q_lookup: Selector, q_running: Selector, q_bitshift: Selector, - q_range_check_4: Selector, - q_range_check_5: Selector, running_sum: Column, table_idx: TableColumn, - table_range_check_tag: TableColumn, + zsa: Option, _marker: PhantomData, } @@ -84,24 +91,31 @@ impl LookupRangeCheckConfig { meta: &mut ConstraintSystem, running_sum: Column, table_idx: TableColumn, - table_range_check_tag: TableColumn, + table_range_check_tag: Option, ) -> Self { meta.enable_equality(running_sum); let q_lookup = meta.complex_selector(); let q_running = meta.complex_selector(); let q_bitshift = meta.selector(); - let q_range_check_4 = meta.complex_selector(); - let q_range_check_5 = meta.complex_selector(); + // FIXME: q_range_check_4 and q_range_check_5 need to be created here + // if the order of the creation makes a difference let config = LookupRangeCheckConfig { q_lookup, q_running, q_bitshift, - q_range_check_4, - q_range_check_5, running_sum, table_idx, - table_range_check_tag, + zsa: table_range_check_tag.map(|table_range_check_tag| { + let q_range_check_4 = meta.complex_selector(); + let q_range_check_5 = meta.complex_selector(); + + ZsaExtension { + q_range_check_4, + q_range_check_5, + table_range_check_tag, + } + }), _marker: PhantomData, }; @@ -109,8 +123,8 @@ impl LookupRangeCheckConfig { meta.lookup(|meta| { let q_lookup = meta.query_selector(config.q_lookup); let q_running = meta.query_selector(config.q_running); - let q_range_check_4 = meta.query_selector(config.q_range_check_4); - let q_range_check_5 = meta.query_selector(config.q_range_check_5); + // FIXME: q_range_check_4 and q_range_check_5 need to be created here + // if the order of the creation makes a difference let z_cur = meta.query_advice(config.running_sum, Rotation::cur()); let one = Expression::Constant(F::ONE); @@ -135,34 +149,45 @@ impl LookupRangeCheckConfig { q_short * short_word }; - // q_range_check is equal to - // - 1 if q_range_check_4 = 1 or q_range_check_5 = 1 - // - 0 otherwise - let q_range_check = one.clone() - - (one.clone() - q_range_check_4.clone()) * (one.clone() - q_range_check_5.clone()); - - // num_bits is equal to - // - 5 if q_range_check_5 = 1 - // - 4 if q_range_check_4 = 1 and q_range_check_5 = 0 - // - 0 otherwise - let num_bits = q_range_check_5.clone() * Expression::Constant(F::from(5_u64)) - + (one.clone() - q_range_check_5) - * q_range_check_4 - * Expression::Constant(F::from(4_u64)); - - // Combine the running sum, short lookups and optimized range checks: - vec![ - ( - q_lookup.clone() - * ((one - q_range_check.clone()) * (running_sum_lookup + short_lookup) - + q_range_check.clone() * z_cur), + if let Some(zsa) = config.zsa { + let q_range_check_4 = meta.query_selector(zsa.q_range_check_4); + let q_range_check_5 = meta.query_selector(zsa.q_range_check_5); + + // q_range_check is equal to + // - 1 if q_range_check_4 = 1 or q_range_check_5 = 1 + // - 0 otherwise + let q_range_check = one.clone() + - (one.clone() - q_range_check_4.clone()) + * (one.clone() - q_range_check_5.clone()); + + // num_bits is equal to + // - 5 if q_range_check_5 = 1 + // - 4 if q_range_check_4 = 1 and q_range_check_5 = 0 + // - 0 otherwise + let num_bits = q_range_check_5.clone() * Expression::Constant(F::from(5_u64)) + + (one.clone() - q_range_check_5) + * q_range_check_4 + * Expression::Constant(F::from(4_u64)); + + // Combine the running sum, short lookups and optimized range checks: + vec![ + ( + q_lookup.clone() + * ((one - q_range_check.clone()) * (running_sum_lookup + short_lookup) + + q_range_check.clone() * z_cur), + config.table_idx, + ), + ( + q_lookup * q_range_check * num_bits, + zsa.table_range_check_tag, + ), + ] + } else { + vec![( + q_lookup * (running_sum_lookup + short_lookup), config.table_idx, - ), - ( - q_lookup * q_range_check * num_bits, - config.table_range_check_tag, - ), - ] + )] + } }); // For short lookups, check that the word has been shifted by the correct number of bits. @@ -424,41 +449,48 @@ impl LookupRangeCheckConfig { // Enable lookup for `element`. self.q_lookup.enable(region, 0)?; - match num_bits { - 4 => { - self.q_range_check_4.enable(region, 0)?; - } - 5 => { - self.q_range_check_5.enable(region, 0)?; - } - _ => { - // Enable lookup for shifted element, to constrain it to 10 bits. - self.q_lookup.enable(region, 1)?; - - // Check element has been shifted by the correct number of bits. - self.q_bitshift.enable(region, 1)?; - - // Assign shifted `element * 2^{K - num_bits}` - let shifted = element.value().into_field() * F::from(1 << (K - num_bits)); + // FIXME: consider refactoring of this + if let Some(zsa) = self.zsa { + match num_bits { + 4 => { + zsa.q_range_check_4.enable(region, 0)?; + return Ok(()); + } - region.assign_advice( - || format!("element * 2^({}-{})", K, num_bits), - self.running_sum, - 1, - || shifted, - )?; + 5 => { + zsa.q_range_check_5.enable(region, 0)?; + return Ok(()); + } - // Assign 2^{-num_bits} from a fixed column. - let inv_two_pow_s = F::from(1 << num_bits).invert().unwrap(); - region.assign_advice_from_constant( - || format!("2^(-{})", num_bits), - self.running_sum, - 2, - inv_two_pow_s, - )?; + _ => {} } } + // Enable lookup for shifted element, to constrain it to 10 bits. + self.q_lookup.enable(region, 1)?; + + // Check element has been shifted by the correct number of bits. + self.q_bitshift.enable(region, 1)?; + + // Assign shifted `element * 2^{K - num_bits}` + let shifted = element.value().into_field() * F::from(1 << (K - num_bits)); + + region.assign_advice( + || format!("element * 2^({}-{})", K, num_bits), + self.running_sum, + 1, + || shifted, + )?; + + // Assign 2^{-num_bits} from a fixed column. + let inv_two_pow_s = F::from(1 << num_bits).invert().unwrap(); + region.assign_advice_from_constant( + || format!("2^(-{})", num_bits), + self.running_sum, + 2, + inv_two_pow_s, + )?; + Ok(()) } } diff --git a/halo2_proofs/src/dev/cost.rs b/halo2_proofs/src/dev/cost.rs index 0c3c7efaf1..1fe8043ce0 100644 --- a/halo2_proofs/src/dev/cost.rs +++ b/halo2_proofs/src/dev/cost.rs @@ -270,6 +270,9 @@ impl> CircuitCost= cs.minimum_rows()); From 067eca51135c06922a71200e83caac1d2c843b7f Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Sat, 24 Feb 2024 20:17:38 +0100 Subject: [PATCH 2/3] Make missed fixes for the previous commit and provide a draft generalization to generate both vanilla and zsa circuit --- Cargo.lock | 21 ------ Cargo.toml | 1 - halo2_gadgets/src/sinsemilla.rs | 4 ++ halo2_gadgets/src/sinsemilla/chip.rs | 13 +++- .../src/sinsemilla/chip/hash_to_point.rs | 64 ++++++++++++++++++- .../src/utilities/lookup_range_check.rs | 2 +- halo2_proofs/src/dev/cost.rs | 3 - 7 files changed, 77 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b48b4f4a0..2f8bc71dfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -864,27 +864,6 @@ dependencies = [ "uint", ] -[[package]] -name = "halo2_gadgets_zsa" -version = "0.3.0" -dependencies = [ - "arrayvec", - "bitvec", - "criterion", - "ff", - "group", - "halo2_proofs", - "inferno", - "lazy_static", - "pasta_curves", - "plotters", - "pprof", - "proptest", - "rand", - "subtle", - "uint", -] - [[package]] name = "halo2_legacy_pdqsort" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index dbb7735770..b7878ae843 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,5 @@ members = [ "halo2", "halo2_gadgets", - "halo2_gadgets_zsa", "halo2_proofs", ] diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index e57c0a2129..7bae069dd8 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -515,8 +515,12 @@ where Error, > { assert_eq!(self.M.sinsemilla_chip, message.chip); + + // FIXME: it's not a breaking change because `blinding_factor` simply wraps `R.mul` + // and `hash` simply wraps `M.hash_to_point` - are those wrapper really needed? let blind = self.blinding_factor(layouter.namespace(|| "[r] R"), r)?; let (p, zs) = self.hash(layouter.namespace(|| "M"), message)?; + let commitment = p.add(layouter.namespace(|| "M + [r] R"), &blind)?; Ok((commitment, zs)) } diff --git a/halo2_gadgets/src/sinsemilla/chip.rs b/halo2_gadgets/src/sinsemilla/chip.rs index 222886a867..022941dd82 100644 --- a/halo2_gadgets/src/sinsemilla/chip.rs +++ b/halo2_gadgets/src/sinsemilla/chip.rs @@ -59,6 +59,8 @@ where pub(super) generator_table: GeneratorTableConfig, /// An advice column configured to perform lookup range checks. lookup_config: LookupRangeCheckConfig, + /// FIXME: add a proper comment + is_zsa_variant: bool, _marker: PhantomData<(Hash, Commit, F)>, } @@ -181,6 +183,8 @@ where table_range_check_tag: lookup.3, }, lookup_config: range_check, + // FIXME: consider passing is_zsa_enabled to `configure` function explicitly + is_zsa_variant: lookup.3.is_some(), _marker: PhantomData, }; @@ -204,9 +208,12 @@ where // https://p.z.cash/halo2-0.1:sinsemilla-constraints?partial meta.create_gate("Initial y_Q", |meta| { let q_s4 = meta.query_selector(config.q_sinsemilla4); - let y_q = meta.query_fixed(config.fixed_y_q); - // FIXME: restore zsa version: - //let y_q = meta.query_advice(config.double_and_add.x_p, Rotation::prev()); + + let y_q = if config.is_zsa_variant { + meta.query_advice(config.double_and_add.x_p, Rotation::prev()) + } else { + meta.query_fixed(config.fixed_y_q) + }; // Y_A = (lambda_1 + lambda_2) * (x_a - x_r) let Y_A_cur = Y_A(meta, Rotation::cur()); diff --git a/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs b/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs index 165615efaa..c9c4bdb470 100644 --- a/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs +++ b/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs @@ -41,7 +41,11 @@ where ), Error, > { - let (offset, x_a, y_a) = self.public_initialization(region, Q)?; + let (offset, x_a, y_a) = if self.config.is_zsa_variant { + self.public_initialization_zsa(region, Q)? + } else { + self.public_initialization(region, Q)? + }; let (x_a, y_a, zs_sum) = self.hash_all_pieces(region, offset, message, x_a, y_a)?; @@ -116,6 +120,19 @@ where let (x_a, y_a, zs_sum) = self.hash_all_pieces(region, offset, message, x_a, y_a)?; + // FIXME: try to avoid duplication with a very similar code block in `hash_message` method + // - it's basically the same code except the following lines: + // + // hash_message_with_private_init: + // ... + // .zip(Q.point()) + // .assert_if_known(|((field_elems, (x_a, y_a)), Q)| { + // ... + // + // hash_message: + // ... + // .assert_if_known(|(field_elems, (x_a, y_a))| { + // ... #[cfg(test)] #[allow(non_snake_case)] // Check equivalence to result from primitives::sinsemilla::hash_to_point @@ -165,6 +182,49 @@ where )) } + #[allow(non_snake_case)] + fn public_initialization( + &self, + region: &mut Region<'_, pallas::Base>, + Q: pallas::Affine, + ) -> Result<(usize, X, Y), Error> { + let config = self.config().clone(); + let offset = 0; + + // Get the `x`- and `y`-coordinates of the starting `Q` base. + let x_q = *Q.coordinates().unwrap().x(); + let y_q = *Q.coordinates().unwrap().y(); + + // Constrain the initial x_a, lambda_1, lambda_2, x_p using the q_sinsemilla4 + // selector. + let y_a: Y = { + // Enable `q_sinsemilla4` on the first row. + config.q_sinsemilla4.enable(region, offset)?; + region.assign_fixed( + || "fixed y_q", + config.fixed_y_q, + offset, + || Value::known(y_q), + )?; + + Value::known(y_q.into()).into() + }; + + // Constrain the initial x_q to equal the x-coordinate of the domain's `Q`. + let x_a: X = { + let x_a = region.assign_advice_from_constant( + || "fixed x_q", + config.double_and_add.x_a, + offset, + x_q.into(), + )?; + + x_a.into() + }; + + Ok((offset, x_a, y_a)) + } + #[allow(non_snake_case)] /// Assign the coordinates of the initial public point `Q` /// @@ -172,7 +232,7 @@ where /// -------------------------------------- /// | 0 | | y_Q | | /// | 1 | x_Q | | 1 | - fn public_initialization( + fn public_initialization_zsa( &self, region: &mut Region<'_, pallas::Base>, Q: pallas::Affine, diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index e03e39dce9..04e94e30df 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -49,7 +49,7 @@ impl RangeConstrained> { .map(|inner| Self { inner, num_bits, - _phantom: PhantomData::default(), + _phantom: PhantomData, }) } } diff --git a/halo2_proofs/src/dev/cost.rs b/halo2_proofs/src/dev/cost.rs index 1fe8043ce0..0c3c7efaf1 100644 --- a/halo2_proofs/src/dev/cost.rs +++ b/halo2_proofs/src/dev/cost.rs @@ -270,9 +270,6 @@ impl> CircuitCost= cs.minimum_rows()); From 4cc147385e7cf106b9fab6d6951d66a343899e38 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Mon, 26 Feb 2024 21:13:37 +0100 Subject: [PATCH 3/3] Update unit tests to support the code modifications related to backward compatability --- halo2_gadgets/src/ecc.rs | 2 +- halo2_gadgets/src/ecc/chip/mul_fixed/short.rs | 4 +- halo2_gadgets/src/sinsemilla.rs | 4 +- halo2_gadgets/src/sinsemilla/merkle.rs | 2 +- halo2_gadgets/src/utilities/cond_swap.rs | 2 +- .../src/utilities/lookup_range_check.rs | 110 ++++++++++-------- 6 files changed, 71 insertions(+), 53 deletions(-) diff --git a/halo2_gadgets/src/ecc.rs b/halo2_gadgets/src/ecc.rs index 4861a20e52..f8da830b5f 100644 --- a/halo2_gadgets/src/ecc.rs +++ b/halo2_gadgets/src/ecc.rs @@ -812,7 +812,7 @@ pub(crate) mod tests { meta, advices[9], lookup_table, - table_range_check_tag, + Some(table_range_check_tag), ); EccChip::::configure(meta, advices, lagrange_coeffs, range_check) } diff --git a/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs b/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs index a10c54c1ed..0b576d50a7 100644 --- a/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs +++ b/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs @@ -528,7 +528,7 @@ pub mod tests { meta, advices[9], lookup_table, - table_range_check_tag, + Some(table_range_check_tag), ); EccChip::::configure(meta, advices, lagrange_coeffs, range_check) } @@ -853,7 +853,7 @@ pub mod tests { meta, advices[9], lookup_table, - table_range_check_tag, + Some(table_range_check_tag), ); EccChip::::configure(meta, advices, lagrange_coeffs, range_check) } diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index 7bae069dd8..0cfd821e98 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -658,14 +658,14 @@ pub(crate) mod tests { table_idx, meta.lookup_table_column(), meta.lookup_table_column(), - table_range_check_tag, + Some(table_range_check_tag), ); let range_check = LookupRangeCheckConfig::configure( meta, advices[9], table_idx, - table_range_check_tag, + Some(table_range_check_tag), ); let ecc_config = diff --git a/halo2_gadgets/src/sinsemilla/merkle.rs b/halo2_gadgets/src/sinsemilla/merkle.rs index 1eabfaa870..c9c088f16b 100644 --- a/halo2_gadgets/src/sinsemilla/merkle.rs +++ b/halo2_gadgets/src/sinsemilla/merkle.rs @@ -246,7 +246,7 @@ pub mod tests { meta.lookup_table_column(), meta.lookup_table_column(), meta.lookup_table_column(), - meta.lookup_table_column(), + Some(meta.lookup_table_column()), ); let range_check = diff --git a/halo2_gadgets/src/utilities/cond_swap.rs b/halo2_gadgets/src/utilities/cond_swap.rs index 78049e742a..46c0a5ded2 100644 --- a/halo2_gadgets/src/utilities/cond_swap.rs +++ b/halo2_gadgets/src/utilities/cond_swap.rs @@ -484,7 +484,7 @@ mod tests { meta, advices[9], table_idx, - table_range_check_tag, + Some(table_range_check_tag), ); let ecc_config = EccChip::::configure( diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 04e94e30df..8d14462c68 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -219,50 +219,68 @@ impl LookupRangeCheckConfig { layouter.assign_table( || "table_idx", |mut table| { - // We generate the row values lazily (we only need them during keygen). - for index in 0..(1 << K) { - table.assign_cell( - || "table_idx", - self.table_idx, - index, - || Value::known(F::from(index as u64)), - )?; - table.assign_cell( - || "table_range_check_tag", - self.table_range_check_tag, - index, - || Value::known(F::ZERO), - )?; - } - for index in 0..(1 << 4) { - let new_index = index + (1 << K); - table.assign_cell( - || "table_idx", - self.table_idx, - new_index, - || Value::known(F::from(index as u64)), - )?; - table.assign_cell( - || "table_range_check_tag", - self.table_range_check_tag, - new_index, - || Value::known(F::from(4_u64)), - )?; - } - for index in 0..(1 << 5) { - let new_index = index + (1 << K) + (1 << 4); - table.assign_cell( - || "table_idx", - self.table_idx, - new_index, - || Value::known(F::from(index as u64)), - )?; - table.assign_cell( - || "table_range_check_tag", - self.table_range_check_tag, - new_index, - || Value::known(F::from(5_u64)), - )?; + match self.zsa { + // Non-ZSA variant + None => { + // We generate the row values lazily (we only need them during keygen). + for index in 0..(1 << K) { + table.assign_cell( + || "table_idx", + self.table_idx, + index, + || Value::known(F::from(index as u64)), + )?; + } + } + + // ZSA variant + Some(zsa) => { + // We generate the row values lazily (we only need them during keygen). + for index in 0..(1 << K) { + table.assign_cell( + || "table_idx", + self.table_idx, + index, + || Value::known(F::from(index as u64)), + )?; + table.assign_cell( + || "table_range_check_tag", + zsa.table_range_check_tag, + index, + || Value::known(F::ZERO), + )?; + } + for index in 0..(1 << 4) { + let new_index = index + (1 << K); + table.assign_cell( + || "table_idx", + self.table_idx, + new_index, + || Value::known(F::from(index as u64)), + )?; + table.assign_cell( + || "table_range_check_tag", + zsa.table_range_check_tag, + new_index, + || Value::known(F::from(4_u64)), + )?; + } + for index in 0..(1 << 5) { + let new_index = index + (1 << K) + (1 << 4); + table.assign_cell( + || "table_idx", + self.table_idx, + new_index, + || Value::known(F::from(index as u64)), + )?; + table.assign_cell( + || "table_range_check_tag", + zsa.table_range_check_tag, + new_index, + || Value::known(F::from(5_u64)), + )?; + } + } } Ok(()) }, @@ -539,7 +557,7 @@ mod tests { meta, running_sum, table_idx, - table_range_check_tag, + Some(table_range_check_tag), ) } @@ -644,7 +662,7 @@ mod tests { meta, running_sum, table_idx, - table_range_check_tag, + Some(table_range_check_tag), ) }