Skip to content

Commit

Permalink
add test for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoGalteland committed Mar 24, 2024
1 parent 4560230 commit 1440a36
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<F: PrimeFieldBits> RangeConstrained<F, AssignedCell<F, F>> {
}
}

// FIXME: add a proper doc
// FIXME: add a proper doc, rename ZsaExtension?
/// ZsaExtension
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
pub struct ZsaExtension {
Expand Down Expand Up @@ -507,10 +507,15 @@ mod tests {
dev::{FailureLocation, MockProver, VerifyFailure},
plonk::{Circuit, ConstraintSystem, Error},
};
use pasta_curves::pallas;
use pasta_curves::{pallas, vesta};

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `vesta`

warning: unused import: `vesta` --> halo2_gadgets/src/utilities/lookup_range_check.rs:510:32 | 510 | use pasta_curves::{pallas, vesta}; | ^^^^^

Check failure on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unused import: `vesta`

error: unused import: `vesta` --> halo2_gadgets/src/utilities/lookup_range_check.rs:510:32 | 510 | use pasta_curves::{pallas, vesta}; | ^^^^^ | = note: `-D unused-imports` implied by `-D warnings`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with beta features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with beta features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with beta features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with beta features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with nightly features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with nightly features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with nightly features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with nightly features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with beta features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with beta features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with nightly features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with nightly features

unused import: `vesta`

Check warning on line 510 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

unused import: `vesta`

use std::{convert::TryInto, marker::PhantomData};

Check warning on line 512 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

the item `TryInto` is imported redundantly

warning: the item `TryInto` is imported redundantly --> halo2_gadgets/src/utilities/lookup_range_check.rs:512:15 | 512 | use std::{convert::TryInto, marker::PhantomData}; | ^^^^^^^^^^^^^^^^ --> /rustc/277d06bc95c6c38a2337ccde798b2c709384bd84/library/std/src/prelude/mod.rs:129:13 | = note: the item `TryInto` is already defined here

// 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;

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

constant `enable_backward_compatibility` should have an upper case name

warning: constant `enable_backward_compatibility` should have an upper case name --> halo2_gadgets/src/utilities/lookup_range_check.rs:517:15 | 517 | pub const enable_backward_compatibility: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper case: `ENABLE_BACKWARD_COMPATIBILITY` | = note: `#[warn(non_upper_case_globals)]` on by default

Check failure on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

constant `enable_backward_compatibility` should have an upper case name

error: constant `enable_backward_compatibility` should have an upper case name --> halo2_gadgets/src/utilities/lookup_range_check.rs:517:15 | 517 | pub const enable_backward_compatibility: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper case: `ENABLE_BACKWARD_COMPATIBILITY` | = note: `-D non-upper-case-globals` implied by `-D warnings`

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with beta features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with beta features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with beta features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with beta features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with nightly features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with nightly features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with nightly features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with nightly features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with beta features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with beta features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with nightly features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with nightly features

constant `enable_backward_compatibility` should have an upper case name

Check warning on line 517 in halo2_gadgets/src/utilities/lookup_range_check.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

constant `enable_backward_compatibility` should have an upper case name

#[test]
fn lookup_range_check() {
#[derive(Clone, Copy)]
Expand All @@ -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::<F, K>::configure(
meta,
running_sum,
table_idx,
Some(table_range_check_tag),
table_range_check_tag_option,
)
}

Expand Down Expand Up @@ -571,6 +581,7 @@ mod tests {
.map(|chunk| F::from(lebs2ip::<K>(chunk.try_into().unwrap())))
.collect::<Vec<_>>()
};

let expected_zs = {
let inv_two_pow_k = F::from(1 << K).invert().unwrap();
chunks.iter().fold(vec![element], |mut zs, a_i| {
Expand Down Expand Up @@ -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::<F, K>::configure(
meta,
running_sum,
table_idx,
Some(table_range_check_tag),
table_range_check_tag_option,
)
}

Expand Down Expand Up @@ -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<pallas::Base> = MyCircuit {
element: Value::known(pallas::Base::from(1 << 5)),
num_bits: 5,
Expand Down

0 comments on commit 1440a36

Please sign in to comment.