diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 64c7dd27..5f7fbfc2 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -55,7 +55,6 @@ getrandom = { version = "0.2", features = ["js"] } default = ["batch", "bits"] bits = ["halo2curves/bits"] gadget-traces = ["backtrace"] -thread-safe-region = [] sanity-checks = [] batch = ["rand_core/getrandom"] circuit-params = [] diff --git a/backend/src/plonk/evaluation.rs b/backend/src/plonk/evaluation.rs index 2cd00a5f..109523ec 100644 --- a/backend/src/plonk/evaluation.rs +++ b/backend/src/plonk/evaluation.rs @@ -390,7 +390,7 @@ impl Evaluator { let blinding_factors = pk.vk.cs.blinding_factors(); let last_rotation = Rotation(-((blinding_factors + 1) as i32)); let chunk_len = pk.vk.cs.degree() - 2; - let delta_start = beta * &C::Scalar::ZETA; + let delta_start = beta * C::Scalar::ZETA; let first_set = sets.first().unwrap(); let last_set = sets.last().unwrap(); @@ -863,7 +863,7 @@ pub fn evaluate( }, &|challenge| challenges[challenge.index()], &|a| -a, - &|a, b| a + &b, + &|a, b| a + b, &|a, b| a * b, &|a, scalar| a * scalar, ); diff --git a/backend/src/plonk/lookup/prover.rs b/backend/src/plonk/lookup/prover.rs index b0124ca4..3af77a7f 100644 --- a/backend/src/plonk/lookup/prover.rs +++ b/backend/src/plonk/lookup/prover.rs @@ -199,7 +199,7 @@ impl Permuted { .zip(self.permuted_input_expression[start..].iter()) .zip(self.permuted_table_expression[start..].iter()) { - *lookup_product = (*beta + permuted_input_value) * &(*gamma + permuted_table_value); + *lookup_product = (*beta + permuted_input_value) * (*gamma + permuted_table_value); } }); @@ -214,8 +214,8 @@ impl Permuted { for (i, product) in product.iter_mut().enumerate() { let i = i + start; - *product *= &(self.compressed_input_expression[i] + &*beta); - *product *= &(self.compressed_table_expression[i] + &*gamma); + *product *= &(self.compressed_input_expression[i] + *beta); + *product *= &(self.compressed_table_expression[i] + *gamma); } }); @@ -276,7 +276,7 @@ impl Permuted { input_term += &(*beta); table_term += &(*gamma); - right *= &(input_term * &table_term); + right *= &(input_term * table_term); assert_eq!(left, right); } diff --git a/backend/src/plonk/lookup/verifier.rs b/backend/src/plonk/lookup/verifier.rs index 8639077a..b394d398 100644 --- a/backend/src/plonk/lookup/verifier.rs +++ b/backend/src/plonk/lookup/verifier.rs @@ -109,8 +109,8 @@ impl Evaluated { // z(\omega X) (a'(X) + \beta) (s'(X) + \gamma) // - z(X) (\theta^{m-1} a_0(X) + ... + a_{m-1}(X) + \beta) (\theta^{m-1} s_0(X) + ... + s_{m-1}(X) + \gamma) let left = self.product_next_eval - * &(self.permuted_input_eval + &*beta) - * &(self.permuted_table_eval + &*gamma); + * (self.permuted_input_eval + *beta) + * (self.permuted_table_eval + *gamma); let compress_expressions = |expressions: &[Expression]| { expressions @@ -124,28 +124,28 @@ impl Evaluated { &|query| instance_evals[query.index.unwrap()], &|challenge| challenges[challenge.index()], &|a| -a, - &|a, b| a + &b, - &|a, b| a * &b, - &|a, scalar| a * &scalar, + &|a, b| a + b, + &|a, b| a * b, + &|a, scalar| a * scalar, ) }) - .fold(C::Scalar::ZERO, |acc, eval| acc * &*theta + &eval) + .fold(C::Scalar::ZERO, |acc, eval| acc * *theta + eval) }; let right = self.product_eval - * &(compress_expressions(&argument.input_expressions) + &*beta) - * &(compress_expressions(&argument.table_expressions) + &*gamma); + * (compress_expressions(&argument.input_expressions) + *beta) + * (compress_expressions(&argument.table_expressions) + *gamma); - (left - &right) * &active_rows + (left - right) * active_rows }; std::iter::empty() .chain( // l_0(X) * (1 - z(X)) = 0 - Some(l_0 * &(C::Scalar::ONE - &self.product_eval)), + Some(l_0 * (C::Scalar::ONE - self.product_eval)), ) .chain( // l_last(X) * (z(X)^2 - z(X)) = 0 - Some(l_last * &(self.product_eval.square() - &self.product_eval)), + Some(l_last * (self.product_eval.square() - self.product_eval)), ) .chain( // (1 - (l_last(X) + l_blind(X))) * ( @@ -156,13 +156,13 @@ impl Evaluated { ) .chain(Some( // l_0(X) * (a'(X) - s'(X)) = 0 - l_0 * &(self.permuted_input_eval - &self.permuted_table_eval), + l_0 * (self.permuted_input_eval - self.permuted_table_eval), )) .chain(Some( // (1 - (l_last(X) + l_blind(X))) * (a′(X) − s′(X))⋅(a′(X) − a′(\omega^{-1} X)) = 0 - (self.permuted_input_eval - &self.permuted_table_eval) - * &(self.permuted_input_eval - &self.permuted_input_inv_eval) - * &active_rows, + (self.permuted_input_eval - self.permuted_table_eval) + * (self.permuted_input_eval - self.permuted_input_inv_eval) + * active_rows, )) } diff --git a/backend/src/plonk/permutation/keygen.rs b/backend/src/plonk/permutation/keygen.rs index a22c87f0..f85f343c 100644 --- a/backend/src/plonk/permutation/keygen.rs +++ b/backend/src/plonk/permutation/keygen.rs @@ -13,13 +13,18 @@ use crate::{ use halo2_middleware::circuit::{Any, ColumnMid}; use halo2_middleware::permutation::{ArgumentV2, AssemblyMid}; -#[cfg(feature = "thread-safe-region")] +// NOTE: Temporarily disabled thread-safe-region feature. Regions are a frontend concept, so the +// thread-safe support for them should be only in the frontend package. + +// #[cfg(feature = "thread-safe-region")] use crate::multicore::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; +/* #[cfg(feature = "thread-safe-region")] use std::collections::{BTreeSet, HashMap}; +*/ -#[cfg(not(feature = "thread-safe-region"))] +// #[cfg(not(feature = "thread-safe-region"))] /// Struct that accumulates all the necessary data in order to construct the permutation argument. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Assembly { @@ -33,7 +38,7 @@ pub struct Assembly { sizes: Vec>, } -#[cfg(not(feature = "thread-safe-region"))] +// #[cfg(not(feature = "thread-safe-region"))] impl Assembly { pub(crate) fn new_from_assembly_mid( n: usize, @@ -143,12 +148,13 @@ impl Assembly { } } +/* #[cfg(feature = "thread-safe-region")] /// Struct that accumulates all the necessary data in order to construct the permutation argument. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Assembly { /// Columns that participate on the copy permutation argument. - columns: Vec>, + columns: Vec, /// Mapping of the actual copies done. cycles: Vec>, /// Mapping of the actual copies done. @@ -165,10 +171,10 @@ pub struct Assembly { impl Assembly { pub(crate) fn new_from_assembly_mid( n: usize, - p: &Argument, + p: &ArgumentV2, a: &AssemblyMid, ) -> Result { - let mut assembly = Self::new(n, p); + let mut assembly = Self::new(n, &p.clone().into()); for copy in &a.copies { assembly.copy(copy.0.column, copy.0.row, copy.1.column, copy.1.row)?; } @@ -176,21 +182,27 @@ impl Assembly { } pub(crate) fn new(n: usize, p: &Argument) -> Self { + // Initialize the copy vector to keep track of copy constraints in all + // the permutation arguments. + let mut columns = vec![]; + for i in 0..p.columns.len() { + // Computes [(i, 0), (i, 1), ..., (i, n - 1)] + columns.push((0..n).map(|j| (i, j)).collect()); + } + Assembly { - columns: p.columns.clone(), - cycles: Vec::with_capacity(n), - ordered_cycles: Vec::with_capacity(n), - aux: HashMap::new(), - col_len: n, - num_cols: p.columns.len(), + columns: p.columns.clone().into_iter().map(|c| c.into()).collect(), + mapping: columns.clone(), + aux: columns, + sizes: vec![vec![1usize; n]; p.columns.len()], } } pub(crate) fn copy( &mut self, - left_column: ColumnMid, + left_column: ColumnMid, left_row: usize, - right_column: ColumnMid, + right_column: ColumnMid, right_row: usize, ) -> Result<(), Error> { let left_column = self @@ -316,7 +328,7 @@ impl Assembly { } /// Returns columns that participate in the permutation argument. - pub fn columns(&self) -> &[ColumnMid] { + pub fn columns(&self) -> &[ColumnMid] { &self.columns } @@ -331,6 +343,7 @@ impl Assembly { }) } } +*/ pub(crate) fn build_pk<'params, C: CurveAffine, P: Params<'params, C>>( params: &P, diff --git a/backend/src/plonk/permutation/prover.rs b/backend/src/plonk/permutation/prover.rs index 317286b6..81cdddf4 100644 --- a/backend/src/plonk/permutation/prover.rs +++ b/backend/src/plonk/permutation/prover.rs @@ -110,7 +110,7 @@ pub(in crate::plonk) fn permutation_commit< .zip(values[column.index()][start..].iter()) .zip(permuted_column_values[start..].iter()) { - *modified_values *= &(*beta * permuted_value + &*gamma + value); + *modified_values *= *beta * permuted_value + *gamma + value; } }); } @@ -128,13 +128,13 @@ pub(in crate::plonk) fn permutation_commit< Any::Instance => instance, }; parallelize(&mut modified_values, |modified_values, start| { - let mut deltaomega = deltaomega * &omega.pow_vartime([start as u64, 0, 0, 0]); + let mut deltaomega = deltaomega * omega.pow_vartime([start as u64, 0, 0, 0]); for (modified_values, value) in modified_values .iter_mut() .zip(values[column.index()][start..].iter()) { // Multiply by p_j(\omega^i) + \delta^j \omega^i \beta - *modified_values *= &(deltaomega * &*beta + &*gamma + value); + *modified_values *= deltaomega * *beta + *gamma + value; deltaomega *= ω } }); diff --git a/backend/src/plonk/permutation/verifier.rs b/backend/src/plonk/permutation/verifier.rs index 9fa98ddc..e0fe5439 100644 --- a/backend/src/plonk/permutation/verifier.rs +++ b/backend/src/plonk/permutation/verifier.rs @@ -123,13 +123,13 @@ impl Evaluated { .chain( self.sets .first() - .map(|first_set| l_0 * &(C::Scalar::ONE - &first_set.permutation_product_eval)), + .map(|first_set| l_0 * (C::Scalar::ONE - first_set.permutation_product_eval)), ) // Enforce only for the last set. // l_last(X) * (z_l(X)^2 - z_l(X)) = 0 .chain(self.sets.last().map(|last_set| { - (last_set.permutation_product_eval.square() - &last_set.permutation_product_eval) - * &l_last + (last_set.permutation_product_eval.square() - last_set.permutation_product_eval) + * l_last })) // Except for the first set, enforce. // l_0(X) * (z_i(X) - z_{i-1}(\omega^(last) X)) = 0 @@ -144,7 +144,7 @@ impl Evaluated { last_set.permutation_product_last_eval.unwrap(), ) }) - .map(move |(set, prev_last)| (set - &prev_last) * &l_0), + .map(move |(set, prev_last)| (set - prev_last) * l_0), ) // And for all the sets we enforce: // (1 - (l_last(X) + l_blind(X))) * ( @@ -175,12 +175,12 @@ impl Evaluated { }) .zip(permutation_evals.iter()) { - left *= &(eval + &(*beta * permutation_eval) + &*gamma); + left *= eval + (*beta * permutation_eval) + *gamma; } let mut right = set.permutation_product_eval; - let mut current_delta = (*beta * &*x) - * &(::DELTA + let mut current_delta = (*beta * *x) + * (::DELTA .pow_vartime([(chunk_index * chunk_len) as u64])); for eval in columns.iter().map(|&column| match column.column_type() { Any::Advice(_) => { @@ -193,11 +193,11 @@ impl Evaluated { instance_evals[vk.cs.get_any_query_index(column, Rotation::cur())] } }) { - right *= &(eval + ¤t_delta + &*gamma); + right *= eval + current_delta + *gamma; current_delta *= &C::Scalar::DELTA; } - (left - &right) * (C::Scalar::ONE - &(l_last + &l_blind)) + (left - right) * (C::Scalar::ONE - (l_last + l_blind)) }), ) } diff --git a/backend/src/plonk/prover.rs b/backend/src/plonk/prover.rs index 7ebb022e..c685945a 100644 --- a/backend/src/plonk/prover.rs +++ b/backend/src/plonk/prover.rs @@ -258,6 +258,7 @@ impl< } /// Commit the `witness` at `phase` and return the challenges after `phase`. + #[allow(clippy::type_complexity)] pub fn commit_phase( &mut self, phase: u8, @@ -454,7 +455,7 @@ impl< .iter() .map(|lookup| { lookup_commit_permuted( - &lookup, + lookup, pk, params, domain, @@ -527,7 +528,7 @@ impl< .iter() .map(|shuffle| { shuffle_commit_product( - &shuffle, + shuffle, pk, params, domain, diff --git a/backend/src/plonk/shuffle/verifier.rs b/backend/src/plonk/shuffle/verifier.rs index 9bbb122d..e989de2c 100644 --- a/backend/src/plonk/shuffle/verifier.rs +++ b/backend/src/plonk/shuffle/verifier.rs @@ -81,31 +81,31 @@ impl Evaluated { &|query| instance_evals[query.index.unwrap()], &|challenge| challenges[challenge.index()], &|a| -a, - &|a, b| a + &b, - &|a, b| a * &b, - &|a, scalar| a * &scalar, + &|a, b| a + b, + &|a, b| a * b, + &|a, scalar| a * scalar, ) }) - .fold(C::Scalar::ZERO, |acc, eval| acc * &*theta + &eval) + .fold(C::Scalar::ZERO, |acc, eval| acc * *theta + eval) }; // z(\omega X) (s(X) + \gamma) let left = self.product_next_eval - * &(compress_expressions(&argument.shuffle_expressions) + &*gamma); + * (compress_expressions(&argument.shuffle_expressions) + *gamma); // z(X) (a(X) + \gamma) let right = - self.product_eval * &(compress_expressions(&argument.input_expressions) + &*gamma); + self.product_eval * (compress_expressions(&argument.input_expressions) + *gamma); - (left - &right) * &active_rows + (left - right) * active_rows }; std::iter::empty() .chain( // l_0(X) * (1 - z'(X)) = 0 - Some(l_0 * &(C::Scalar::ONE - &self.product_eval)), + Some(l_0 * (C::Scalar::ONE - self.product_eval)), ) .chain( // l_last(X) * (z(X)^2 - z(X)) = 0 - Some(l_last * &(self.product_eval.square() - &self.product_eval)), + Some(l_last * (self.product_eval.square() - self.product_eval)), ) .chain( // (1 - (l_last(X) + l_blind(X))) * ( z(\omega X) (s(X) + \gamma) - z(X) (a(X) + \gamma)) diff --git a/backend/src/plonk/vanishing/verifier.rs b/backend/src/plonk/vanishing/verifier.rs index d570a93b..93de57b0 100644 --- a/backend/src/plonk/vanishing/verifier.rs +++ b/backend/src/plonk/vanishing/verifier.rs @@ -95,7 +95,7 @@ impl PartiallyEvaluated { y: ChallengeY, xn: C::Scalar, ) -> Evaluated { - let expected_h_eval = expressions.fold(C::Scalar::ZERO, |h_eval, v| h_eval * &*y + &v); + let expected_h_eval = expressions.fold(C::Scalar::ZERO, |h_eval, v| h_eval * *y + v); let expected_h_eval = expected_h_eval * ((xn - C::Scalar::ONE).invert().unwrap()); let h_commitment = diff --git a/backend/src/plonk/verifier.rs b/backend/src/plonk/verifier.rs index 02b3bae8..f86f0134 100644 --- a/backend/src/plonk/verifier.rs +++ b/backend/src/plonk/verifier.rs @@ -327,9 +327,9 @@ where &|query| instance_evals[query.index.unwrap()], &|challenge| challenges[challenge.index()], &|a| -a, - &|a, b| a + &b, - &|a, b| a * &b, - &|a, scalar| a * &scalar, + &|a, b| a + b, + &|a, b| a * b, + &|a, scalar| a * scalar, ) }) })) diff --git a/common/src/plonk/circuit.rs b/common/src/plonk/circuit.rs index 0150468d..26e4a1b5 100644 --- a/common/src/plonk/circuit.rs +++ b/common/src/plonk/circuit.rs @@ -29,11 +29,11 @@ pub struct Column { pub column_type: C, } -impl Into for Column { - fn into(self) -> metadata::Column { +impl From> for metadata::Column { + fn from(val: Column) -> Self { metadata::Column { - index: self.index(), - column_type: *self.column_type(), + index: val.index(), + column_type: *val.column_type(), } } } @@ -126,11 +126,11 @@ impl From for Column { } } -impl Into for Column { - fn into(self) -> ColumnMid { +impl From> for ColumnMid { + fn from(val: Column) -> Self { ColumnMid { - index: self.index(), - column_type: *self.column_type(), + index: val.index(), + column_type: *val.column_type(), } } } @@ -469,11 +469,11 @@ impl Challenge { } } -impl Into for Challenge { - fn into(self) -> ChallengeMid { +impl From for ChallengeMid { + fn from(val: Challenge) -> Self { ChallengeMid { - index: self.index, - phase: self.phase, + index: val.index, + phase: val.phase, } } } @@ -699,9 +699,9 @@ pub enum Expression { Scaled(Box>, F), } -impl Into> for Expression { - fn into(self) -> ExpressionMid { - match self { +impl From> for ExpressionMid { + fn from(val: Expression) -> Self { + match val { Expression::Constant(c) => ExpressionMid::Constant(c), Expression::Selector(_) => unreachable!(), Expression::Fixed(FixedQuery { @@ -1538,7 +1538,7 @@ impl QueriesMap { rotation: query.rotation, }) } - ExpressionMid::Challenge(c) => Expression::Challenge(c.clone().into()), + ExpressionMid::Challenge(c) => Expression::Challenge((*c).into()), ExpressionMid::Negated(e) => Expression::Negated(Box::new(self.as_expression(e))), ExpressionMid::Sum(lhs, rhs) => Expression::Sum( Box::new(self.as_expression(lhs)), @@ -1566,13 +1566,13 @@ impl From> for ConstraintSystemV2Backend { gates: cs .gates .into_iter() - .map(|mut g| { + .flat_map(|mut g| { let constraint_names = std::mem::take(&mut g.constraint_names); let gate_name = g.name.clone(); g.polys.into_iter().enumerate().map(move |(i, e)| { let name = match constraint_names[i].as_str() { "" => gate_name.clone(), - constraint_name => format!("{}:{}", gate_name, constraint_name), + constraint_name => format!("{gate_name}:{constraint_name}"), }; GateV2Backend { name, @@ -1580,7 +1580,6 @@ impl From> for ConstraintSystemV2Backend { } }) }) - .flatten() .collect(), permutation: halo2_middleware::permutation::ArgumentV2 { columns: cs @@ -1759,6 +1758,7 @@ fn cs2_collect_queries_shuffles( /// Collect all queries used in the expressions of gates, lookups and shuffles. Map the /// expressions of gates, lookups and shuffles into equivalent ones with indexed query /// references. +#[allow(clippy::type_complexity)] pub fn collect_queries( cs2: &ConstraintSystemV2Backend, ) -> ( @@ -1972,7 +1972,7 @@ impl Default for ConstraintSystem { advice_queries: Vec::new(), num_advice_queries: Vec::new(), instance_queries: Vec::new(), - permutation: permutation::Argument::new(), + permutation: permutation::Argument::default(), lookups: Vec::new(), shuffles: Vec::new(), general_column_annotations: HashMap::new(), diff --git a/common/src/plonk/permutation.rs b/common/src/plonk/permutation.rs index ffe84356..cd7fc611 100644 --- a/common/src/plonk/permutation.rs +++ b/common/src/plonk/permutation.rs @@ -5,7 +5,7 @@ use halo2_middleware::circuit::Any; use halo2_middleware::permutation::{ArgumentV2, Cell}; /// A permutation argument. -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub struct Argument { /// A sequence of columns involved in the argument. pub columns: Vec>, @@ -20,10 +20,6 @@ impl From for Argument { } impl Argument { - pub fn new() -> Self { - Argument { columns: vec![] } - } - /// Returns the minimum circuit degree required by the permutation argument. /// The argument may use larger degree gates depending on the actual /// circuit's degree and how many columns are involved in the permutation. diff --git a/common/src/poly/kzg/msm.rs b/common/src/poly/kzg/msm.rs index fa8359f9..b45dfe2a 100644 --- a/common/src/poly/kzg/msm.rs +++ b/common/src/poly/kzg/msm.rs @@ -103,17 +103,23 @@ where projectives_msms: Vec>, } +impl Default for PreMSM +where + E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, + E::G1: CurveExt, +{ + fn default() -> Self { + PreMSM { + projectives_msms: vec![], + } + } +} + impl PreMSM where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub fn new() -> Self { - PreMSM { - projectives_msms: vec![], - } - } - pub fn normalize(self) -> MSMKZG { let (scalars, bases) = self .projectives_msms diff --git a/common/src/poly/kzg/multiopen/shplonk/verifier.rs b/common/src/poly/kzg/multiopen/shplonk/verifier.rs index f5a4d824..27e33c62 100644 --- a/common/src/poly/kzg/multiopen/shplonk/verifier.rs +++ b/common/src/poly/kzg/multiopen/shplonk/verifier.rs @@ -72,7 +72,7 @@ where let h2 = transcript.read_point().map_err(|_| Error::SamplingError)?; let (mut z_0_diff_inverse, mut z_0) = (E::Fr::ZERO, E::Fr::ZERO); - let (mut outer_msm, mut r_outer_acc) = (PreMSM::::new(), E::Fr::ZERO); + let (mut outer_msm, mut r_outer_acc) = (PreMSM::::default(), E::Fr::ZERO); for (i, (rotation_set, power_of_v)) in rotation_sets.iter().zip(powers(*v)).enumerate() { let diffs: Vec = super_point_set .iter() diff --git a/frontend/src/circuit.rs b/frontend/src/circuit.rs index 582ec394..c4288f56 100644 --- a/frontend/src/circuit.rs +++ b/frontend/src/circuit.rs @@ -28,6 +28,7 @@ pub use halo2_common::circuit::{layouter, Layouter, Value}; /// copy constraints assignments. The output of this function can then be used for the key /// generation, and proof generation. /// If `compress_selectors` is true, multiple selector columns may be multiplexed. +#[allow(clippy::type_complexity)] pub fn compile_circuit>( k: u32, circuit: &ConcreteCircuit, diff --git a/frontend/src/dev.rs b/frontend/src/dev.rs index 23d56c3f..2dd615cc 100644 --- a/frontend/src/dev.rs +++ b/frontend/src/dev.rs @@ -720,8 +720,8 @@ impl + Ord> MockProver { v })); - #[cfg(feature = "thread-safe-region")] - prover.permutation.build_ordered_mapping(); + // #[cfg(feature = "thread-safe-region")] + // prover.permutation.build_ordered_mapping(); Ok(prover) } diff --git a/frontend/src/dev/cost_model.rs b/frontend/src/dev/cost_model.rs index 86ce0380..ec0bd437 100644 --- a/frontend/src/dev/cost_model.rs +++ b/frontend/src/dev/cost_model.rs @@ -4,7 +4,7 @@ use std::collections::HashSet; use std::{iter, num::ParseIntError, str::FromStr}; -use crate::plonk::Circuit; +use halo2_common::plonk::circuit::Circuit; use halo2_middleware::ff::{Field, FromUniformBytes}; use serde::Deserialize; use serde_derive::Serialize; diff --git a/frontend/src/dev/graph.rs b/frontend/src/dev/graph.rs index 381cd6bd..ed3523c5 100644 --- a/frontend/src/dev/graph.rs +++ b/frontend/src/dev/graph.rs @@ -1,13 +1,13 @@ +use halo2_common::plonk::{ + circuit::{Circuit, Column}, + Assignment, Challenge, ConstraintSystem, Error, FloorPlanner, Selector, +}; +use halo2_middleware::circuit::{Advice, Any, Fixed, Instance}; use halo2_middleware::ff::Field; +use halo2_middleware::plonk::Assigned; use tabbycat::{AttrList, Edge, GraphBuilder, GraphType, Identity, StmtList}; -use crate::{ - circuit::Value, - plonk::{ - Advice, Any, Assigned, Assignment, Challenge, Circuit, Column, ConstraintSystem, Error, - Fixed, FloorPlanner, Instance, Selector, - }, -}; +use crate::circuit::Value; pub mod layout; @@ -154,7 +154,7 @@ impl Assignment for Graph { _: usize, _: Column, _: usize, - ) -> Result<(), crate::plonk::Error> { + ) -> Result<(), halo2_common::plonk::Error> { // Do nothing; we don't care about permutations in this context. Ok(()) } diff --git a/frontend/src/dev/graph/layout.rs b/frontend/src/dev/graph/layout.rs index 4777e05f..829479ad 100644 --- a/frontend/src/dev/graph/layout.rs +++ b/frontend/src/dev/graph/layout.rs @@ -6,11 +6,9 @@ use plotters::{ use std::collections::HashSet; use std::ops::Range; -use crate::{ - circuit::layouter::RegionColumn, - dev::cost::Layout, - plonk::{Any, Circuit, Column, ConstraintSystem, FloorPlanner}, -}; +use crate::{circuit::layouter::RegionColumn, dev::cost::Layout}; +use halo2_common::plonk::{circuit::Column, Circuit, ConstraintSystem, FloorPlanner}; +use halo2_middleware::circuit::Any; /// Graphical renderer for circuit layouts. /// diff --git a/halo2_proofs/Cargo.toml b/halo2_proofs/Cargo.toml index df016059..0fe79b99 100644 --- a/halo2_proofs/Cargo.toml +++ b/halo2_proofs/Cargo.toml @@ -68,6 +68,7 @@ gumdrop = "0.8" proptest = "1" dhat = "0.3.2" serde_json = "1" +plotters = { version = "0.3.0", features = ["bitmap_backend", "bitmap_encoder", "ttf"] } [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] getrandom = { version = "0.2", features = ["js"] } diff --git a/halo2_proofs/src/lib.rs b/halo2_proofs/src/lib.rs index 78ecf3d4..31c9ca41 100644 --- a/halo2_proofs/src/lib.rs +++ b/halo2_proofs/src/lib.rs @@ -30,6 +30,12 @@ pub mod arithmetic { /// Tools for developing circuits. pub mod dev { pub use halo2_frontend::dev::{metadata, FailureLocation, MockProver, VerifyFailure}; + + #[cfg(feature = "cost-estimator")] + pub use halo2_frontend::dev::cost_model; + + #[cfg(feature = "dev-graph")] + pub use halo2_frontend::dev::{circuit_dot_graph, CircuitLayout}; } /// Contains utilities for performing arithmetic over univariate polynomials in /// various forms, including computing commitments to them and provably opening diff --git a/halo2_proofs/tests/frontend_backend_split.rs b/halo2_proofs/tests/frontend_backend_split.rs index c647fa2e..ffc184a4 100644 --- a/halo2_proofs/tests/frontend_backend_split.rs +++ b/halo2_proofs/tests/frontend_backend_split.rs @@ -65,6 +65,7 @@ struct MyCircuitConfig { } impl MyCircuitConfig { + #[allow(clippy::type_complexity)] fn assign_gate>( &self, region: &mut Region<'_, F>, @@ -516,7 +517,7 @@ fn test_mycircuit_full_legacy() { create_proof::, ProverSHPLONK<'_, Bn256>, _, _, _, _>( ¶ms, &pk, - &[circuit.clone()], + &[circuit], &[instances_slice], &mut rng, &mut transcript, @@ -584,7 +585,7 @@ fn test_mycircuit_full_split() { .unwrap(); let mut challenges = HashMap::new(); for phase in 0..cs.phases().count() { - println!("phase {}", phase); + println!("phase {phase}"); let witness = witness_calc.calc(phase as u8, &challenges).unwrap(); challenges = prover.commit_phase(phase as u8, witness).unwrap(); } diff --git a/middleware/src/circuit.rs b/middleware/src/circuit.rs index 004e86d4..b5676e61 100644 --- a/middleware/src/circuit.rs +++ b/middleware/src/circuit.rs @@ -190,17 +190,11 @@ pub struct ColumnMid { } /// An advice column -#[derive(Clone, Copy, Eq, PartialEq, Hash)] +#[derive(Default, Clone, Copy, Eq, PartialEq, Hash)] pub struct Advice { pub phase: u8, } -impl Default for Advice { - fn default() -> Advice { - Advice { phase: 0 } - } -} - impl Advice { /// Returns `Advice` in given `Phase` pub fn new(phase: u8) -> Advice {