Skip to content

Commit

Permalink
feat: use tagged table to reduce # of lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 committed Aug 30, 2022
1 parent 841d779 commit 4505bf1
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 152 deletions.
3 changes: 1 addition & 2 deletions ecc/src/base_field_ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ mod tests {

fn config_range<N: FieldExt>(&self, layouter: &mut impl Layouter<N>) -> Result<(), Error> {
let range_chip = RangeChip::<N>::new(self.range_config.clone());
range_chip.load_composition_tables(layouter)?;
range_chip.load_overflow_tables(layouter)?;
range_chip.load_table(layouter)?;

Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions ecc/src/general_ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,7 @@ mod tests {

fn config_range<N: FieldExt>(&self, layouter: &mut impl Layouter<N>) -> Result<(), Error> {
let range_chip = RangeChip::<N>::new(self.range_config.clone());
range_chip.load_composition_tables(layouter)?;
range_chip.load_overflow_tables(layouter)?;
range_chip.load_table(layouter)?;

Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions ecdsa/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ mod tests {
layouter: &mut impl Layouter<N>,
) -> Result<(), Error> {
let range_chip = RangeChip::<N>::new(self.range_config.clone());
range_chip.load_composition_tables(layouter)?;
range_chip.load_overflow_tables(layouter)?;
range_chip.load_table(layouter)?;

Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions integer/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,7 @@ mod tests {

fn config_range<N: FieldExt>(&self, layouter: &mut impl Layouter<N>) -> Result<(), Error> {
let range_chip = RangeChip::<N>::new(self.range_config.clone());
range_chip.load_composition_tables(layouter)?;
range_chip.load_overflow_tables(layouter)?;
range_chip.load_table(layouter)?;

Ok(())
}
Expand Down
13 changes: 4 additions & 9 deletions maingate/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
AssignedCondition, AssignedValue, ColumnTags, MainGateColumn,
};
use halo2wrong::{
halo2::plonk::Selector,
utils::{big_to_fe, decompose, fe_to_big, power_of_two},
RegionCtx,
};
Expand Down Expand Up @@ -1003,12 +1002,12 @@ pub trait MainGateInstructions<F: FieldExt, const WIDTH: usize>: Chip<F> {
/// Assigns a new witness composed of given array of terms
/// `result = constant + term_0 + term_1 + ... `
/// where `term_i = a_i * q_i`
fn decompose<T: FnMut(bool) -> Vec<Selector>>(
fn decompose<T: FnMut(&mut RegionCtx<'_, F>, bool) -> Result<(), Error>>(
&self,
ctx: &mut RegionCtx<'_, F>,
terms: &[Term<F>],
constant: F,
mut fetch_tables: T,
mut enable_lookup: T,
) -> Result<(AssignedValue<F>, Vec<AssignedValue<F>>), Error> {
assert!(!terms.is_empty(), "At least one term is expected");

Expand Down Expand Up @@ -1054,11 +1053,7 @@ pub trait MainGateInstructions<F: FieldExt, const WIDTH: usize>: Chip<F> {
CombinationOptionCommon::CombineToNextAdd(F::one())
};

// Enable tables if there is any
let tables = fetch_tables(is_final);
for table in tables {
ctx.enable(table)?;
}
enable_lookup(ctx, is_final)?;

let chunk_len = chunk.len();
let mut combined = self.apply(
Expand Down Expand Up @@ -1098,7 +1093,7 @@ pub trait MainGateInstructions<F: FieldExt, const WIDTH: usize>: Chip<F> {
constant: F,
) -> Result<AssignedValue<F>, Error> {
assert!(!terms.is_empty(), "At least one term is expected");
let (composed, _) = self.decompose(ctx, terms, constant, |_| vec![])?;
let (composed, _) = self.decompose(ctx, terms, constant, |_, _| Ok(()))?;

Ok(composed)
}
Expand Down
Loading

0 comments on commit 4505bf1

Please sign in to comment.