Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RangeChip with tagged table #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions halo2wrong/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod utils;
pub use halo2;
pub use halo2::halo2curves as curves;

#[derive(Debug)]
pub struct RegionCtx<'a, F: FieldExt> {
region: Region<'a, F>,
offset: usize,
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
7 changes: 7 additions & 0 deletions maingate/src/main_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pub struct MainGateConfig {
pub(crate) instance: Column<Instance>,
}

impl MainGateConfig {
/// Returns advice columns of `MainGateConfig`
pub fn advices(&self) -> [Column<Advice>; WIDTH] {
[self.a, self.b, self.c, self.d, self.e]
}
}

/// MainGate implements instructions with [`MainGateConfig`]
#[derive(Clone, Debug)]
pub struct MainGate<F: FieldExt> {
Expand Down
Loading