From bd385c36253cd1611785dd4ef10199234e2c64bc Mon Sep 17 00:00:00 2001 From: duguorong009 <80258679+duguorong009@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:48:09 +0800 Subject: [PATCH] fix: review the pub types/fields(post-split)(1) (#307) * fix: check the "pub" types/fields in backend & middleware * fix: check the "pub" type/fields in frontend * fix: remove dead methods --- halo2_backend/src/arithmetic.rs | 16 +++--- halo2_backend/src/helpers.rs | 19 ------- halo2_backend/src/plonk.rs | 27 ++++------ halo2_backend/src/plonk/circuit.rs | 14 ++--- halo2_backend/src/plonk/evaluation.rs | 4 +- halo2_backend/src/plonk/keygen.rs | 53 ++----------------- halo2_backend/src/plonk/lookup/verifier.rs | 6 +-- halo2_backend/src/plonk/permutation.rs | 13 ++--- halo2_backend/src/plonk/permutation/keygen.rs | 2 +- halo2_backend/src/plonk/vanishing/verifier.rs | 8 +-- halo2_backend/src/poly.rs | 7 +-- halo2_frontend/src/circuit.rs | 2 +- .../src/circuit/floor_planner/v1/strategy.rs | 8 +-- halo2_frontend/src/circuit/layouter.rs | 6 +-- halo2_frontend/src/dev.rs | 42 +-------------- halo2_frontend/src/plonk.rs | 1 - .../src/plonk/circuit/compress_selectors.rs | 6 +-- halo2_frontend/src/plonk/keygen.rs | 14 ++--- halo2_frontend/src/plonk/permutation.rs | 6 +-- halo2_frontend/src/plonk/shuffle.rs | 2 +- halo2_middleware/src/expression.rs | 7 +-- 21 files changed, 70 insertions(+), 193 deletions(-) diff --git a/halo2_backend/src/arithmetic.rs b/halo2_backend/src/arithmetic.rs index b16b9c3e24..f580f72fd1 100644 --- a/halo2_backend/src/arithmetic.rs +++ b/halo2_backend/src/arithmetic.rs @@ -14,7 +14,7 @@ pub use halo2curves::{CurveAffine, CurveExt}; /// This represents an element of a group with basic operations that can be /// performed. This allows an FFT implementation (for example) to operate /// generically over either a field or elliptic curve group. -pub trait FftGroup: +pub(crate) trait FftGroup: Copy + Send + Sync + 'static + GroupOpsOwned + ScalarMulOwned { } @@ -27,7 +27,7 @@ where } /// Convert coefficient bases group elements to lagrange basis by inverse FFT. -pub fn g_to_lagrange(g_projective: Vec, k: u32) -> Vec { +pub(crate) fn g_to_lagrange(g_projective: Vec, k: u32) -> Vec { let n_inv = C::Scalar::TWO_INV.pow_vartime([k as u64, 0, 0, 0]); let mut omega_inv = C::Scalar::ROOT_OF_UNITY_INV; for _ in k..C::Scalar::S { @@ -54,7 +54,7 @@ pub fn g_to_lagrange(g_projective: Vec, k: u32) -> Vec } /// This evaluates a provided polynomial (in coefficient form) at `point`. -pub fn eval_polynomial(poly: &[F], point: F) -> F { +pub(crate) fn eval_polynomial(poly: &[F], point: F) -> F { fn evaluate(poly: &[F], point: F) -> F { poly.iter() .rev() @@ -84,7 +84,7 @@ pub fn eval_polynomial(poly: &[F], point: F) -> F { /// This computes the inner product of two vectors `a` and `b`. /// /// This function will panic if the two vectors are not the same size. -pub fn compute_inner_product(a: &[F], b: &[F]) -> F { +pub(crate) fn compute_inner_product(a: &[F], b: &[F]) -> F { // TODO: parallelize? assert_eq!(a.len(), b.len()); @@ -98,7 +98,7 @@ pub fn compute_inner_product(a: &[F], b: &[F]) -> F { /// Divides polynomial `a` in `X` by `X - b` with /// no remainder. -pub fn kate_division<'a, F: Field, I: IntoIterator>(a: I, mut b: F) -> Vec +pub(crate) fn kate_division<'a, F: Field, I: IntoIterator>(a: I, mut b: F) -> Vec where I::IntoIter: DoubleEndedIterator + ExactSizeIterator, { @@ -174,7 +174,7 @@ pub fn parallelize(v: &mu /// Returns coefficients of an n - 1 degree polynomial given a set of n points /// and their evaluations. This function will panic if two values in `points` /// are the same. -pub fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { +pub(crate) fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { assert_eq!(points.len(), evals.len()); if points.len() == 1 { // Constant polynomial @@ -229,7 +229,7 @@ pub fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { } } -pub fn evaluate_vanishing_polynomial(roots: &[F], z: F) -> F { +pub(crate) fn evaluate_vanishing_polynomial(roots: &[F], z: F) -> F { fn evaluate(roots: &[F], z: F) -> F { roots.iter().fold(F::ONE, |acc, point| (z - point) * acc) } @@ -249,7 +249,7 @@ pub fn evaluate_vanishing_polynomial(roots: &[F], z: F) -> F { } } -pub fn powers(base: F) -> impl Iterator { +pub(crate) fn powers(base: F) -> impl Iterator { std::iter::successors(Some(F::ONE), move |power| Some(base * power)) } diff --git a/halo2_backend/src/helpers.rs b/halo2_backend/src/helpers.rs index 9993dbd61e..710cedb691 100644 --- a/halo2_backend/src/helpers.rs +++ b/halo2_backend/src/helpers.rs @@ -102,25 +102,6 @@ pub trait SerdePrimeField: PrimeField + SerdeObject { } impl SerdePrimeField for F {} -/// Convert a slice of `bool` into a `u8`. -/// -/// Panics if the slice has length greater than 8. -pub fn pack(bits: &[bool]) -> u8 { - let mut value = 0u8; - assert!(bits.len() <= 8); - for (bit_index, bit) in bits.iter().enumerate() { - value |= (*bit as u8) << bit_index; - } - value -} - -/// Writes the first `bits.len()` bits of a `u8` into `bits`. -pub fn unpack(byte: u8, bits: &mut [bool]) { - for (bit_index, bit) in bits.iter_mut().enumerate() { - *bit = (byte >> bit_index) & 1 == 1; - } -} - /// Reads a vector of polynomials from buffer pub(crate) fn read_polynomial_vec( reader: &mut R, diff --git a/halo2_backend/src/plonk.rs b/halo2_backend/src/plonk.rs index 770c1130f0..ee34d50e3d 100644 --- a/halo2_backend/src/plonk.rs +++ b/halo2_backend/src/plonk.rs @@ -230,13 +230,8 @@ impl VerifyingKey { &self.fixed_commitments } - /// Returns `VerifyingKey` of permutation - pub fn permutation(&self) -> &permutation::VerifyingKey { - &self.permutation - } - /// Returns `ConstraintSystem` - pub fn cs(&self) -> &ConstraintSystemBack { + pub(crate) fn cs(&self) -> &ConstraintSystemBack { &self.cs } @@ -388,21 +383,21 @@ impl VerifyingKey { } #[derive(Clone, Copy, Debug)] -pub struct Theta; -pub type ChallengeTheta = ChallengeScalar; +pub(crate) struct Theta; +pub(crate) type ChallengeTheta = ChallengeScalar; #[derive(Clone, Copy, Debug)] -pub struct Beta; -pub type ChallengeBeta = ChallengeScalar; +pub(crate) struct Beta; +pub(crate) type ChallengeBeta = ChallengeScalar; #[derive(Clone, Copy, Debug)] -pub struct Gamma; -pub type ChallengeGamma = ChallengeScalar; +pub(crate) struct Gamma; +pub(crate) type ChallengeGamma = ChallengeScalar; #[derive(Clone, Copy, Debug)] -pub struct Y; -pub type ChallengeY = ChallengeScalar; +pub(crate) struct Y; +pub(crate) type ChallengeY = ChallengeScalar; #[derive(Clone, Copy, Debug)] -pub struct X; -pub type ChallengeX = ChallengeScalar; +pub(crate) struct X; +pub(crate) type ChallengeX = ChallengeScalar; diff --git a/halo2_backend/src/plonk/circuit.rs b/halo2_backend/src/plonk/circuit.rs index 2e5cc9ebd1..c36bd7b9b4 100644 --- a/halo2_backend/src/plonk/circuit.rs +++ b/halo2_backend/src/plonk/circuit.rs @@ -97,7 +97,7 @@ pub struct ConstraintSystemBack { impl ConstraintSystemBack { /// Compute the degree of the constraint system (the maximum degree of all /// constraints). - pub fn degree(&self) -> usize { + pub(crate) fn degree(&self) -> usize { // The permutation argument will serve alongside the gates, so must be // accounted for. let mut degree = permutation_argument_required_degree(); @@ -140,7 +140,7 @@ impl ConstraintSystemBack { /// Compute the number of blinding factors necessary to perfectly blind /// each of the prover's witness polynomials. - pub fn blinding_factors(&self) -> usize { + pub(crate) fn blinding_factors(&self) -> usize { // All of the prover's advice columns are evaluated at no more than let factors = *self.num_advice_queries.iter().max().unwrap_or(&1); // distinct points during gate checks. @@ -169,7 +169,7 @@ impl ConstraintSystemBack { /// Returns the minimum necessary rows that need to exist in order to /// account for e.g. blinding factors. - pub fn minimum_rows(&self) -> usize { + pub(crate) fn minimum_rows(&self) -> usize { self.blinding_factors() // m blinding factors + 1 // for l_{-(m + 1)} (l_last) + 1 // for l_0 (just for extra breathing room for the permutation @@ -179,7 +179,7 @@ impl ConstraintSystemBack { + 1 // for at least one row } - pub fn get_any_query_index(&self, column: ColumnMid, at: Rotation) -> usize { + pub(crate) fn get_any_query_index(&self, column: ColumnMid, at: Rotation) -> usize { let queries = match column.column_type { Any::Advice => &self.advice_queries, Any::Fixed => &self.fixed_queries, @@ -194,7 +194,7 @@ impl ConstraintSystemBack { } /// Returns the list of phases - pub fn phases(&self) -> impl Iterator { + pub(crate) fn phases(&self) -> impl Iterator { let max_phase = self .advice_column_phase .iter() @@ -207,7 +207,7 @@ impl ConstraintSystemBack { /// Obtain a pinned version of this constraint system; a structure with the /// minimal parameters needed to determine the rest of the constraint /// system. - pub fn pinned(&self) -> PinnedConstraintSystem<'_, F> { + pub(crate) fn pinned(&self) -> PinnedConstraintSystem<'_, F> { PinnedConstraintSystem { num_fixed_columns: &self.num_fixed_columns, num_advice_columns: &self.num_advice_columns, @@ -238,7 +238,7 @@ impl<'a, F: Field> std::fmt::Debug for PinnedGates<'a, F> { } /// Represents the minimal parameters that determine a `ConstraintSystem`. -pub struct PinnedConstraintSystem<'a, F: Field> { +pub(crate) struct PinnedConstraintSystem<'a, F: Field> { num_fixed_columns: &'a usize, num_advice_columns: &'a usize, num_instance_columns: &'a usize, diff --git a/halo2_backend/src/plonk/evaluation.rs b/halo2_backend/src/plonk/evaluation.rs index 7003f8d638..ef5c05f1c4 100644 --- a/halo2_backend/src/plonk/evaluation.rs +++ b/halo2_backend/src/plonk/evaluation.rs @@ -173,7 +173,7 @@ impl Calculation { /// Evaluator #[derive(Clone, Default, Debug)] -pub struct Evaluator { +pub(crate) struct Evaluator { /// Custom gates evalution custom_gates: GraphEvaluator, /// Lookups evalution @@ -835,7 +835,7 @@ impl GraphEvaluator { } /// Simple evaluation of an [`ExpressionBack`] over the provided lagrange polynomials -pub fn evaluate( +pub(crate) fn evaluate( expression: &ExpressionBack, size: usize, rot_scale: i32, diff --git a/halo2_backend/src/plonk/keygen.rs b/halo2_backend/src/plonk/keygen.rs index 00c34b948a..067434a4d6 100644 --- a/halo2_backend/src/plonk/keygen.rs +++ b/halo2_backend/src/plonk/keygen.rs @@ -377,58 +377,15 @@ impl From> for ConstraintSystemBack { /// List of queries (columns and rotations) used by a circuit #[derive(Debug, Clone)] -pub struct Queries { +pub(crate) struct Queries { /// List of unique advice queries - pub advice: Vec<(ColumnMid, Rotation)>, + pub(crate) advice: Vec<(ColumnMid, Rotation)>, /// List of unique instance queries - pub instance: Vec<(ColumnMid, Rotation)>, + pub(crate) instance: Vec<(ColumnMid, Rotation)>, /// List of unique fixed queries - pub fixed: Vec<(ColumnMid, Rotation)>, + pub(crate) fixed: Vec<(ColumnMid, Rotation)>, /// Contains an integer for each advice column /// identifying how many distinct queries it has /// so far; should be same length as cs.num_advice_columns. - pub num_advice_queries: Vec, -} - -impl Queries { - /// Returns the minimum necessary rows that need to exist in order to - /// account for e.g. blinding factors. - pub fn minimum_rows(&self) -> usize { - self.blinding_factors() // m blinding factors - + 1 // for l_{-(m + 1)} (l_last) - + 1 // for l_0 (just for extra breathing room for the permutation - // argument, to essentially force a separation in the - // permutation polynomial between the roles of l_last, l_0 - // and the interstitial values.) - + 1 // for at least one row - } - - /// Compute the number of blinding factors necessary to perfectly blind - /// each of the prover's witness polynomials. - pub fn blinding_factors(&self) -> usize { - // All of the prover's advice columns are evaluated at no more than - let factors = *self.num_advice_queries.iter().max().unwrap_or(&1); - // distinct points during gate checks. - - // - The permutation argument witness polynomials are evaluated at most 3 times. - // - Each lookup argument has independent witness polynomials, and they are - // evaluated at most 2 times. - let factors = std::cmp::max(3, factors); - - // Each polynomial is evaluated at most an additional time during - // multiopen (at x_3 to produce q_evals): - let factors = factors + 1; - - // h(x) is derived by the other evaluations so it does not reveal - // anything; in fact it does not even appear in the proof. - - // h(x_3) is also not revealed; the verifier only learns a single - // evaluation of a polynomial in x_1 which has h(x_3) and another random - // polynomial evaluated at x_3 as coefficients -- this random polynomial - // is "random_poly" in the vanishing argument. - - // Add an additional blinding factor as a slight defense against - // off-by-one errors. - factors + 1 - } + pub(crate) num_advice_queries: Vec, } diff --git a/halo2_backend/src/plonk/lookup/verifier.rs b/halo2_backend/src/plonk/lookup/verifier.rs index 2afefa2cf3..aadf8cd0e6 100644 --- a/halo2_backend/src/plonk/lookup/verifier.rs +++ b/halo2_backend/src/plonk/lookup/verifier.rs @@ -12,17 +12,17 @@ use halo2_middleware::circuit::Any; use halo2_middleware::ff::Field; use halo2_middleware::poly::Rotation; -pub struct PermutationCommitments { +pub(crate) struct PermutationCommitments { permuted_input_commitment: C, permuted_table_commitment: C, } -pub struct Committed { +pub(crate) struct Committed { permuted: PermutationCommitments, 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/plonk/permutation.rs b/halo2_backend/src/plonk/permutation.rs index 785a4b71e9..f96e1271d1 100644 --- a/halo2_backend/src/plonk/permutation.rs +++ b/halo2_backend/src/plonk/permutation.rs @@ -11,22 +11,17 @@ pub use halo2_middleware::permutation::ArgumentMid as Argument; use std::io; -pub mod keygen; -pub mod prover; -pub mod verifier; +pub(crate) mod keygen; +pub(crate) mod prover; +pub(crate) mod verifier; /// The verifying key for a single permutation argument. #[derive(Clone, Debug)] -pub struct VerifyingKey { +pub(crate) struct VerifyingKey { commitments: Vec, } impl VerifyingKey { - /// Returns commitments of sigma polynomials - pub fn commitments(&self) -> &Vec { - &self.commitments - } - pub(crate) fn write(&self, writer: &mut W, format: SerdeFormat) -> io::Result<()> where C: SerdeCurveAffine, diff --git a/halo2_backend/src/plonk/permutation/keygen.rs b/halo2_backend/src/plonk/permutation/keygen.rs index 5721dc16fa..6a09946fe2 100644 --- a/halo2_backend/src/plonk/permutation/keygen.rs +++ b/halo2_backend/src/plonk/permutation/keygen.rs @@ -16,7 +16,7 @@ use halo2_middleware::permutation::{ArgumentMid, AssemblyMid}; /// Struct that accumulates all the necessary data in order to construct the permutation argument. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Assembly { +pub(crate) struct Assembly { /// Columns that participate on the copy permutation argument. columns: Vec, /// Mapping of the actual copies done. diff --git a/halo2_backend/src/plonk/vanishing/verifier.rs b/halo2_backend/src/plonk/vanishing/verifier.rs index c925c8cec9..aeb5d85a10 100644 --- a/halo2_backend/src/plonk/vanishing/verifier.rs +++ b/halo2_backend/src/plonk/vanishing/verifier.rs @@ -14,22 +14,22 @@ use crate::{ use super::Argument; -pub struct Committed { +pub(in crate::plonk) struct Committed { random_poly_commitment: C, } -pub struct Constructed { +pub(in crate::plonk) struct Constructed { h_commitments: Vec, random_poly_commitment: C, } -pub struct PartiallyEvaluated { +pub(in crate::plonk) struct PartiallyEvaluated { h_commitments: Vec, random_poly_commitment: C, random_eval: C::Scalar, } -pub struct Evaluated> { +pub(in crate::plonk) struct Evaluated> { h_commitment: M, random_poly_commitment: C, expected_h_eval: C::Scalar, diff --git a/halo2_backend/src/poly.rs b/halo2_backend/src/poly.rs index 0499072381..093034ed83 100644 --- a/halo2_backend/src/poly.rs +++ b/halo2_backend/src/poly.rs @@ -28,15 +28,10 @@ pub mod kzg; mod multiopen_test; pub use domain::*; -pub use query::{ProverQuery, VerifierQuery}; +pub(crate) use query::{ProverQuery, VerifierQuery}; pub use strategy::{Guard, VerificationStrategy}; -// TODO: move everything from the poly module to the backend. This requires that the frontend -// works without Poly (and just Vec). -// https://github.com/privacy-scaling-explorations/halo2/issues/257 - /// This is an error that could occur during proving or circuit synthesis. -// TODO: these errors need to be cleaned up #[derive(Debug)] pub enum Error { /// OpeningProof is not well-formed diff --git a/halo2_frontend/src/circuit.rs b/halo2_frontend/src/circuit.rs index 3f7644d7df..233a1cb032 100644 --- a/halo2_frontend/src/circuit.rs +++ b/halo2_frontend/src/circuit.rs @@ -133,7 +133,7 @@ pub fn compile_circuit>( )) } -pub struct WitnessCollection<'a, F: Field> { +struct WitnessCollection<'a, F: Field> { k: u32, current_phase: sealed::Phase, advice_column_phase: &'a Vec, diff --git a/halo2_frontend/src/circuit/floor_planner/v1/strategy.rs b/halo2_frontend/src/circuit/floor_planner/v1/strategy.rs index b78721f501..a5dd0f2bad 100644 --- a/halo2_frontend/src/circuit/floor_planner/v1/strategy.rs +++ b/halo2_frontend/src/circuit/floor_planner/v1/strategy.rs @@ -47,7 +47,7 @@ impl EmptySpace { /// /// This is a set of [a_start, a_end) pairs representing disjoint allocated intervals. #[derive(Clone, Default, Debug)] -pub struct Allocations(BTreeSet); +pub(crate) struct Allocations(BTreeSet); impl Allocations { /// Returns the row that forms the unbounded unallocated interval [row, None). @@ -100,7 +100,7 @@ impl Allocations { } /// Allocated rows within a circuit. -pub type CircuitAllocations = HashMap; +pub(crate) type CircuitAllocations = HashMap; /// - `start` is the current start row of the region (not of this column). /// - `slack` is the maximum number of rows the start could be moved down, taking into @@ -163,7 +163,7 @@ fn first_fit_region( /// Positions the regions starting at the earliest row for which none of the columns are /// in use, taking into account gaps between earlier regions. -pub fn slot_in( +fn slot_in( region_shapes: Vec, ) -> (Vec<(RegionStart, RegionShape)>, CircuitAllocations) { // Tracks the empty regions for each column. @@ -196,7 +196,7 @@ pub fn slot_in( } /// Sorts the regions by advice area and then lays them out with the [`slot_in`] strategy. -pub fn slot_in_biggest_advice_first( +pub(crate) fn slot_in_biggest_advice_first( region_shapes: Vec, ) -> (Vec, CircuitAllocations) { let mut sorted_regions: Vec<_> = region_shapes.into_iter().collect(); diff --git a/halo2_frontend/src/circuit/layouter.rs b/halo2_frontend/src/circuit/layouter.rs index 80625676cd..743492daa4 100644 --- a/halo2_frontend/src/circuit/layouter.rs +++ b/halo2_frontend/src/circuit/layouter.rs @@ -140,9 +140,9 @@ pub trait RegionLayouter: fmt::Debug + SyncDeps { /// the set of columns it uses as well as the number of rows it uses. #[derive(Clone, Debug)] pub struct RegionShape { - pub region_index: RegionIndex, - pub columns: HashSet, - pub row_count: usize, + pub(super) region_index: RegionIndex, + pub(super) columns: HashSet, + pub(super) row_count: usize, } /// The virtual column involved in a region. This includes concrete columns, diff --git a/halo2_frontend/src/dev.rs b/halo2_frontend/src/dev.rs index faa802828a..787a6dfe98 100644 --- a/halo2_frontend/src/dev.rs +++ b/halo2_frontend/src/dev.rs @@ -50,7 +50,7 @@ pub use graph::{circuit_dot_graph, layout::CircuitLayout}; /// Region of assignments that are done during synthesis. #[derive(Debug)] -pub struct Region { +struct Region { /// The name of the region. Not required to be unique. name: String, /// The columns involved in this region. @@ -83,36 +83,6 @@ impl Region { } self.rows = Some((start, end)); } - - /// Returns the name of the region. - pub fn name(&self) -> &String { - &self.name - } - - /// Returns the columns involved in this region. - pub fn columns(&self) -> &HashSet> { - &self.columns - } - - /// Returns the rows that this region starts and ends on, if known. - pub fn rows(&self) -> Option<(usize, usize)> { - self.rows - } - - /// Returns the selectors that have been enabled in this region. - pub fn enabled_selectors(&self) -> &HashMap> { - &self.enabled_selectors - } - - /// Returns the annotations given to Advice, Fixed or Instance columns within a region context. - pub fn annotations(&self) -> &HashMap { - &self.annotations - } - - /// Returns the cells assigned in this region. - pub fn cells(&self) -> &HashMap<(Column, usize), usize> { - &self.cells - } } /// The value of a particular cell within the circuit. @@ -1269,16 +1239,6 @@ impl + Ord> MockProver { pub fn instance(&self) -> &Vec>> { &self.instance } - - /// Returns the permutation argument (`Assembly`) used within a MockProver instance. - pub fn permutation(&self) -> &permutation::Assembly { - &self.permutation - } - - /// Returns the Regions used during synthesis. - pub fn regions(&self) -> &[Region] { - &self.regions - } } #[cfg(test)] diff --git a/halo2_frontend/src/plonk.rs b/halo2_frontend/src/plonk.rs index db37295807..36701a97be 100644 --- a/halo2_frontend/src/plonk.rs +++ b/halo2_frontend/src/plonk.rs @@ -9,4 +9,3 @@ pub mod shuffle; pub use assigned::*; pub use circuit::*; pub use error::*; -pub use keygen::*; diff --git a/halo2_frontend/src/plonk/circuit/compress_selectors.rs b/halo2_frontend/src/plonk/circuit/compress_selectors.rs index b40b27503d..46af4a0e35 100644 --- a/halo2_frontend/src/plonk/circuit/compress_selectors.rs +++ b/halo2_frontend/src/plonk/circuit/compress_selectors.rs @@ -3,7 +3,7 @@ use halo2_middleware::ff::Field; /// This describes a selector and where it is activated. #[derive(Debug, Clone)] -pub struct SelectorDescription { +pub(crate) struct SelectorDescription { /// The selector that this description references, by index. pub selector: usize, @@ -20,7 +20,7 @@ pub struct SelectorDescription { /// This describes the assigned combination of a particular selector as well as /// the expression it should be substituted with. #[derive(Debug, Clone)] -pub struct SelectorAssignment { +pub(crate) struct SelectorAssignment { /// The selector that this structure references, by index. pub selector: usize, @@ -48,7 +48,7 @@ pub struct SelectorAssignment { /// substitutions to the constraint system. /// /// This function is completely deterministic. -pub fn process( +pub(crate) fn process( mut selectors: Vec, max_degree: usize, mut allocate_fixed_column: E, diff --git a/halo2_frontend/src/plonk/keygen.rs b/halo2_frontend/src/plonk/keygen.rs index 94c44c1f43..8e9b829033 100644 --- a/halo2_frontend/src/plonk/keygen.rs +++ b/halo2_frontend/src/plonk/keygen.rs @@ -10,14 +10,14 @@ use crate::plonk::{ /// Assembly to be used in circuit synthesis. #[derive(Debug)] -pub struct Assembly { - pub k: u32, - pub fixed: Vec>>, - pub permutation: permutation::Assembly, - pub selectors: Vec>, +pub(crate) struct Assembly { + pub(crate) k: u32, + pub(crate) fixed: Vec>>, + pub(crate) permutation: permutation::Assembly, + pub(crate) selectors: Vec>, // A range of available rows for assignment and copies. - pub usable_rows: Range, - pub _marker: std::marker::PhantomData, + pub(crate) usable_rows: Range, + pub(crate) _marker: std::marker::PhantomData, } impl Assignment for Assembly { diff --git a/halo2_frontend/src/plonk/permutation.rs b/halo2_frontend/src/plonk/permutation.rs index 20444df083..30e0a5bc74 100644 --- a/halo2_frontend/src/plonk/permutation.rs +++ b/halo2_frontend/src/plonk/permutation.rs @@ -62,14 +62,14 @@ impl Argument { } #[derive(Clone, Debug)] -pub struct Assembly { +pub(crate) struct Assembly { pub(crate) n: usize, pub(crate) columns: Vec>, pub(crate) copies: Vec<(Cell, Cell)>, } impl Assembly { - pub fn new(n: usize, p: &Argument) -> Self { + pub(crate) fn new(n: usize, p: &Argument) -> Self { Self { n, columns: p.columns.clone(), @@ -77,7 +77,7 @@ impl Assembly { } } - pub fn copy( + pub(crate) fn copy( &mut self, left_column: Column, left_row: usize, diff --git a/halo2_frontend/src/plonk/shuffle.rs b/halo2_frontend/src/plonk/shuffle.rs index 7bf1052208..5d379fb659 100644 --- a/halo2_frontend/src/plonk/shuffle.rs +++ b/halo2_frontend/src/plonk/shuffle.rs @@ -32,7 +32,7 @@ impl Argument { } } - pub fn required_degree(&self) -> usize { + pub(crate) fn required_degree(&self) -> usize { assert_eq!(self.input_expressions.len(), self.shuffle_expressions.len()); let mut input_degree = 1; diff --git a/halo2_middleware/src/expression.rs b/halo2_middleware/src/expression.rs index 43a92efee8..217d26c321 100644 --- a/halo2_middleware/src/expression.rs +++ b/halo2_middleware/src/expression.rs @@ -65,7 +65,7 @@ impl Expression { } } - fn write_identifier(&self, writer: &mut W) -> std::io::Result<()> { + pub fn write_identifier(&self, writer: &mut W) -> std::io::Result<()> { match self { Expression::Constant(scalar) => write!(writer, "{scalar:?}"), Expression::Var(v) => v.write_identifier(writer), @@ -122,11 +122,6 @@ impl Expression { Expression::Product(a, b) => a.complexity() + b.complexity() + 30, } } - - /// Square this expression. - pub fn square(self) -> Self { - self.clone() * self - } } impl Neg for Expression {