Skip to content

Commit

Permalink
first pass at error check evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
adr1anh committed Jul 4, 2023
1 parent beaee8a commit f16aa39
Show file tree
Hide file tree
Showing 9 changed files with 1,507 additions and 1,006 deletions.
38 changes: 33 additions & 5 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl TryFrom<Column<Any>> for Column<Instance> {
/// Ok(())
/// }
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Selector(pub(crate) usize, bool);

impl Selector {
Expand All @@ -479,7 +479,7 @@ impl Selector {
}

/// Query of fixed column at a certain relative location
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct FixedQuery {
/// Query index
pub(crate) index: Option<usize>,
Expand All @@ -502,7 +502,7 @@ impl FixedQuery {
}

/// Query of advice column at a certain relative location
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct AdviceQuery {
/// Query index
pub(crate) index: Option<usize>,
Expand Down Expand Up @@ -532,7 +532,7 @@ impl AdviceQuery {
}

/// Query of instance column at a certain relative location
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct InstanceQuery {
/// Query index
pub(crate) index: Option<usize>,
Expand Down Expand Up @@ -583,7 +583,7 @@ impl TableColumn {
}

/// A challenge squeezed from transcript after advice columns at the phase have been committed.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Challenge {
index: usize,
pub(crate) phase: sealed::Phase,
Expand Down Expand Up @@ -1248,6 +1248,34 @@ impl<F: Field> Expression<F> {
&|a, _| a,
)
}

/// Applies `f` to all leaves
pub fn traverse(&self, f: &mut impl FnMut(&Expression<F>)) {
match self {
Expression::Negated(e) => e.traverse(f),
Expression::Sum(e1, e2) => {
e1.traverse(f);
e2.traverse(f);
}
Expression::Product(e1, e2) => {
e1.traverse(f);
e2.traverse(f);
}
Expression::Scaled(e, _) => e.traverse(f),
v => f(v),
}
}

/// If the whole polynomial is multiplied by a simple selector, return it along with the expression it selects
pub fn extract_top_selector(&self) -> (Option<Selector>, &Expression<F>) {
match self {
Expression::Product(e1, e2) => match (&**e1, &**e2) {
(Expression::Selector(s), e) | (e, Expression::Selector(s)) => (Some(*s), e),
_ => (None, self),
},
_ => (None, self),
}
}
}

impl<F: std::fmt::Debug> std::fmt::Debug for Expression<F> {
Expand Down
13 changes: 4 additions & 9 deletions halo2_proofs/src/plonk/permutation/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,9 @@ impl Assembly {
}
}

pub(crate) fn build_permutations<'params, C: CurveAffine, P: Params<'params, C>>(
&mut self,
params: &P,
p: &Argument,
) -> Vec<Vec<usize>> {
pub(crate) fn build_permutations(&mut self, n: usize, p: &Argument) -> Vec<Vec<usize>> {
self.build_ordered_mapping();
build_permutations(params, p, |i, j| self.mapping_at_idx(i, j))
build_permutations(n, p, |i, j| self.mapping_at_idx(i, j))
}

pub(crate) fn build_vk<'params, C: CurveAffine, P: Params<'params, C>>(
Expand Down Expand Up @@ -333,12 +329,11 @@ impl Assembly {
}
}

pub(crate) fn build_permutations<'params, C: CurveAffine, P: Params<'params, C>>(
params: &P,
pub(crate) fn build_permutations(
n: usize,
p: &Argument,
mapping: impl Fn(usize, usize) -> (usize, usize) + Sync,
) -> Vec<Vec<usize>> {
let n = params.n() as usize;
// Compute permutation polynomials, convert to coset form.
let mut permutations = vec![vec![0; n]; p.columns.len()];
{
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl<'a, F: Field, B: Basis> Sub<F> for &'a Polynomial<F, B> {
/// Describes the relative rotation of a vector. Negative numbers represent
/// reverse (leftmost) rotations and positive numbers represent forward (rightmost)
/// rotations. Zero represents no rotation.
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Rotation(pub i32);

impl Rotation {
Expand Down
31 changes: 31 additions & 0 deletions halo2_proofs/src/protostar/error_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::collections::BTreeMap;

use crate::poly::{LagrangeCoeff, Polynomial};
use halo2curves::CurveAffine;

// enum CircuitInstance<C:CurveAffine> {
// Raw(Vec<Poly<C::Scalar, LagrangeCoeff>>),
// Committed(Vec<C>),
// }

struct AccumulatorInstance<C: CurveAffine> {
// challenges[i][p] = challenge[i][0]^{p-1}
// p is the power of the challenge and >1.
challenges: Vec<Vec<C::Scalar>>,
instance_polys: Vec<Polynomial<C::Scalar, LagrangeCoeff>>,
advice_commitments: Vec<C>,

// powers of the constraint separation challenge
y_challenges: Vec<C::Scalar>,
// thetas: Vec<C::Scalar>,
// aux_lookup_commitments: Vec<C>,
// aux_table_online_commitments: Vec<C>,
// aux_table_fixed_commitments: Vec<C>,
}

struct AccumulatorWitness<C: CurveAffine> {
advice_polys: Vec<Polynomial<C::Scalar, LagrangeCoeff>>,
// aux_lookup_polys: Vec<Polynomial<C::Scalar, LagrangeCoeff>>,
// aux_table_polys: Vec<BTreeMap<usize, C::Scalar>>,
// aux_cached_polys: Vec<BTreeMap<usize, C::Scalar>>,
}
Loading

0 comments on commit f16aa39

Please sign in to comment.