Skip to content

Commit

Permalink
update lookup table for generator_table and lookup_range_check
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoGalteland committed Mar 21, 2024
1 parent dc93a71 commit 613b840
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 63 deletions.
101 changes: 40 additions & 61 deletions halo2_gadgets/src/sinsemilla/chip/generator_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use halo2_proofs::{

use super::{CommitDomains, FixedPoints, HashDomains};
use crate::sinsemilla::primitives::{self as sinsemilla, K, SINSEMILLA_S};
use halo2_proofs::circuit::Table;
use pasta_curves::pallas;
use pasta_curves::pallas::Base;

/// Table containing independent generators S[0..2^k]
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
Expand Down Expand Up @@ -98,81 +100,58 @@ impl GeneratorTableConfig {
layouter.assign_table(
|| "generator_table",
|mut table| {
for (index, (x, y)) in SINSEMILLA_S.iter().enumerate() {
table.assign_cell(
|| "table_idx",
self.table_idx,
index,
|| Value::known(pallas::Base::from(index as u64)),
)?;
table.assign_cell(|| "table_x", self.table_x, index, || Value::known(*x))?;
table.assign_cell(|| "table_y", self.table_y, index, || Value::known(*y))?;
self.create_lookup_subtable(&mut table, 0, K)?;

if let Some(table_range_check_tag) = self.table_range_check_tag {
table.assign_cell(
|| "table_range_check_tag",
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),
)?;
if let Some(table_range_check_tag) = self.table_range_check_tag {

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused variable: `table_range_check_tag`

warning: unused variable: `table_range_check_tag` --> halo2_gadgets/src/sinsemilla/chip/generator_table.rs:105:29 | 105 | if let Some(table_range_check_tag) = self.table_range_check_tag { | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_table_range_check_tag` | = note: `#[warn(unused_variables)]` on by default

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused variable: `table_range_check_tag`

warning: unused variable: `table_range_check_tag` --> halo2_gadgets/src/sinsemilla/chip/generator_table.rs:105:29 | 105 | if let Some(table_range_check_tag) = self.table_range_check_tag { | ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_table_range_check_tag` | = note: `#[warn(unused_variables)]` on by default

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Book tests

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Build target wasm32-unknown-unknown

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Bitrot check

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with beta features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with beta features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with nightly features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with nightly features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with beta features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with beta features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with beta features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with beta features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with nightly features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with nightly features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with nightly features

unused variable: `table_range_check_tag`

Check warning on line 105 in halo2_gadgets/src/sinsemilla/chip/generator_table.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with nightly features

unused variable: `table_range_check_tag`
self.create_lookup_subtable(&mut table, 1 << K, 4)?;

self.create_lookup_subtable(&mut table, (1 << K) + (1 << 4), 5)?;
}
Ok(())
},
)
}

// create a lookup range check subtable for an 'index_size'-bit
fn create_lookup_subtable(
&self,
table: &mut Table<Base>,
index_start: usize,
index_size: usize,
) -> Result<(), Error> {
for (index, (x, y)) in SINSEMILLA_S.iter().enumerate() {
if index < (1 << index_size) {
let new_index = index + index_start;
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 {
match index_size {
K => {
table.assign_cell(
|| "table_range_check_tag",
table_range_check_tag,
new_index,
|| Value::known(pallas::Base::from(4_u64)),
|| Value::known(pallas::Base::zero()),
)?;
}
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)),
|| Value::known(pallas::Base::from(index_size as u64)),
)?;
}
}
}
Ok(())
},
)
}
}
Ok(())
}
}
6 changes: 4 additions & 2 deletions halo2_gadgets/src/utilities/lookup_range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ impl<F: PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K> {
|mut table| {
self.create_lookup_subtable(&mut table, 0, K)?;

self.create_lookup_subtable(&mut table, 1 << K, 4)?;
if let Some(extended_lookup_inputs) = self.extended_lookup_inputs {

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

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused variable: `extended_lookup_inputs`

warning: unused variable: `extended_lookup_inputs` --> halo2_gadgets/src/utilities/lookup_range_check.rs:230:29 | 230 | if let Some(extended_lookup_inputs) = self.extended_lookup_inputs { | ^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_extended_lookup_inputs`

Check warning on line 230 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 variable: `extended_lookup_inputs`

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

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

unused variable: `extended_lookup_inputs`

Check warning on line 230 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 variable: `extended_lookup_inputs`

Check warning on line 230 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 variable: `extended_lookup_inputs`

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

View workflow job for this annotation

GitHub Actions / Test on macOS-latest

unused variable: `extended_lookup_inputs`

Check warning on line 230 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 variable: `extended_lookup_inputs`

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

View workflow job for this annotation

GitHub Actions / Test on windows-latest

unused variable: `extended_lookup_inputs`

Check warning on line 230 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 variable: `extended_lookup_inputs`

Check warning on line 230 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 variable: `extended_lookup_inputs`
self.create_lookup_subtable(&mut table, 1 << K, 4)?;

self.create_lookup_subtable(&mut table, (1 << K) + (1 << 4), 5)?;
self.create_lookup_subtable(&mut table, (1 << K) + (1 << 4), 5)?;
}
Ok(())
},
)
Expand Down

0 comments on commit 613b840

Please sign in to comment.