Skip to content

Commit

Permalink
Formatting the code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseiVambol committed Mar 3, 2024
1 parent a45d3d4 commit 5b7abca
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 69 deletions.
14 changes: 7 additions & 7 deletions halo2_proofs/benches/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ use halo2curves::pairing::Engine;
use rand_core::OsRng;

use halo2_proofs::{
poly::
kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
multiopen::ProverGWC,
strategy::SingleStrategy,
},
poly::kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG},
multiopen::ProverGWC,
strategy::SingleStrategy,
},
transcript::{TranscriptReadBuffer, TranscriptWriterBuffer},
};

Expand Down Expand Up @@ -59,7 +58,8 @@ fn criterion_benchmark(c: &mut Criterion) {

meta.create_gate("degree 6 gate", |meta| {
let dummy_selector = meta.query_selector(dummy_selector);
let constraints = vec![dummy_selector.clone(); 4].iter()
let constraints = vec![dummy_selector.clone(); 4]
.iter()
.fold(dummy_selector.clone(), |acc, val| acc * val.clone());
Constraints::with_selector(dummy_selector, Some(constraints))
});
Expand Down
16 changes: 13 additions & 3 deletions halo2_proofs/src/dev/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,19 @@ fn render_lookup<F: Field>(
let cell_values = input.evaluate(
&|_| BTreeMap::default(),
&|_| panic!("virtual selectors are removed during optimization"),
&cell_value(&util::load(n, row, &cs.fixed_queries, prover.fixed.as_slice())),
&cell_value(&util::load(
n,
row,
&cs.fixed_queries,
prover.fixed.as_slice(),
)),
&cell_value(&util::load(n, row, &cs.advice_queries, &prover.advice)),
&cell_value(&util::load_instance(n, row, &cs.instance_queries, &prover.instance)),
&cell_value(&util::load_instance(
n,
row,
&cs.instance_queries,
&prover.instance,
)),
&|_| BTreeMap::default(),
&|a| a,
&|mut a, mut b| {
Expand All @@ -638,7 +648,7 @@ fn render_lookup<F: Field>(
.or_default()
.entry(cell.column)
.or_insert(format!("x{}", i));
}
}
if i != 0 {
eprintln!();
}
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::BTreeMap;
use super::{mv_lookup, permutation, shuffle, Assigned, Error};
use crate::circuit::layouter::SyncDeps;
use crate::dev::metadata;
Expand All @@ -10,6 +9,7 @@ use core::cmp::max;
use core::ops::{Add, Mul};
use ff::Field;
use sealed::SealedPhase;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fmt::Debug;
use std::iter::{Product, Sum};
Expand Down Expand Up @@ -1825,7 +1825,7 @@ impl<F: Field> ConstraintSystem<F> {
for input in inputs.iter().skip(1) {
let cur_input_degree = input.iter().map(|expr| expr.degree()).max().unwrap();
let mut indicator = false;
for arg in args.iter_mut() {
for arg in args.iter_mut() {
// try to fit input in one of the args
let cur_argument_degree = arg.required_degree();
let new_potential_degree = cur_argument_degree + cur_input_degree;
Expand Down
75 changes: 37 additions & 38 deletions halo2_proofs/src/plonk/evaluation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::{shuffle, ConstraintSystem, Expression};
use crate::multicore;
use crate::plonk::{mv_lookup, permutation, Any, ProvingKey};
use crate::poly::Basis;
Expand All @@ -6,10 +7,12 @@ use crate::{
poly::{Coeff, ExtendedLagrangeCoeff, Polynomial, Rotation},
};
use group::ff::{Field, PrimeField, WithSmallOrderMulGroup};
use super::{shuffle, ConstraintSystem, Expression};

#[cfg(not(feature = "logup_skip_inv"))]
use rayon::{slice::ParallelSlice, prelude::{ParallelIterator, IntoParallelIterator}};
use rayon::{
prelude::{IntoParallelIterator, ParallelIterator},
slice::ParallelSlice,
};

#[cfg(not(feature = "logup_skip_inv"))]
use crate::arithmetic::par_invert;
Expand Down Expand Up @@ -269,7 +272,7 @@ impl<C: CurveAffine> Evaluator<C> {
compressed_table_coset,
ValueSource::Beta(),
));
/*
/*
a) f_i + beta
b) t + beta
*/
Expand Down Expand Up @@ -482,7 +485,6 @@ impl<C: CurveAffine> Evaluator<C> {
});
}


// For lookups, compute inputs_inv_sum = ∑ 1 / (f_i(X) + beta)
// The outer vector has capacity self.lookups.len()
#[cfg(not(feature = "logup_skip_inv"))]
Expand All @@ -497,50 +499,47 @@ impl<C: CurveAffine> Evaluator<C> {
.map(|idx| {
let mut inputs_eval_data: Vec<_> = inputs_lookup_evaluator
.iter()
.map(|input_lookup_evaluator| {
input_lookup_evaluator.instance()
})
.map(|input_lookup_evaluator| input_lookup_evaluator.instance())
.collect();

inputs_lookup_evaluator
.iter()
.zip(inputs_eval_data.iter_mut())
.map(|(input_lookup_evaluator, input_eval_data)| {
input_lookup_evaluator.evaluate(
input_eval_data,
fixed,
advice,
instance,
challenges,
&beta,
&gamma,
&theta,
&y,
&C::ScalarExt::ZERO,
idx,
rot_scale,
isize,
)
})
.collect()
})
.collect();
.iter()
.zip(inputs_eval_data.iter_mut())
.map(|(input_lookup_evaluator, input_eval_data)| {
input_lookup_evaluator.evaluate(
input_eval_data,
fixed,
advice,
instance,
challenges,
&beta,
&gamma,
&theta,
&y,
&C::ScalarExt::ZERO,
idx,
rot_scale,
isize,
)
})
.collect()
})
.collect();

let mut inputs_values_for_extended_domain: Vec<C::Scalar> =
inputs_values_for_extended_domain
.into_iter()
.flatten()
.collect();
.into_iter()
.flatten()
.collect();

par_invert(&mut inputs_values_for_extended_domain);

let inputs_len = inputs_lookup_evaluator.len();

inputs_values_for_extended_domain
.par_chunks_exact(inputs_len)
.map(|values| values.iter().sum())
.collect::<Vec<_>>()

.par_chunks_exact(inputs_len)
.map(|values| values.iter().sum())
.collect::<Vec<_>>()
})
.collect();

Expand All @@ -560,7 +559,7 @@ impl<C: CurveAffine> Evaluator<C> {
LHS = τ(X) * Π(φ_i(X)) * (ϕ(gX) - ϕ(X))
RHS = τ(X) * Π(φ_i(X)) * (∑ 1/(φ_i(X)) - m(X) / τ(X)))) (1)
= (τ(X) * Π(φ_i(X)) * ∑ 1/(φ_i(X))) - Π(φ_i(X)) * m(X)
= Π(φ_i(X)) * (τ(X) * ∑ 1/(φ_i(X)) - m(X))
= Π(φ_i(X)) * (τ(X) * ∑ 1/(φ_i(X)) - m(X))
= ∑_i τ(X) * Π_{j != i} φ_j(X) - m(X) * Π(φ_i(X)) (2)
*/
parallelize(&mut values, |values, start| {
Expand Down Expand Up @@ -639,7 +638,7 @@ impl<C: CurveAffine> Evaluator<C> {
.fold(C::Scalar::ZERO, |acc, x| acc + x);
inputs * table_value - inputs_prod * m_coset[idx]
};

#[cfg(not(feature = "logup_skip_inv"))]
let rhs = {
// ∑ 1 / (f_i(X) + beta) at ω^idx
Expand Down
12 changes: 6 additions & 6 deletions halo2_proofs/src/plonk/mv_lookup/prover.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use super::super::{
circuit::Expression, ChallengeBeta, ChallengeTheta, ChallengeX, Error,
ProvingKey,
circuit::Expression, ChallengeBeta, ChallengeTheta, ChallengeX, Error, ProvingKey,
};
use super::Argument;
use crate::plonk::evaluation::evaluate;
use crate::{
arithmetic::{eval_polynomial, parallelize, parallelize_naive, CurveAffine, Field, par_invert},
arithmetic::{eval_polynomial, par_invert, parallelize, parallelize_naive, CurveAffine, Field},
poly::{
commitment::{Blind, Params},
Coeff, EvaluationDomain, LagrangeCoeff, Polynomial, ProverQuery,
Rotation,
Coeff, EvaluationDomain, LagrangeCoeff, Polynomial, ProverQuery, Rotation,
},
transcript::{EncodedChallenge, TranscriptWrite},
};
Expand All @@ -21,7 +19,9 @@ use std::{
ops::{Mul, MulAssign},
};

use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator, ParallelSliceMut};
use rayon::prelude::{
IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator, ParallelSliceMut,
};

#[derive(Debug)]
pub(in crate::plonk) struct Prepared<C: CurveAffine> {
Expand Down
12 changes: 3 additions & 9 deletions halo2_proofs/src/plonk/mv_lookup/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::iter;

use super::super::{
circuit::Expression, ChallengeBeta, ChallengeTheta, ChallengeX,
};
use super::super::{circuit::Expression, ChallengeBeta, ChallengeTheta, ChallengeX};
use super::Argument;
use crate::{
arithmetic::{CurveAffine, Field},
Expand Down Expand Up @@ -133,15 +131,11 @@ impl<C: CurveAffine> Evaluated<C> {

let tau = t_eval + *beta;
// Π(φ_i(X))
let prod_fi = f_evals
.iter()
.fold(C::Scalar::ONE, |acc, eval| acc * eval);
let prod_fi = f_evals.iter().fold(C::Scalar::ONE, |acc, eval| acc * eval);
// ∑ 1/(φ_i(X))
let sum_inv_fi = {
f_evals.batch_invert();
f_evals
.iter()
.fold(C::Scalar::ZERO, |acc, eval| acc + eval)
f_evals.iter().fold(C::Scalar::ZERO, |acc, eval| acc + eval)
};

// LHS = τ(X) * Π(φ_i(X)) * (ϕ(gX) - ϕ(X))
Expand Down
8 changes: 4 additions & 4 deletions halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,19 @@ fn plonk_api() {
let a_ = meta.query_any(a, Rotation::cur());
vec![(a_, sl)]
});

// Add to test mvlookup
meta.lookup("lookup_same", |meta| {
let a_ = meta.query_any(a, Rotation::cur());
vec![(a_, sl)]
});

meta.lookup("lookup_same", |meta| {
let b_ = meta.query_any(b, Rotation::cur());
let dummy = meta.query_selector(dummy);
let dummy_2 = meta.query_selector(dummy_2);
let dummy_3 = meta.query_selector(dummy_3);

vec![(dummy * dummy_2 * dummy_3 * b_, dummy_table)]
});

Expand Down Expand Up @@ -644,7 +644,7 @@ fn plonk_api() {
test_plonk_api_ipa();
*/

test_plonk_api_gwc();
test_plonk_api_shplonk();
}

0 comments on commit 5b7abca

Please sign in to comment.