From 4f1cccc330475f6929835bdb950458739895cf40 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:35:42 +0800 Subject: [PATCH 01/15] fix: review & correct the pub types/fields in "halo2_frontend" crate --- halo2_frontend/src/dev/cost.rs | 34 +++++++++++++++--------------- halo2_frontend/src/dev/metadata.rs | 2 +- halo2_frontend/src/dev/util.rs | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/halo2_frontend/src/dev/cost.rs b/halo2_frontend/src/dev/cost.rs index 12bf6f02f2..793871dbfe 100644 --- a/halo2_frontend/src/dev/cost.rs +++ b/halo2_frontend/src/dev/cost.rs @@ -58,44 +58,44 @@ pub struct CircuitCost> { /// Region implementation used by Layout #[allow(dead_code)] #[derive(Debug)] -pub struct LayoutRegion { +pub(crate) struct LayoutRegion { /// The name of the region. Not required to be unique. - pub name: String, + pub(crate) name: String, /// The columns used by this region. - pub columns: HashSet, + pub(crate) columns: HashSet, /// The row that this region starts on, if known. - pub offset: Option, + pub(crate) offset: Option, /// The number of rows that this region takes up. - pub rows: usize, + pub(crate) rows: usize, /// The cells assigned in this region. - pub cells: Vec<(RegionColumn, usize)>, + pub(crate) cells: Vec<(RegionColumn, usize)>, } /// Cost and graphing layouter #[derive(Default, Debug)] -pub struct Layout { +pub(crate) struct Layout { /// k = 1 << n - pub k: u32, + pub(crate) k: u32, /// Regions of the layout - pub regions: Vec, + pub(crate) regions: Vec, current_region: Option, /// Total row count - pub total_rows: usize, + pub(crate) total_rows: usize, /// Total advice rows - pub total_advice_rows: usize, + pub(crate) total_advice_rows: usize, /// Total fixed rows - pub total_fixed_rows: usize, + pub(crate) total_fixed_rows: usize, /// Any cells assigned outside of a region. - pub loose_cells: Vec<(RegionColumn, usize)>, + pub(crate) loose_cells: Vec<(RegionColumn, usize)>, /// Pairs of cells between which we have equality constraints. - pub equality: Vec<(Column, usize, Column, usize)>, + pub(crate) equality: Vec<(Column, usize, Column, usize)>, /// Selector assignments used for optimization pass - pub selectors: Vec>, + pub(crate) selectors: Vec>, } impl Layout { /// Creates a empty layout - pub fn new(k: u32, n: usize, num_selectors: usize) -> Self { + pub(crate) fn new(k: u32, n: usize, num_selectors: usize) -> Self { Layout { k, regions: vec![], @@ -113,7 +113,7 @@ impl Layout { } /// Update layout metadata - pub fn update(&mut self, column: RegionColumn, row: usize) { + pub(crate) fn update(&mut self, column: RegionColumn, row: usize) { self.total_rows = cmp::max(self.total_rows, row + 1); if let RegionColumn::Column(col) = column { diff --git a/halo2_frontend/src/dev/metadata.rs b/halo2_frontend/src/dev/metadata.rs index 66e4b49bd3..d3cf96abb7 100644 --- a/halo2_frontend/src/dev/metadata.rs +++ b/halo2_frontend/src/dev/metadata.rs @@ -207,7 +207,7 @@ impl Region { /// This function will return `None` if: /// - There's no annotation map generated for this `Region`. /// - There's no entry on the annotation map corresponding to the metadata provided. - pub fn get_column_annotation(&self, metadata: ColumnMetadata) -> Option { + pub(crate) fn get_column_annotation(&self, metadata: ColumnMetadata) -> Option { self.column_annotations .as_ref() .and_then(|map| map.get(&metadata).cloned()) diff --git a/halo2_frontend/src/dev/util.rs b/halo2_frontend/src/dev/util.rs index c3f3d7e494..ac7017e833 100644 --- a/halo2_frontend/src/dev/util.rs +++ b/halo2_frontend/src/dev/util.rs @@ -8,7 +8,7 @@ use halo2_common::plonk::{ use halo2_middleware::circuit::{Advice, Any, ColumnType}; use halo2_middleware::poly::Rotation; -pub struct AnyQuery { +pub(crate) struct AnyQuery { /// Query index pub index: Option, /// Column type From b38812df5d7667d0692c47958c636db74fbff03f Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:36:00 +0800 Subject: [PATCH 02/15] fix: review & correct the pub types/fields in "halo2_common" crate --- .../src/circuit/floor_planner/v1/strategy.rs | 8 ++++---- halo2_common/src/circuit/table_layouter.rs | 2 +- halo2_common/src/plonk/circuit.rs | 12 ++++++------ halo2_common/src/plonk/lookup.rs | 3 ++- halo2_common/src/plonk/permutation.rs | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/halo2_common/src/circuit/floor_planner/v1/strategy.rs b/halo2_common/src/circuit/floor_planner/v1/strategy.rs index c711b7cec5..ae5fe8acbe 100644 --- a/halo2_common/src/circuit/floor_planner/v1/strategy.rs +++ b/halo2_common/src/circuit/floor_planner/v1/strategy.rs @@ -30,7 +30,7 @@ impl PartialOrd for AllocatedRegion { } /// An area of empty space within a column. -pub struct EmptySpace { +pub(crate) struct EmptySpace { // The starting position (inclusive) of the empty space. start: usize, // The ending position (exclusive) of the empty space, or `None` if unbounded. @@ -38,7 +38,7 @@ pub struct EmptySpace { } impl EmptySpace { - pub fn range(&self) -> Option> { + pub(crate) fn range(&self) -> Option> { self.end.map(|end| self.start..end) } } @@ -51,7 +51,7 @@ pub struct Allocations(BTreeSet); impl Allocations { /// Returns the row that forms the unbounded unallocated interval [row, None). - pub fn unbounded_interval_start(&self) -> usize { + pub(crate) fn unbounded_interval_start(&self) -> usize { self.0 .iter() .last() @@ -62,7 +62,7 @@ impl Allocations { /// Return all the *unallocated* nonempty intervals intersecting [start, end). /// /// `end = None` represents an unbounded end. - pub fn free_intervals( + pub(crate) fn free_intervals( &self, start: usize, end: Option, diff --git a/halo2_common/src/circuit/table_layouter.rs b/halo2_common/src/circuit/table_layouter.rs index b3087c9d60..8de7c0e221 100644 --- a/halo2_common/src/circuit/table_layouter.rs +++ b/halo2_common/src/circuit/table_layouter.rs @@ -118,7 +118,7 @@ impl<'r, 'a, F: Field, CS: Assignment + 'a> TableLayouter } } -pub fn compute_table_lengths( +pub(crate) fn compute_table_lengths( default_and_assigned: &HashMap, Vec)>, ) -> Result { let column_lengths: Result, Error> = default_and_assigned diff --git a/halo2_common/src/plonk/circuit.rs b/halo2_common/src/plonk/circuit.rs index 69c09ca9b5..a0d0304126 100644 --- a/halo2_common/src/plonk/circuit.rs +++ b/halo2_common/src/plonk/circuit.rs @@ -449,7 +449,7 @@ impl TableColumn { #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub struct Challenge { pub index: usize, - pub phase: u8, + pub(crate) phase: u8, } impl Challenge { @@ -1298,7 +1298,7 @@ impl Product for Expression { /// Represents an index into a vector where each entry corresponds to a distinct /// point that polynomials are queried at. #[derive(Copy, Clone, Debug)] -pub struct PointIndex(pub usize); +pub(crate) struct PointIndex(pub usize); /// A "virtual cell" is a PLONK cell that has been queried at a particular relative offset /// within a custom gate. @@ -2054,7 +2054,7 @@ impl ConstraintSystem { index } - pub fn query_advice_index(&mut self, column: Column, at: Rotation) -> usize { + pub(crate) fn query_advice_index(&mut self, column: Column, at: Rotation) -> usize { // Return existing query, if it exists for (index, advice_query) in self.advice_queries.iter().enumerate() { if advice_query == &(column, at) { @@ -2097,7 +2097,7 @@ impl ConstraintSystem { } } - pub fn get_advice_query_index(&self, column: Column, at: Rotation) -> usize { + pub(crate) fn get_advice_query_index(&self, column: Column, at: Rotation) -> usize { for (index, advice_query) in self.advice_queries.iter().enumerate() { if advice_query == &(column, at) { return index; @@ -2107,7 +2107,7 @@ impl ConstraintSystem { panic!("get_advice_query_index called for non-existent query"); } - pub fn get_fixed_query_index(&self, column: Column, at: Rotation) -> usize { + pub(crate) fn get_fixed_query_index(&self, column: Column, at: Rotation) -> usize { for (index, fixed_query) in self.fixed_queries.iter().enumerate() { if fixed_query == &(column, at) { return index; @@ -2117,7 +2117,7 @@ impl ConstraintSystem { panic!("get_fixed_query_index called for non-existent query"); } - pub fn get_instance_query_index(&self, column: Column, at: Rotation) -> usize { + pub(crate) fn get_instance_query_index(&self, column: Column, at: Rotation) -> usize { for (index, instance_query) in self.instance_queries.iter().enumerate() { if instance_query == &(column, at) { return index; diff --git a/halo2_common/src/plonk/lookup.rs b/halo2_common/src/plonk/lookup.rs index 3116b79f5e..2993029b56 100644 --- a/halo2_common/src/plonk/lookup.rs +++ b/halo2_common/src/plonk/lookup.rs @@ -3,6 +3,7 @@ use halo2_middleware::ff::Field; use std::fmt::{self, Debug}; /// Expressions involved in a lookup argument, with a name as metadata. +/// TODO: possible to move to "halo2_backend", if moved, pub(crate) fields. #[derive(Clone)] pub struct Argument { pub name: String, @@ -32,7 +33,7 @@ impl Argument { } } - pub fn required_degree(&self) -> usize { + pub(crate) fn required_degree(&self) -> usize { assert_eq!(self.input_expressions.len(), self.table_expressions.len()); // The first value in the permutation poly should be one. diff --git a/halo2_common/src/plonk/permutation.rs b/halo2_common/src/plonk/permutation.rs index ed5704ff33..ba307bd2f8 100644 --- a/halo2_common/src/plonk/permutation.rs +++ b/halo2_common/src/plonk/permutation.rs @@ -23,7 +23,7 @@ impl Argument { /// 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. - pub fn required_degree(&self) -> usize { + pub(crate) fn required_degree(&self) -> usize { // degree 2: // l_0(X) * (1 - z(X)) = 0 // @@ -58,7 +58,7 @@ impl Argument { 3 } - pub fn add_column(&mut self, column: Column) { + pub(crate) fn add_column(&mut self, column: Column) { if !self.columns.contains(&column) { self.columns.push(column); } From 8661231167183d9a7d45c3e7da38c7a7b9b8c66f Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:36:47 +0800 Subject: [PATCH 03/15] fix: review & correct the pub types/fields in "halo2_backend" crate --- halo2_backend/src/helpers.rs | 6 +++--- halo2_backend/src/plonk.rs | 14 +++++++------- halo2_backend/src/plonk/lookup.rs | 4 ++-- halo2_backend/src/plonk/permutation.rs | 4 ++-- halo2_backend/src/plonk/permutation/prover.rs | 2 +- halo2_backend/src/plonk/permutation/verifier.rs | 8 ++++---- halo2_backend/src/plonk/shuffle.rs | 4 ++-- halo2_backend/src/plonk/shuffle/verifier.rs | 4 ++-- halo2_backend/src/poly.rs | 4 ++-- halo2_backend/src/poly/ipa/commitment.rs | 12 ++++++------ halo2_backend/src/poly/ipa/msm.rs | 2 +- halo2_backend/src/poly/ipa/multiopen.rs | 8 ++++---- halo2_backend/src/poly/ipa/multiopen/prover.rs | 2 +- halo2_backend/src/poly/ipa/strategy.rs | 8 ++++---- halo2_backend/src/poly/kzg/commitment.rs | 12 ++++++------ halo2_backend/src/poly/kzg/msm.rs | 16 ++++++++-------- halo2_backend/src/poly/kzg/strategy.rs | 10 +++++----- halo2_backend/src/poly/query.rs | 16 ++++++++-------- 18 files changed, 68 insertions(+), 68 deletions(-) diff --git a/halo2_backend/src/helpers.rs b/halo2_backend/src/helpers.rs index 4f2afda00c..25f1072832 100644 --- a/halo2_backend/src/helpers.rs +++ b/halo2_backend/src/helpers.rs @@ -6,7 +6,7 @@ use std::io; pub(crate) use halo2_common::helpers::{pack, unpack, CurveRead, SerdeCurveAffine}; /// Reads a vector of polynomials from buffer -pub fn read_polynomial_vec( +pub(crate) fn read_polynomial_vec( reader: &mut R, format: SerdeFormat, ) -> io::Result>> { @@ -20,7 +20,7 @@ pub fn read_polynomial_vec( } /// Writes a slice of polynomials to buffer -pub fn write_polynomial_slice( +pub(crate) fn write_polynomial_slice( slice: &[Polynomial], writer: &mut W, format: SerdeFormat, @@ -33,7 +33,7 @@ pub fn write_polynomial_slice( } /// Gets the total number of bytes of a slice of polynomials, assuming all polynomials are the same length -pub fn polynomial_slice_byte_length(slice: &[Polynomial]) -> usize { +pub(crate) fn polynomial_slice_byte_length(slice: &[Polynomial]) -> usize { let field_len = F::default().to_repr().as_ref().len(); 4 + slice.len() * (4 + field_len * slice.get(0).map(|poly| poly.len()).unwrap_or(0)) } diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index 9a170834cd..d25b1f8bfe 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -62,7 +62,7 @@ where /// - Otherwise: Writes an uncompressed curve element with coordinates in Montgomery form /// Writes a field element into raw bytes in its internal Montgomery representation, /// WITHOUT performing the expensive Montgomery reduction. - pub fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { + pub(crate) fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { // Version byte that will be checked on read. writer.write_all(&[VERSION])?; let k = &self.domain.k(); @@ -99,7 +99,7 @@ where /// Checks that field elements are less than modulus, and then checks that the point is on the curve. /// - `RawBytesUnchecked`: Reads an uncompressed curve element with coordinates in Montgomery form; /// does not perform any checks - pub fn read>( + pub(crate) fn read>( reader: &mut R, format: SerdeFormat, #[cfg(feature = "circuit-params")] params: ConcreteCircuit::Params, @@ -183,14 +183,14 @@ where } /// Writes a verifying key to a vector of bytes using [`Self::write`]. - pub fn to_bytes(&self, format: SerdeFormat) -> Vec { + pub(crate) fn to_bytes(&self, format: SerdeFormat) -> Vec { let mut bytes = Vec::::with_capacity(self.bytes_length(format)); Self::write(self, &mut bytes, format).expect("Writing to vector should not fail"); bytes } /// Reads a verification key from a slice of bytes using [`Self::read`]. - pub fn from_bytes>( + pub(crate) fn from_bytes>( mut bytes: &[u8], format: SerdeFormat, #[cfg(feature = "circuit-params")] params: ConcreteCircuit::Params, @@ -290,17 +290,17 @@ impl VerifyingKey { } /// Returns `VerifyingKey` of permutation - pub fn permutation(&self) -> &permutation::VerifyingKey { + pub(crate) fn permutation(&self) -> &permutation::VerifyingKey { &self.permutation } /// Returns `ConstraintSystem` - pub fn cs(&self) -> &ConstraintSystem { + pub(crate) fn cs(&self) -> &ConstraintSystem { &self.cs } /// Returns representative of this `VerifyingKey` in transcripts - pub fn transcript_repr(&self) -> C::Scalar { + pub(crate) fn transcript_repr(&self) -> C::Scalar { self.transcript_repr } } diff --git a/halo2_backend/src/plonk/lookup.rs b/halo2_backend/src/plonk/lookup.rs index f0691166ec..67abd8a614 100644 --- a/halo2_backend/src/plonk/lookup.rs +++ b/halo2_backend/src/plonk/lookup.rs @@ -1,4 +1,4 @@ -pub mod prover; -pub mod verifier; +pub(crate) mod prover; +pub(crate) mod verifier; pub use halo2_common::plonk::lookup::Argument; diff --git a/halo2_backend/src/plonk/permutation.rs b/halo2_backend/src/plonk/permutation.rs index 122236e74d..1dd0fe2e70 100644 --- a/halo2_backend/src/plonk/permutation.rs +++ b/halo2_backend/src/plonk/permutation.rs @@ -17,7 +17,7 @@ pub mod verifier; /// The verifying key for a single permutation argument. #[derive(Clone, Debug)] -pub struct VerifyingKey { +pub(crate) struct VerifyingKey { commitments: Vec, } @@ -61,7 +61,7 @@ impl VerifyingKey { /// The proving key for a single permutation argument. #[derive(Clone, Debug)] -pub struct ProvingKey { +pub(crate) struct ProvingKey { permutations: Vec>, polys: Vec>, pub(super) cosets: Vec>, diff --git a/halo2_backend/src/plonk/permutation/prover.rs b/halo2_backend/src/plonk/permutation/prover.rs index 4a1ec7d903..b4ccc1e35a 100644 --- a/halo2_backend/src/plonk/permutation/prover.rs +++ b/halo2_backend/src/plonk/permutation/prover.rs @@ -33,7 +33,7 @@ pub(crate) struct Committed { pub(crate) sets: Vec>, } -pub struct ConstructedSet { +pub(crate) struct ConstructedSet { permutation_product_poly: Polynomial, permutation_product_blind: Blind, } diff --git a/halo2_backend/src/plonk/permutation/verifier.rs b/halo2_backend/src/plonk/permutation/verifier.rs index f343b60632..21646f7b02 100644 --- a/halo2_backend/src/plonk/permutation/verifier.rs +++ b/halo2_backend/src/plonk/permutation/verifier.rs @@ -12,22 +12,22 @@ use halo2_common::plonk::{ChallengeBeta, ChallengeGamma, ChallengeX, Error}; use halo2_middleware::circuit::Any; use halo2_middleware::poly::Rotation; -pub struct Committed { +pub(crate) struct Committed { permutation_product_commitments: Vec, } -pub struct EvaluatedSet { +pub(crate) struct EvaluatedSet { permutation_product_commitment: C, permutation_product_eval: C::Scalar, permutation_product_next_eval: C::Scalar, permutation_product_last_eval: Option, } -pub struct CommonEvaluated { +pub(crate) struct CommonEvaluated { permutation_evals: Vec, } -pub struct Evaluated { +pub(crate) struct Evaluated { sets: Vec>, } diff --git a/halo2_backend/src/plonk/shuffle.rs b/halo2_backend/src/plonk/shuffle.rs index 4c48e5a7b6..87bb58b701 100644 --- a/halo2_backend/src/plonk/shuffle.rs +++ b/halo2_backend/src/plonk/shuffle.rs @@ -1,4 +1,4 @@ -pub mod prover; -pub mod verifier; +pub(crate) mod prover; +pub(crate) mod verifier; pub use halo2_common::plonk::shuffle::Argument; diff --git a/halo2_backend/src/plonk/shuffle/verifier.rs b/halo2_backend/src/plonk/shuffle/verifier.rs index dd32f3d6f2..96b374e751 100644 --- a/halo2_backend/src/plonk/shuffle/verifier.rs +++ b/halo2_backend/src/plonk/shuffle/verifier.rs @@ -11,11 +11,11 @@ use halo2_common::plonk::{ChallengeGamma, ChallengeTheta, ChallengeX, Error, Exp use halo2_middleware::ff::Field; use halo2_middleware::poly::Rotation; -pub struct Committed { +pub(crate) struct Committed { product_commitment: C, } -pub struct Evaluated { +pub(crate) struct Evaluated { committed: Committed, product_eval: C::Scalar, product_next_eval: C::Scalar, diff --git a/halo2_backend/src/poly.rs b/halo2_backend/src/poly.rs index 6e4befe581..756ceac483 100644 --- a/halo2_backend/src/poly.rs +++ b/halo2_backend/src/poly.rs @@ -172,7 +172,7 @@ impl Polynomial { impl Polynomial { /// Reads polynomial from buffer using `SerdePrimeField::read`. - pub fn read(reader: &mut R, format: SerdeFormat) -> io::Result { + pub(crate) fn read(reader: &mut R, format: SerdeFormat) -> io::Result { let mut poly_len = [0u8; 4]; reader.read_exact(&mut poly_len)?; let poly_len = u32::from_be_bytes(poly_len); @@ -187,7 +187,7 @@ impl Polynomial { } /// Writes polynomial to buffer using `SerdePrimeField::write`. - pub fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { + pub(crate) fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { writer.write_all(&(self.values.len() as u32).to_be_bytes())?; for value in self.values.iter() { value.write(writer, format)?; diff --git a/halo2_backend/src/poly/ipa/commitment.rs b/halo2_backend/src/poly/ipa/commitment.rs index b77bd18e2a..388adfa0a4 100644 --- a/halo2_backend/src/poly/ipa/commitment.rs +++ b/halo2_backend/src/poly/ipa/commitment.rs @@ -23,12 +23,12 @@ use std::io; /// Public parameters for IPA commitment scheme #[derive(Debug, Clone)] pub struct ParamsIPA { - pub k: u32, - pub n: u64, - pub g: Vec, - pub g_lagrange: Vec, - pub w: C, - pub u: C, + pub(crate) k: u32, + pub(crate) n: u64, + pub(crate) g: Vec, + pub(crate) g_lagrange: Vec, + pub(crate) w: C, + pub(crate) u: C, } /// Concrete IPA commitment scheme diff --git a/halo2_backend/src/poly/ipa/msm.rs b/halo2_backend/src/poly/ipa/msm.rs index 212ec461a8..0154bdef31 100644 --- a/halo2_backend/src/poly/ipa/msm.rs +++ b/halo2_backend/src/poly/ipa/msm.rs @@ -7,7 +7,7 @@ use std::collections::BTreeMap; /// A multiscalar multiplication in the polynomial commitment scheme #[derive(Debug, Clone)] pub struct MSMIPA<'params, C: CurveAffine> { - pub params: &'params ParamsVerifierIPA, + pub(crate) params: &'params ParamsVerifierIPA, g_scalars: Option>, w_scalar: Option, u_scalar: Option, diff --git a/halo2_backend/src/poly/ipa/multiopen.rs b/halo2_backend/src/poly/ipa/multiopen.rs index 045e9ac3f1..1df7f41daa 100644 --- a/halo2_backend/src/poly/ipa/multiopen.rs +++ b/halo2_backend/src/poly/ipa/multiopen.rs @@ -37,10 +37,10 @@ type ChallengeX4 = ChallengeScalar; #[derive(Debug)] struct CommitmentData { - pub commitment: T, - pub set_index: usize, - pub point_indices: Vec, - pub evals: Vec, + pub(crate) commitment: T, + pub(crate) set_index: usize, + pub(crate) point_indices: Vec, + pub(crate) evals: Vec, } impl CommitmentData { diff --git a/halo2_backend/src/poly/ipa/multiopen/prover.rs b/halo2_backend/src/poly/ipa/multiopen/prover.rs index c72336bf5a..62934afe79 100644 --- a/halo2_backend/src/poly/ipa/multiopen/prover.rs +++ b/halo2_backend/src/poly/ipa/multiopen/prover.rs @@ -16,7 +16,7 @@ use std::marker::PhantomData; /// IPA multi-open prover #[derive(Debug)] pub struct ProverIPA<'params, C: CurveAffine> { - pub params: &'params ParamsIPA, + pub(crate) params: &'params ParamsIPA, } impl<'params, C: CurveAffine> Prover<'params, IPACommitmentScheme> for ProverIPA<'params, C> { diff --git a/halo2_backend/src/poly/ipa/strategy.rs b/halo2_backend/src/poly/ipa/strategy.rs index cb8dba6b1c..6900981f01 100644 --- a/halo2_backend/src/poly/ipa/strategy.rs +++ b/halo2_backend/src/poly/ipa/strategy.rs @@ -17,10 +17,10 @@ use rand_core::OsRng; /// Wrapper for verification accumulator #[derive(Debug, Clone)] pub struct GuardIPA<'params, C: CurveAffine> { - pub msm: MSMIPA<'params, C>, - pub neg_c: C::Scalar, - pub u: Vec, - pub u_packed: Vec, + pub(crate) msm: MSMIPA<'params, C>, + pub(crate) neg_c: C::Scalar, + pub(crate) u: Vec, + pub(crate) u_packed: Vec, } /// An accumulator instance consisting of an evaluation claim and a proof. diff --git a/halo2_backend/src/poly/kzg/commitment.rs b/halo2_backend/src/poly/kzg/commitment.rs index 320efbe780..c9d2285a09 100644 --- a/halo2_backend/src/poly/kzg/commitment.rs +++ b/halo2_backend/src/poly/kzg/commitment.rs @@ -19,12 +19,12 @@ use super::msm::MSMKZG; /// These are the public parameters for the polynomial commitment scheme. #[derive(Debug, Clone)] pub struct ParamsKZG { - pub k: u32, - pub n: u64, - pub g: Vec, - pub g_lagrange: Vec, - pub g2: E::G2Affine, - pub s_g2: E::G2Affine, + pub(crate) k: u32, + pub(crate) n: u64, + pub(crate) g: Vec, + pub(crate) g_lagrange: Vec, + pub(crate) g2: E::G2Affine, + pub(crate) s_g2: E::G2Affine, } /// Umbrella commitment scheme construction for all KZG variants diff --git a/halo2_backend/src/poly/kzg/msm.rs b/halo2_backend/src/poly/kzg/msm.rs index b45dfe2a99..2c0fa4a6e3 100644 --- a/halo2_backend/src/poly/kzg/msm.rs +++ b/halo2_backend/src/poly/kzg/msm.rs @@ -18,8 +18,8 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub scalars: Vec, - pub bases: Vec, + pub(crate) scalars: Vec, + pub(crate) bases: Vec, } impl MSMKZG @@ -95,7 +95,7 @@ where /// A projective point collector #[derive(Debug, Clone)] -pub struct PreMSM +pub(crate) struct PreMSM where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, @@ -120,7 +120,7 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub fn normalize(self) -> MSMKZG { + pub(crate) fn normalize(self) -> MSMKZG { let (scalars, bases) = self .projectives_msms .into_iter() @@ -133,7 +133,7 @@ where } } - pub fn add_msm(&mut self, other: MSMKZG) { + pub(crate) fn add_msm(&mut self, other: MSMKZG) { self.projectives_msms.push(other); } } @@ -155,9 +155,9 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub params: &'a ParamsKZG, - pub left: MSMKZG, - pub right: MSMKZG, + pub(crate) params: &'a ParamsKZG, + pub(crate) left: MSMKZG, + pub(crate) right: MSMKZG, } impl<'a, E: MultiMillerLoop + Debug> DualMSM<'a, E> diff --git a/halo2_backend/src/poly/kzg/strategy.rs b/halo2_backend/src/poly/kzg/strategy.rs index a114146129..05c424f9c5 100644 --- a/halo2_backend/src/poly/kzg/strategy.rs +++ b/halo2_backend/src/poly/kzg/strategy.rs @@ -25,7 +25,7 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub msm_accumulator: DualMSM<'params, E>, + pub(crate) msm_accumulator: DualMSM<'params, E>, } /// Define accumulator type as `DualMSM` @@ -45,7 +45,7 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub fn new(msm_accumulator: DualMSM<'params, E>) -> Self { + pub(crate) fn new(msm_accumulator: DualMSM<'params, E>) -> Self { Self { msm_accumulator } } } @@ -57,7 +57,7 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub msm_accumulator: DualMSM<'params, E>, + pub(crate) msm_accumulator: DualMSM<'params, E>, } impl<'params, E: MultiMillerLoop + Debug> AccumulatorStrategy<'params, E> @@ -66,14 +66,14 @@ where E::G1: CurveExt, { /// Constructs an empty batch verifier - pub fn new(params: &'params ParamsKZG) -> Self { + pub(crate) fn new(params: &'params ParamsKZG) -> Self { AccumulatorStrategy { msm_accumulator: DualMSM::new(params), } } /// Constructs and initialized new batch verifier - pub fn with(msm_accumulator: DualMSM<'params, E>) -> Self { + pub(crate) fn with(msm_accumulator: DualMSM<'params, E>) -> Self { AccumulatorStrategy { msm_accumulator } } } diff --git a/halo2_backend/src/poly/query.rs b/halo2_backend/src/poly/query.rs index 4c53bf0336..bc7a20c240 100644 --- a/halo2_backend/src/poly/query.rs +++ b/halo2_backend/src/poly/query.rs @@ -20,11 +20,11 @@ pub trait Query: Sized + Clone + Send + Sync { #[derive(Debug, Clone, Copy)] pub struct ProverQuery<'com, C: CurveAffine> { /// Point at which polynomial is queried - pub point: C::Scalar, + pub(crate) point: C::Scalar, /// Coefficients of polynomial - pub poly: &'com Polynomial, + pub(crate) poly: &'com Polynomial, /// Blinding factor of polynomial - pub blind: Blind, + pub(crate) blind: Blind, } impl<'com, C> ProverQuery<'com, C> @@ -44,8 +44,8 @@ where #[doc(hidden)] #[derive(Copy, Clone)] pub struct PolynomialPointer<'com, C: CurveAffine> { - pub poly: &'com Polynomial, - pub blind: Blind, + pub(crate) poly: &'com Polynomial, + pub(crate) blind: Blind, } impl<'com, C: CurveAffine> PartialEq for PolynomialPointer<'com, C> { @@ -96,11 +96,11 @@ impl<'com, C: CurveAffine, M: MSM> VerifierQuery<'com, C, M> { #[derive(Debug, Clone, Copy)] pub struct VerifierQuery<'com, C: CurveAffine, M: MSM> { /// Point at which polynomial is queried - pub point: C::Scalar, + pub(crate) point: C::Scalar, /// Commitment to polynomial - pub commitment: CommitmentReference<'com, C, M>, + pub(crate) commitment: CommitmentReference<'com, C, M>, /// Evaluation of polynomial at query point - pub eval: C::Scalar, + pub(crate) eval: C::Scalar, } impl<'com, C, M> VerifierQuery<'com, C, M> From 30261eba54bd3339db0b161e6a131b0bfc2f8c2f Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:39:03 +0800 Subject: [PATCH 04/15] chore: fmt --- halo2_backend/src/plonk.rs | 6 +++++- halo2_backend/src/poly.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index d25b1f8bfe..afc3909b2a 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -62,7 +62,11 @@ where /// - Otherwise: Writes an uncompressed curve element with coordinates in Montgomery form /// Writes a field element into raw bytes in its internal Montgomery representation, /// WITHOUT performing the expensive Montgomery reduction. - pub(crate) fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { + pub(crate) fn write( + &self, + writer: &mut W, + format: SerdeFormat, + ) -> io::Result<()> { // Version byte that will be checked on read. writer.write_all(&[VERSION])?; let k = &self.domain.k(); diff --git a/halo2_backend/src/poly.rs b/halo2_backend/src/poly.rs index 756ceac483..22702555af 100644 --- a/halo2_backend/src/poly.rs +++ b/halo2_backend/src/poly.rs @@ -187,7 +187,11 @@ impl Polynomial { } /// Writes polynomial to buffer using `SerdePrimeField::write`. - pub(crate) fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { + pub(crate) fn write( + &self, + writer: &mut W, + format: SerdeFormat, + ) -> io::Result<()> { writer.write_all(&(self.values.len() as u32).to_be_bytes())?; for value in self.values.iter() { value.write(writer, format)?; From 121f5f57e0b414d6e3ac58cdbb542321771bb770 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:59:49 +0800 Subject: [PATCH 05/15] chore: clippy --- halo2_backend/src/plonk.rs | 4 ++++ halo2_backend/src/plonk/permutation.rs | 1 + halo2_backend/src/poly/kzg/strategy.rs | 1 + 3 files changed, 6 insertions(+) diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index afc3909b2a..3792b2790a 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -187,6 +187,7 @@ where } /// Writes a verifying key to a vector of bytes using [`Self::write`]. + #[allow(unused)] pub(crate) fn to_bytes(&self, format: SerdeFormat) -> Vec { let mut bytes = Vec::::with_capacity(self.bytes_length(format)); Self::write(self, &mut bytes, format).expect("Writing to vector should not fail"); @@ -194,6 +195,7 @@ where } /// Reads a verification key from a slice of bytes using [`Self::read`]. + #[allow(unused)] pub(crate) fn from_bytes>( mut bytes: &[u8], format: SerdeFormat, @@ -294,6 +296,7 @@ impl VerifyingKey { } /// Returns `VerifyingKey` of permutation + #[allow(unused)] pub(crate) fn permutation(&self) -> &permutation::VerifyingKey { &self.permutation } @@ -304,6 +307,7 @@ impl VerifyingKey { } /// Returns representative of this `VerifyingKey` in transcripts + #[allow(unused)] pub(crate) fn transcript_repr(&self) -> C::Scalar { self.transcript_repr } diff --git a/halo2_backend/src/plonk/permutation.rs b/halo2_backend/src/plonk/permutation.rs index 1dd0fe2e70..80d6d77147 100644 --- a/halo2_backend/src/plonk/permutation.rs +++ b/halo2_backend/src/plonk/permutation.rs @@ -23,6 +23,7 @@ pub(crate) struct VerifyingKey { impl VerifyingKey { /// Returns commitments of sigma polynomials + #[allow(unused)] pub fn commitments(&self) -> &Vec { &self.commitments } diff --git a/halo2_backend/src/poly/kzg/strategy.rs b/halo2_backend/src/poly/kzg/strategy.rs index 05c424f9c5..5af286499f 100644 --- a/halo2_backend/src/poly/kzg/strategy.rs +++ b/halo2_backend/src/poly/kzg/strategy.rs @@ -73,6 +73,7 @@ where } /// Constructs and initialized new batch verifier + #[allow(unused)] pub(crate) fn with(msm_accumulator: DualMSM<'params, E>) -> Self { AccumulatorStrategy { msm_accumulator } } From 2784c54bc69a5c5d1842cbb31649fac2bf9e5851 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:58:26 +0800 Subject: [PATCH 06/15] fix: roll back the "pub(crate)" in "halo2_backend/src/plonk.rs" --- halo2_backend/src/plonk.rs | 18 +++++++----------- halo2_backend/src/plonk/permutation.rs | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index 3792b2790a..eb15fdb58b 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -62,11 +62,7 @@ where /// - Otherwise: Writes an uncompressed curve element with coordinates in Montgomery form /// Writes a field element into raw bytes in its internal Montgomery representation, /// WITHOUT performing the expensive Montgomery reduction. - pub(crate) fn write( - &self, - writer: &mut W, - format: SerdeFormat, - ) -> io::Result<()> { + pub fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> { // Version byte that will be checked on read. writer.write_all(&[VERSION])?; let k = &self.domain.k(); @@ -103,7 +99,7 @@ where /// Checks that field elements are less than modulus, and then checks that the point is on the curve. /// - `RawBytesUnchecked`: Reads an uncompressed curve element with coordinates in Montgomery form; /// does not perform any checks - pub(crate) fn read>( + pub fn read>( reader: &mut R, format: SerdeFormat, #[cfg(feature = "circuit-params")] params: ConcreteCircuit::Params, @@ -188,7 +184,7 @@ where /// Writes a verifying key to a vector of bytes using [`Self::write`]. #[allow(unused)] - pub(crate) fn to_bytes(&self, format: SerdeFormat) -> Vec { + pub fn to_bytes(&self, format: SerdeFormat) -> Vec { let mut bytes = Vec::::with_capacity(self.bytes_length(format)); Self::write(self, &mut bytes, format).expect("Writing to vector should not fail"); bytes @@ -196,7 +192,7 @@ where /// Reads a verification key from a slice of bytes using [`Self::read`]. #[allow(unused)] - pub(crate) fn from_bytes>( + pub fn from_bytes>( mut bytes: &[u8], format: SerdeFormat, #[cfg(feature = "circuit-params")] params: ConcreteCircuit::Params, @@ -297,18 +293,18 @@ impl VerifyingKey { /// Returns `VerifyingKey` of permutation #[allow(unused)] - pub(crate) fn permutation(&self) -> &permutation::VerifyingKey { + pub fn permutation(&self) -> &permutation::VerifyingKey { &self.permutation } /// Returns `ConstraintSystem` - pub(crate) fn cs(&self) -> &ConstraintSystem { + pub fn cs(&self) -> &ConstraintSystem { &self.cs } /// Returns representative of this `VerifyingKey` in transcripts #[allow(unused)] - pub(crate) fn transcript_repr(&self) -> C::Scalar { + pub fn transcript_repr(&self) -> C::Scalar { self.transcript_repr } } diff --git a/halo2_backend/src/plonk/permutation.rs b/halo2_backend/src/plonk/permutation.rs index 80d6d77147..d5f32ffe83 100644 --- a/halo2_backend/src/plonk/permutation.rs +++ b/halo2_backend/src/plonk/permutation.rs @@ -17,7 +17,7 @@ pub mod verifier; /// The verifying key for a single permutation argument. #[derive(Clone, Debug)] -pub(crate) struct VerifyingKey { +pub struct VerifyingKey { commitments: Vec, } From 6587f65fddd1814d00699f30f4fe0678af3b0dd0 Mon Sep 17 00:00:00 2001 From: duguorong Date: Mon, 19 Feb 2024 20:58:44 +0800 Subject: [PATCH 07/15] fix: roll back the "#[allow(unused)]" attrs --- halo2_backend/src/plonk.rs | 4 ---- halo2_backend/src/plonk/permutation.rs | 1 - halo2_backend/src/poly/kzg/strategy.rs | 1 - 3 files changed, 6 deletions(-) diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index eb15fdb58b..9a170834cd 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -183,7 +183,6 @@ where } /// Writes a verifying key to a vector of bytes using [`Self::write`]. - #[allow(unused)] pub fn to_bytes(&self, format: SerdeFormat) -> Vec { let mut bytes = Vec::::with_capacity(self.bytes_length(format)); Self::write(self, &mut bytes, format).expect("Writing to vector should not fail"); @@ -191,7 +190,6 @@ where } /// Reads a verification key from a slice of bytes using [`Self::read`]. - #[allow(unused)] pub fn from_bytes>( mut bytes: &[u8], format: SerdeFormat, @@ -292,7 +290,6 @@ impl VerifyingKey { } /// Returns `VerifyingKey` of permutation - #[allow(unused)] pub fn permutation(&self) -> &permutation::VerifyingKey { &self.permutation } @@ -303,7 +300,6 @@ impl VerifyingKey { } /// Returns representative of this `VerifyingKey` in transcripts - #[allow(unused)] pub fn transcript_repr(&self) -> C::Scalar { self.transcript_repr } diff --git a/halo2_backend/src/plonk/permutation.rs b/halo2_backend/src/plonk/permutation.rs index d5f32ffe83..ac2d6fc302 100644 --- a/halo2_backend/src/plonk/permutation.rs +++ b/halo2_backend/src/plonk/permutation.rs @@ -23,7 +23,6 @@ pub struct VerifyingKey { impl VerifyingKey { /// Returns commitments of sigma polynomials - #[allow(unused)] pub fn commitments(&self) -> &Vec { &self.commitments } diff --git a/halo2_backend/src/poly/kzg/strategy.rs b/halo2_backend/src/poly/kzg/strategy.rs index 5af286499f..05c424f9c5 100644 --- a/halo2_backend/src/poly/kzg/strategy.rs +++ b/halo2_backend/src/poly/kzg/strategy.rs @@ -73,7 +73,6 @@ where } /// Constructs and initialized new batch verifier - #[allow(unused)] pub(crate) fn with(msm_accumulator: DualMSM<'params, E>) -> Self { AccumulatorStrategy { msm_accumulator } } From 32d42cfdc9741c2b53dc3a1d02c2f4c61a225fde Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:56:45 +0800 Subject: [PATCH 08/15] fix: correct the "pub(crate)" in "halo2_backend/poly/kzg/strategy.rs" --- halo2_backend/src/poly/kzg/strategy.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/halo2_backend/src/poly/kzg/strategy.rs b/halo2_backend/src/poly/kzg/strategy.rs index 05c424f9c5..78d182fbf6 100644 --- a/halo2_backend/src/poly/kzg/strategy.rs +++ b/halo2_backend/src/poly/kzg/strategy.rs @@ -66,14 +66,14 @@ where E::G1: CurveExt, { /// Constructs an empty batch verifier - pub(crate) fn new(params: &'params ParamsKZG) -> Self { + pub fn new(params: &'params ParamsKZG) -> Self { AccumulatorStrategy { msm_accumulator: DualMSM::new(params), } } /// Constructs and initialized new batch verifier - pub(crate) fn with(msm_accumulator: DualMSM<'params, E>) -> Self { + pub fn with(msm_accumulator: DualMSM<'params, E>) -> Self { AccumulatorStrategy { msm_accumulator } } } @@ -85,7 +85,7 @@ where E::G1Affine: CurveAffine::Fr, CurveExt = ::G1>, E::G1: CurveExt, { - pub msm: DualMSM<'params, E>, + pub(crate) msm: DualMSM<'params, E>, } impl<'params, E: MultiMillerLoop + Debug> SingleStrategy<'params, E> From 0f81b8df909b992757b0bf46d35e6bf5eefeeacc Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:49:08 +0800 Subject: [PATCH 09/15] refactor: move the "halo2_common::arithmetic" to "halo2_backend" --- {halo2_common => halo2_backend}/src/arithmetic.rs | 4 ++-- halo2_backend/src/lib.rs | 2 +- halo2_backend/src/plonk.rs | 2 +- halo2_backend/src/plonk/prover.rs | 6 +++--- halo2_common/src/lib.rs | 1 - halo2_proofs/src/lib.rs | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) rename {halo2_common => halo2_backend}/src/arithmetic.rs (99%) diff --git a/halo2_common/src/arithmetic.rs b/halo2_backend/src/arithmetic.rs similarity index 99% rename from halo2_common/src/arithmetic.rs rename to halo2_backend/src/arithmetic.rs index d6b546e852..9150edce11 100644 --- a/halo2_common/src/arithmetic.rs +++ b/halo2_backend/src/arithmetic.rs @@ -1,11 +1,11 @@ //! This module provides common utilities, traits and structures for group, //! field and polynomial arithmetic. -use super::multicore; use group::{ ff::{BatchInvert, PrimeField}, Curve, Group, GroupOpsOwned, ScalarMulOwned, }; +use halo2_common::multicore; pub use halo2_middleware::ff::Field; pub use halo2curves::{CurveAffine, CurveExt}; @@ -531,7 +531,7 @@ pub fn powers(base: F) -> impl Iterator { use rand_core::OsRng; #[cfg(test)] -use crate::halo2curves::pasta::Fp; +use halo2curves::pasta::Fp; #[test] fn test_lagrange_interpolate() { diff --git a/halo2_backend/src/lib.rs b/halo2_backend/src/lib.rs index 4183e6425b..6a60c32919 100644 --- a/halo2_backend/src/lib.rs +++ b/halo2_backend/src/lib.rs @@ -1,9 +1,9 @@ +pub mod arithmetic; mod helpers; pub mod plonk; pub mod poly; // Internal re-exports -pub use halo2_common::arithmetic; pub use halo2_common::circuit; pub use halo2_common::multicore; pub use halo2_common::transcript; diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index 9a170834cd..a88c8763a3 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -1,6 +1,7 @@ use blake2b_simd::Params as Blake2bParams; use group::ff::{Field, FromUniformBytes, PrimeField}; +use crate::arithmetic::CurveAffine; use crate::helpers::{ self, polynomial_slice_byte_length, read_polynomial_vec, write_polynomial_slice, SerdeCurveAffine, SerdePrimeField, @@ -10,7 +11,6 @@ use crate::poly::{ Polynomial, }; use evaluation::Evaluator; -use halo2_common::arithmetic::CurveAffine; use halo2_common::plonk::{Circuit, ConstraintSystem, PinnedConstraintSystem}; use halo2_common::transcript::{EncodedChallenge, Transcript}; use halo2_common::SerdeFormat; diff --git a/halo2_backend/src/plonk/prover.rs b/halo2_backend/src/plonk/prover.rs index f6c3cc695d..82ad9cdc47 100644 --- a/halo2_backend/src/plonk/prover.rs +++ b/halo2_backend/src/plonk/prover.rs @@ -4,6 +4,7 @@ use rand_core::RngCore; use std::collections::{BTreeSet, HashSet}; use std::{collections::HashMap, iter}; +use crate::arithmetic::{eval_polynomial, CurveAffine}; use crate::plonk::lookup::prover::lookup_commit_permuted; use crate::plonk::permutation::prover::permutation_commit; use crate::plonk::shuffle::prover::shuffle_commit_product; @@ -12,12 +13,11 @@ use crate::poly::{ commitment::{Blind, CommitmentScheme, Params, Prover}, Basis, Coeff, LagrangeCoeff, Polynomial, ProverQuery, }; + +use group::prime::PrimeCurveAffine; use halo2_common::plonk::{ circuit::sealed, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error, }; - -use group::prime::PrimeCurveAffine; -use halo2_common::arithmetic::{eval_polynomial, CurveAffine}; use halo2_common::transcript::{EncodedChallenge, TranscriptWrite}; /// Collection of instance data used during proving for a single circuit proof. diff --git a/halo2_common/src/lib.rs b/halo2_common/src/lib.rs index 8bd60e0f49..6e0a149bef 100644 --- a/halo2_common/src/lib.rs +++ b/halo2_common/src/lib.rs @@ -6,7 +6,6 @@ #![deny(rustdoc::broken_intra_doc_links)] #![deny(unsafe_code)] -pub mod arithmetic; pub mod circuit; pub use halo2curves; pub mod multicore; diff --git a/halo2_proofs/src/lib.rs b/halo2_proofs/src/lib.rs index dbe5899cc2..5bd18101a6 100644 --- a/halo2_proofs/src/lib.rs +++ b/halo2_proofs/src/lib.rs @@ -23,7 +23,7 @@ pub mod circuit { ///! This module provides common utilities, traits and structures for group, ///! field and polynomial arithmetic. pub mod arithmetic { - pub use halo2_common::arithmetic::{ + pub use halo2_backend::arithmetic::{ best_fft, parallelize, small_multiexp, CurveAffine, CurveExt, Field, }; } From 1ecd1653763807ffe4619bd2b16eaec030e800e2 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:50:20 +0800 Subject: [PATCH 10/15] chore: fix clippy warnings --- halo2_backend/src/arithmetic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/halo2_backend/src/arithmetic.rs b/halo2_backend/src/arithmetic.rs index 9150edce11..876856c05c 100644 --- a/halo2_backend/src/arithmetic.rs +++ b/halo2_backend/src/arithmetic.rs @@ -89,7 +89,7 @@ fn multiexp_serial(coeffs: &[C::Scalar], bases: &[C], acc: &mut other += a; other } - Bucket::Projective(a) => other + &a, + Bucket::Projective(a) => other + a, } } } From b535a1899688de1886aa106781f2a4b9c0bb9b6c Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:21:08 +0800 Subject: [PATCH 11/15] build: update the rustc to "1.73.0" in "rust-toolchain" --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 65ee095984..5e3a425662 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.67.0 +1.73.0 From d1dd34fd1a279f60fece64bee3f7d2f34ed862e1 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:32:16 +0800 Subject: [PATCH 12/15] chore: fix clippy warnings --- halo2_common/src/plonk.rs | 1 - halo2_frontend/src/circuit.rs | 2 +- halo2_frontend/src/circuit/floor_planner.rs | 4 ++-- halo2_proofs/src/lib.rs | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/halo2_common/src/plonk.rs b/halo2_common/src/plonk.rs index e58952346a..01f9177203 100644 --- a/halo2_common/src/plonk.rs +++ b/halo2_common/src/plonk.rs @@ -5,7 +5,6 @@ //! [halo]: https://eprint.iacr.org/2019/1021 //! [plonk]: https://eprint.iacr.org/2019/953 -use crate::plonk::circuit::Column; use crate::transcript::ChallengeScalar; use halo2_middleware::circuit::{Advice, Fixed, Instance}; use halo2_middleware::ff::Field; diff --git a/halo2_frontend/src/circuit.rs b/halo2_frontend/src/circuit.rs index 18a8f917a7..03c5d56697 100644 --- a/halo2_frontend/src/circuit.rs +++ b/halo2_frontend/src/circuit.rs @@ -76,7 +76,7 @@ pub fn compile_circuit>( let selectors = std::mem::take(&mut assembly.selectors); cs.directly_convert_selectors_to_fixed(selectors) }; - fixed.extend(selector_polys.into_iter()); + fixed.extend(selector_polys); let preprocessing = PreprocessingV2 { permutation: halo2_middleware::permutation::AssemblyMid { diff --git a/halo2_frontend/src/circuit/floor_planner.rs b/halo2_frontend/src/circuit/floor_planner.rs index cd63de8a67..9ad3df1a15 100644 --- a/halo2_frontend/src/circuit/floor_planner.rs +++ b/halo2_frontend/src/circuit/floor_planner.rs @@ -1,4 +1,4 @@ -mod single_pass; -mod v1; +pub mod single_pass; +pub mod v1; pub use halo2_common::circuit::floor_planner::*; diff --git a/halo2_proofs/src/lib.rs b/halo2_proofs/src/lib.rs index 5bd18101a6..4f72856a10 100644 --- a/halo2_proofs/src/lib.rs +++ b/halo2_proofs/src/lib.rs @@ -20,8 +20,8 @@ pub mod circuit { AssignedCell, Cell, Chip, Layouter, Region, SimpleFloorPlanner, Value, }; } -///! This module provides common utilities, traits and structures for group, -///! field and polynomial arithmetic. +/// This module provides common utilities, traits and structures for group, +/// field and polynomial arithmetic. pub mod arithmetic { pub use halo2_backend::arithmetic::{ best_fft, parallelize, small_multiexp, CurveAffine, CurveExt, Field, From 6bc668bd27a6a7b30e0dd7e940a8e57fac13a9c8 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:38:31 +0800 Subject: [PATCH 13/15] chore: add resolver(2) to workspace cargo.toml --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 458f57fbe9..39b4e8c24b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ members = [ "halo2_backend", "halo2_common", ] +resolver = "2" \ No newline at end of file From d49bf220fd0711bef42e467cfabf08bd352ac075 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:28:52 +0800 Subject: [PATCH 14/15] chore: fix the lint warning --- halo2_proofs/tests/plonk_api.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index ef595811f9..c3e21112aa 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -622,7 +622,7 @@ fn plonk_api() { //panic!("{:#?}", pk.get_vk().pinned()); assert_eq!( format!("{:#?}", pk.get_vk().pinned()), - r#####"PinnedVerificationKey { + r#"PinnedVerificationKey { base_modulus: "0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001", scalar_modulus: "0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001", domain: PinnedEvaluationDomain { @@ -1015,7 +1015,7 @@ fn plonk_api() { (0x3d907e0591343bd285c2c846f3e871a6ac70d80ec29e9500b8cb57f544e60202, 0x1034e48df35830244cabea076be8a16d67d7896e27c6ac22b285d017105da9c3), ], }, -}"##### +}"# ); } } From 09aaf9781567bde2979f35ddabc2b43148d66173 Mon Sep 17 00:00:00 2001 From: duguorong <80258679+duguorong009@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:58:20 +0800 Subject: [PATCH 15/15] build: set the "getrandom" crate as dependency for "wasm32-*" target --- halo2_backend/Cargo.toml | 2 +- halo2_common/Cargo.toml | 2 +- halo2_frontend/Cargo.toml | 2 +- halo2_middleware/Cargo.toml | 2 +- halo2_proofs/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/halo2_backend/Cargo.toml b/halo2_backend/Cargo.toml index 807436a131..e443c953dc 100644 --- a/halo2_backend/Cargo.toml +++ b/halo2_backend/Cargo.toml @@ -48,7 +48,7 @@ proptest = "1" rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } serde_json = "1" -[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] getrandom = { version = "0.2", features = ["js"] } [features] diff --git a/halo2_common/Cargo.toml b/halo2_common/Cargo.toml index 4f60dbfa11..a4442a6423 100644 --- a/halo2_common/Cargo.toml +++ b/halo2_common/Cargo.toml @@ -44,7 +44,7 @@ proptest = "1" rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } serde_json = "1" -[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] getrandom = { version = "0.2", features = ["js"] } [features] diff --git a/halo2_frontend/Cargo.toml b/halo2_frontend/Cargo.toml index 6a35d66652..9924479feb 100644 --- a/halo2_frontend/Cargo.toml +++ b/halo2_frontend/Cargo.toml @@ -45,7 +45,7 @@ proptest = "1" rand_core = { version = "0.6", default-features = false, features = ["getrandom"] } serde_json = "1" -[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] getrandom = { version = "0.2", features = ["js"] } [features] diff --git a/halo2_middleware/Cargo.toml b/halo2_middleware/Cargo.toml index 66ec0b5105..575c25dc8a 100644 --- a/halo2_middleware/Cargo.toml +++ b/halo2_middleware/Cargo.toml @@ -35,7 +35,7 @@ proptest = "1" group = "0.13" halo2curves = { version = "0.6.0", default-features = false } -[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] getrandom = { version = "0.2", features = ["js"] } [lib] diff --git a/halo2_proofs/Cargo.toml b/halo2_proofs/Cargo.toml index 8bf059790b..4df38b4187 100644 --- a/halo2_proofs/Cargo.toml +++ b/halo2_proofs/Cargo.toml @@ -70,7 +70,7 @@ proptest = "1" dhat = "0.3.2" serde_json = "1" -[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] getrandom = { version = "0.2", features = ["js"] } [features]