From 1440a36c7c9298be50770242b890535d91b749af Mon Sep 17 00:00:00 2001 From: YaoGalteland Date: Sun, 24 Mar 2024 20:33:03 +0100 Subject: [PATCH] add test for backward compatibility --- .../src/utilities/lookup_range_check.rs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index c8b617c315..684f6f0680 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -54,7 +54,7 @@ impl RangeConstrained> { } } -// FIXME: add a proper doc +// FIXME: add a proper doc, rename ZsaExtension? /// ZsaExtension #[derive(Eq, PartialEq, Debug, Clone, Copy)] pub struct ZsaExtension { @@ -507,10 +507,15 @@ mod tests { dev::{FailureLocation, MockProver, VerifyFailure}, plonk::{Circuit, ConstraintSystem, Error}, }; - use pasta_curves::pallas; + use pasta_curves::{pallas, vesta}; use std::{convert::TryInto, marker::PhantomData}; + // test backward compatibility + // if enable_backward_compatibility = true, test the old version + // if enable_backward_compatibility = false, test the new version with extended lookup table + pub const enable_backward_compatibility: bool = false; + #[test] fn lookup_range_check() { #[derive(Clone, Copy)] @@ -534,11 +539,16 @@ mod tests { let constants = meta.fixed_column(); meta.enable_constant(constants); + let table_range_check_tag_option = if enable_backward_compatibility { + None + } else { + Some(table_range_check_tag) + }; LookupRangeCheckConfig::::configure( meta, running_sum, table_idx, - Some(table_range_check_tag), + table_range_check_tag_option, ) } @@ -571,6 +581,7 @@ mod tests { .map(|chunk| F::from(lebs2ip::(chunk.try_into().unwrap()))) .collect::>() }; + let expected_zs = { let inv_two_pow_k = F::from(1 << K).invert().unwrap(); chunks.iter().fold(vec![element], |mut zs, a_i| { @@ -639,11 +650,16 @@ mod tests { let constants = meta.fixed_column(); meta.enable_constant(constants); + let table_range_check_tag_option = if enable_backward_compatibility { + None + } else { + Some(table_range_check_tag) + }; LookupRangeCheckConfig::::configure( meta, running_sum, table_idx, - Some(table_range_check_tag), + table_range_check_tag_option, ) } @@ -781,8 +797,8 @@ mod tests { assert_eq!(prover.verify(), Ok(())); } - // Element larger than 5 bits - { + if !enable_backward_compatibility { + // Element larger than 5 bits let circuit: MyCircuit = MyCircuit { element: Value::known(pallas::Base::from(1 << 5)), num_bits: 5,