diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42ed2c67f..da5ae79a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: crate-ci/typos@v1.24.6 + - uses: crate-ci/typos@v1.26.0 with: config: ./typos.toml isolated: true diff --git a/halo2_backend/src/arithmetic.rs b/halo2_backend/src/arithmetic.rs index ebdcae1e5..d44ef4f93 100644 --- a/halo2_backend/src/arithmetic.rs +++ b/halo2_backend/src/arithmetic.rs @@ -86,7 +86,6 @@ pub(crate) fn eval_polynomial(poly: &[F], point: F) -> F { /// /// This function will panic if the two vectors are not the same size. pub(crate) fn compute_inner_product(a: &[F], b: &[F]) -> F { - // TODO: parallelize? assert_eq!(a.len(), b.len()); let mut acc = F::ZERO; diff --git a/halo2_backend/src/plonk/circuit.rs b/halo2_backend/src/plonk/circuit.rs index 5dd6aa06e..de9c6973f 100644 --- a/halo2_backend/src/plonk/circuit.rs +++ b/halo2_backend/src/plonk/circuit.rs @@ -4,15 +4,12 @@ use halo2_middleware::expression::{Expression, Variable}; use halo2_middleware::poly::Rotation; use halo2_middleware::{lookup, permutation::ArgumentMid, shuffle}; -// TODO: Reuse ColumnMid inside this. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct QueryBack { /// Query index pub(crate) index: usize, - /// Column index - pub(crate) column_index: usize, - /// The type of the column. - pub(crate) column_type: Any, + /// Column + pub(crate) column: ColumnMid, /// Rotation of this query pub(crate) rotation: Rotation, } diff --git a/halo2_backend/src/plonk/evaluation.rs b/halo2_backend/src/plonk/evaluation.rs index f22f6542b..9e6dc0b74 100644 --- a/halo2_backend/src/plonk/evaluation.rs +++ b/halo2_backend/src/plonk/evaluation.rs @@ -573,7 +573,7 @@ impl Evaluator { parallelize(&mut values, |values, start| { let input_evaluator = &self.shuffles[2 * n]; let shuffle_evaluator = &self.shuffles[2 * n + 1]; - let mut eval_data_input = shuffle_evaluator.instance(); + let mut eval_data_input = input_evaluator.instance(); let mut eval_data_shuffle = shuffle_evaluator.instance(); for (i, value) in values.iter_mut().enumerate() { let idx = start + i; @@ -701,17 +701,17 @@ impl GraphEvaluator { ExpressionBack::Constant(scalar) => self.add_constant(scalar), ExpressionBack::Var(VarBack::Query(query)) => { let rot_idx = self.add_rotation(&query.rotation); - match query.column_type { + match query.column.column_type { Any::Fixed => self.add_calculation(Calculation::Store(ValueSource::Fixed( - query.column_index, + query.column.index, rot_idx, ))), Any::Advice => self.add_calculation(Calculation::Store(ValueSource::Advice( - query.column_index, + query.column.index, rot_idx, ))), Any::Instance => self.add_calculation(Calculation::Store( - ValueSource::Instance(query.column_index, rot_idx), + ValueSource::Instance(query.column.index, rot_idx), )), } } @@ -863,10 +863,10 @@ pub(crate) fn evaluate( VarBack::Challenge(challenge) => challenges[challenge.index()], VarBack::Query(query) => { let rot_idx = get_rotation_idx(idx, query.rotation.0, rot_scale, isize); - match query.column_type { - Any::Fixed => fixed[query.column_index][rot_idx], - Any::Advice => advice[query.column_index][rot_idx], - Any::Instance => instance[query.column_index][rot_idx], + match query.column.column_type { + Any::Fixed => fixed[query.column.index][rot_idx], + Any::Advice => advice[query.column.index][rot_idx], + Any::Instance => instance[query.column.index][rot_idx], } } }, @@ -883,7 +883,7 @@ pub(crate) fn evaluate( mod test { use crate::plonk::circuit::{ExpressionBack, QueryBack, VarBack}; use crate::poly::LagrangeCoeff; - use halo2_middleware::circuit::{Any, ChallengeMid}; + use halo2_middleware::circuit::{Any, ChallengeMid, ColumnMid}; use halo2_middleware::poly::Rotation; use halo2curves::pasta::pallas::{Affine, Scalar}; @@ -954,8 +954,10 @@ mod test { check_expr( ExpressionBack::Var(Query(QueryBack { index: 0, - column_index: col, - column_type: Any::Fixed, + column: ColumnMid { + index: col, + column_type: Any::Fixed, + }, rotation: Rotation(rot), })), expected, @@ -965,8 +967,10 @@ mod test { check_expr( ExpressionBack::Var(Query(QueryBack { index: 0, - column_index: col, - column_type: Any::Advice, + column: ColumnMid { + index: col, + column_type: Any::Advice, + }, rotation: Rotation(rot), })), expected, @@ -976,8 +980,10 @@ mod test { check_expr( ExpressionBack::Var(Query(QueryBack { index: 0, - column_index: col, - column_type: Any::Instance, + column: ColumnMid { + index: col, + column_type: Any::Instance, + }, rotation: Rotation(rot), })), expected, @@ -1007,8 +1013,10 @@ mod test { let two = || { Box::new(ExpressionBack::::Var(Query(QueryBack { index: 0, - column_index: 0, - column_type: Any::Fixed, + column: ColumnMid { + index: 0, + column_type: Any::Fixed, + }, rotation: Rotation(0), }))) }; @@ -1016,8 +1024,10 @@ mod test { let three = || { Box::new(ExpressionBack::::Var(Query(QueryBack { index: 0, - column_index: 0, - column_type: Any::Fixed, + column: ColumnMid { + index: 0, + column_type: Any::Fixed, + }, rotation: Rotation(1), }))) }; diff --git a/halo2_backend/src/plonk/keygen.rs b/halo2_backend/src/plonk/keygen.rs index 2771ee09d..028812dd1 100644 --- a/halo2_backend/src/plonk/keygen.rs +++ b/halo2_backend/src/plonk/keygen.rs @@ -218,8 +218,10 @@ impl QueriesMap { let index = self.add(column, query.rotation); ExpressionBack::Var(VarBack::Query(QueryBack { index, - column_index: query.column_index, - column_type: query.column_type, + column: ColumnMid { + index: query.column_index, + column_type: query.column_type, + }, rotation: query.rotation, })) } diff --git a/halo2_backend/src/plonk/lookup/verifier.rs b/halo2_backend/src/plonk/lookup/verifier.rs index aadf8cd0e..8f4443def 100644 --- a/halo2_backend/src/plonk/lookup/verifier.rs +++ b/halo2_backend/src/plonk/lookup/verifier.rs @@ -119,13 +119,13 @@ impl Evaluated { &|scalar| scalar, &|var| match var { VarBack::Challenge(challenge) => challenges[challenge.index], - VarBack::Query(QueryBack { - index, column_type, .. - }) => match column_type { - Any::Fixed => fixed_evals[index], - Any::Advice => advice_evals[index], - Any::Instance => instance_evals[index], - }, + VarBack::Query(QueryBack { index, column, .. }) => { + match column.column_type { + Any::Fixed => fixed_evals[index], + Any::Advice => advice_evals[index], + Any::Instance => instance_evals[index], + } + } }, &|a| -a, &|a, b| a + b, diff --git a/halo2_backend/src/plonk/permutation.rs b/halo2_backend/src/plonk/permutation.rs index f96e1271d..9de1a08be 100644 --- a/halo2_backend/src/plonk/permutation.rs +++ b/halo2_backend/src/plonk/permutation.rs @@ -6,8 +6,7 @@ use crate::{ helpers::{polynomial_slice_byte_length, read_polynomial_vec, write_polynomial_slice}, poly::{Coeff, ExtendedLagrangeCoeff, LagrangeCoeff, Polynomial}, }; -// TODO: Remove the renaming -pub use halo2_middleware::permutation::ArgumentMid as Argument; +pub use halo2_middleware::permutation::ArgumentMid; use std::io; @@ -34,7 +33,7 @@ impl VerifyingKey { pub(crate) fn read( reader: &mut R, - argument: &Argument, + argument: &ArgumentMid, format: SerdeFormat, ) -> io::Result where diff --git a/halo2_backend/src/plonk/permutation/keygen.rs b/halo2_backend/src/plonk/permutation/keygen.rs index 261d07386..f2587c35b 100644 --- a/halo2_backend/src/plonk/permutation/keygen.rs +++ b/halo2_backend/src/plonk/permutation/keygen.rs @@ -2,7 +2,7 @@ use group::Curve; use halo2_middleware::ff::{Field, PrimeField}; use halo2_middleware::zal::impls::H2cEngine; -use super::{Argument, ProvingKey, VerifyingKey}; +use super::{ProvingKey, VerifyingKey}; use crate::{ arithmetic::{parallelize, CurveAffine}, plonk::Error, @@ -40,7 +40,7 @@ impl Assembly { Ok(assembly) } - pub(crate) fn new(n: usize, p: &Argument) -> Self { + pub(crate) fn new(n: usize, p: &ArgumentMid) -> Self { // Initialize the copy vector to keep track of copy constraints in all // the permutation arguments. let mut columns = vec![]; @@ -121,7 +121,7 @@ impl Assembly { self, params: &P, domain: &EvaluationDomain, - p: &Argument, + p: &ArgumentMid, ) -> VerifyingKey { build_vk(params, domain, p, |i, j| self.mapping[i][j]) } @@ -130,7 +130,7 @@ impl Assembly { self, params: &P, domain: &EvaluationDomain, - p: &Argument, + p: &ArgumentMid, ) -> ProvingKey { build_pk(params, domain, p, |i, j| self.mapping[i][j]) } @@ -139,7 +139,7 @@ impl Assembly { pub(crate) fn build_pk>( params: &P, domain: &EvaluationDomain, - p: &Argument, + p: &ArgumentMid, mapping: impl Fn(usize, usize) -> (usize, usize) + Sync, ) -> ProvingKey { // Compute [omega^0, omega^1, ..., omega^{params.n - 1}] @@ -215,7 +215,7 @@ pub(crate) fn build_pk>( pub(crate) fn build_vk>( params: &P, domain: &EvaluationDomain, - p: &Argument, + p: &ArgumentMid, mapping: impl Fn(usize, usize) -> (usize, usize) + Sync, ) -> VerifyingKey { // Compute [omega^0, omega^1, ..., omega^{params.n - 1}] diff --git a/halo2_backend/src/plonk/permutation/prover.rs b/halo2_backend/src/plonk/permutation/prover.rs index a3ae97f76..3d40c4130 100644 --- a/halo2_backend/src/plonk/permutation/prover.rs +++ b/halo2_backend/src/plonk/permutation/prover.rs @@ -2,12 +2,11 @@ use group::{ ff::{BatchInvert, Field}, Curve, }; -use halo2_middleware::zal::traits::MsmAccel; use halo2_middleware::{ff::PrimeField, zal::impls::PlonkEngine}; +use halo2_middleware::{permutation::ArgumentMid, zal::traits::MsmAccel}; use rand_core::RngCore; use std::iter::{self, ExactSizeIterator}; -use super::Argument; use crate::{ arithmetic::{eval_polynomial, parallelize, CurveAffine}, plonk::{self, permutation::ProvingKey, ChallengeBeta, ChallengeGamma, ChallengeX, Error}, @@ -61,7 +60,7 @@ pub(in crate::plonk) fn permutation_commit< M: MsmAccel, >( engine: &PlonkEngine, - arg: &Argument, + arg: &ArgumentMid, params: &P, pk: &plonk::ProvingKey, pkey: &ProvingKey, diff --git a/halo2_backend/src/plonk/permutation/verifier.rs b/halo2_backend/src/plonk/permutation/verifier.rs index 6fead2ffc..a24487dc3 100644 --- a/halo2_backend/src/plonk/permutation/verifier.rs +++ b/halo2_backend/src/plonk/permutation/verifier.rs @@ -1,7 +1,10 @@ -use halo2_middleware::ff::{Field, PrimeField}; +use halo2_middleware::{ + ff::{Field, PrimeField}, + permutation::ArgumentMid, +}; use std::iter; -use super::{Argument, VerifyingKey}; +use super::VerifyingKey; use crate::{ arithmetic::CurveAffine, plonk::{self, ChallengeBeta, ChallengeGamma, ChallengeX, Error}, @@ -35,7 +38,7 @@ pub(crate) fn permutation_read_product_commitments< E: EncodedChallenge, T: TranscriptRead, >( - arg: &Argument, + arg: &ArgumentMid, vk: &plonk::VerifyingKey, transcript: &mut T, ) -> Result, Error> { @@ -102,7 +105,7 @@ impl Evaluated { pub(in crate::plonk) fn expressions<'a>( &'a self, vk: &'a plonk::VerifyingKey, - p: &'a Argument, + p: &'a ArgumentMid, common: &'a CommonEvaluated, advice_evals: &'a [C::Scalar], fixed_evals: &'a [C::Scalar], diff --git a/halo2_backend/src/plonk/shuffle/verifier.rs b/halo2_backend/src/plonk/shuffle/verifier.rs index 1462e4734..daddc2e11 100644 --- a/halo2_backend/src/plonk/shuffle/verifier.rs +++ b/halo2_backend/src/plonk/shuffle/verifier.rs @@ -78,13 +78,13 @@ impl Evaluated { &|scalar| scalar, &|var| match var { VarBack::Challenge(challenge) => challenges[challenge.index], - VarBack::Query(QueryBack { - index, column_type, .. - }) => match column_type { - Any::Fixed => fixed_evals[index], - Any::Advice => advice_evals[index], - Any::Instance => instance_evals[index], - }, + VarBack::Query(QueryBack { index, column, .. }) => { + match column.column_type { + Any::Fixed => fixed_evals[index], + Any::Advice => advice_evals[index], + Any::Instance => instance_evals[index], + } + } }, &|a| -a, &|a, b| a + b, diff --git a/halo2_backend/src/plonk/vanishing/prover.rs b/halo2_backend/src/plonk/vanishing/prover.rs index 691a55de6..11b034bbd 100644 --- a/halo2_backend/src/plonk/vanishing/prover.rs +++ b/halo2_backend/src/plonk/vanishing/prover.rs @@ -111,7 +111,12 @@ impl Committed { let h_poly = domain.divide_by_vanishing_poly(h_poly); // Obtain final h(X) polynomial - let h_poly = domain.extended_to_coeff(h_poly); + let mut h_poly = domain.extended_to_coeff(h_poly); + + // Truncate it to match the size of the quotient polynomial; the + // evaluation domain might be slightly larger than necessary because + // it always lies on a power-of-two boundary. + h_poly.truncate(((1u64 << domain.k()) as usize) * domain.get_quotient_poly_degree()); // Split h(X) up into pieces let h_pieces = h_poly diff --git a/halo2_backend/src/plonk/verifier.rs b/halo2_backend/src/plonk/verifier.rs index bfefcab62..3e62576fc 100644 --- a/halo2_backend/src/plonk/verifier.rs +++ b/halo2_backend/src/plonk/verifier.rs @@ -314,7 +314,7 @@ where gate.poly.evaluate( &|scalar| scalar, &|var| match var { - VarBack::Query(query) => match query.column_type { + VarBack::Query(query) => match query.column.column_type { Any::Fixed => fixed_evals[query.index], Any::Advice => advice_evals[query.index], Any::Instance => instance_evals[query.index], diff --git a/halo2_backend/src/poly/domain.rs b/halo2_backend/src/poly/domain.rs index 5ca352e6c..706892677 100644 --- a/halo2_backend/src/poly/domain.rs +++ b/halo2_backend/src/poly/domain.rs @@ -328,7 +328,6 @@ impl> EvaluationDomain { /// /// This function will panic if the provided vector is not the correct /// length. - // TODO/FIXME: caller should be responsible for truncating pub fn extended_to_coeff(&self, mut a: Polynomial) -> Vec { assert_eq!(a.values.len(), self.extended_len()); @@ -344,12 +343,6 @@ impl> EvaluationDomain { // transformation we performed earlier. self.distribute_powers_zeta(&mut a.values, false); - // Truncate it to match the size of the quotient polynomial; the - // evaluation domain might be slightly larger than necessary because - // it always lies on a power-of-two boundary. - a.values - .truncate((self.n * self.quotient_poly_degree) as usize); - a.values } diff --git a/halo2_proofs/tests/compress_selectors.rs b/halo2_proofs/tests/compress_selectors.rs index 1808c7969..246b69d0d 100644 --- a/halo2_proofs/tests/compress_selectors.rs +++ b/halo2_proofs/tests/compress_selectors.rs @@ -494,13 +494,13 @@ fn test_key_compression() -> Result<(), halo2_proofs::plonk::Error> { // vk & pk keygen both WITH compression test_result( || test_mycircuit(true, true).expect("should pass"), - "acae50508de5ead584170dd83b139daf40e1026b6debbb78eb05d515173fc2dd", + "44130c6388df3d99263be8da4a280b426dc05f1f315d35d3827347761534bf08", ); // vk & pk keygen both WITHOUT compression test_result( || test_mycircuit(false, false).expect("should pass"), - "f9c99bd341705ac6a13724a526dd28df0bac1c745e0cde40ab39cab3e1b95309", + "9f58d7a0088fa2c614e8d67bd238f61bc160300e72f5ffd5d52485ed5fb06752", ); Ok(()) diff --git a/halo2_proofs/tests/frontend_backend_split.rs b/halo2_proofs/tests/frontend_backend_split.rs index cd8004e0b..c5c90c152 100644 --- a/halo2_proofs/tests/frontend_backend_split.rs +++ b/halo2_proofs/tests/frontend_backend_split.rs @@ -545,7 +545,7 @@ fn test_mycircuit_full_legacy() { proof }, - "78aadfd46b5cc58b90d832ee47e4df57af3dfc28d1457c4ceeb5d0323a72f130", + "44a4bca99aec990b2f382d9c2e1dcc8d8e254d49c2e47cab7556918105346474", ); } @@ -626,6 +626,6 @@ fn test_mycircuit_full_split() { proof }, - "78aadfd46b5cc58b90d832ee47e4df57af3dfc28d1457c4ceeb5d0323a72f130", + "44a4bca99aec990b2f382d9c2e1dcc8d8e254d49c2e47cab7556918105346474", ); } diff --git a/halo2_proofs/tests/plonk_api.rs b/halo2_proofs/tests/plonk_api.rs index 896fc7ca2..bd4164143 100644 --- a/halo2_proofs/tests/plonk_api.rs +++ b/halo2_proofs/tests/plonk_api.rs @@ -602,7 +602,7 @@ fn plonk_api() { proof }, - "f87ba1010dede5a2148ed94403ca12a566d3154ebb12ccb6c20a330e9b280af8", + "da790e980ea5a871e7b713f781fb7d6905a321d25427dc54b3accac2aa0d8860", ); } @@ -639,7 +639,7 @@ fn plonk_api() { proof }, - "0fc67d890faef0ef8ea7ef680cc566b2ab7dabef12fcceb74d3655a0fb08c708", + "88c7197240d5a8db1b51d82e7a2a6d49e8593d64aed624e2a72c2b75fbac0357", ); } diff --git a/halo2_proofs/tests/serialization.rs b/halo2_proofs/tests/serialization.rs index 1a6308597..1201761dc 100644 --- a/halo2_proofs/tests/serialization.rs +++ b/halo2_proofs/tests/serialization.rs @@ -219,6 +219,6 @@ fn test_serialization() { proof }, - "b51ea51140e9fbd1f0c665c788bab9e4b3e648ac674b6d07a24ca0844f0962ad", + "0be5dca07d18b9ad4ccfbf27fc58a7359d1909e5f762cf5df07ce02d0ab96f94", ); } diff --git a/halo2_proofs/tests/shuffle.rs b/halo2_proofs/tests/shuffle.rs index b56528dc0..462955c23 100644 --- a/halo2_proofs/tests/shuffle.rs +++ b/halo2_proofs/tests/shuffle.rs @@ -326,7 +326,7 @@ fn test_shuffle() { halo2_debug::test_result( || test_prover::(K, circuit.clone(), true), - "513e85f35c818a35670bda274f5d5fe73e3a62948a43b0cdcdc317c606a3a2e3", + "2a91b131950f5c9d9bf8d6486caf3870edcdb772d0021bead607076497762fac", ); #[cfg(not(feature = "sanity-checks"))] diff --git a/halo2_proofs/tests/shuffle_api.rs b/halo2_proofs/tests/shuffle_api.rs index 92cd023ea..d3d26ee9f 100644 --- a/halo2_proofs/tests/shuffle_api.rs +++ b/halo2_proofs/tests/shuffle_api.rs @@ -211,6 +211,6 @@ fn test_shuffle_api() { halo2_debug::test_result( || test_prover(K, circuit, true), - "c4a5b69cf43d3e84ee311a2801ca194b756f2b21437756bd54204113d42e6f07", + "c8d44278f8b6ed8e15c9bb34c81a1d634398152d3a09a6589acb65d806a33b0d", ); } diff --git a/halo2_proofs/tests/vector-ops-unblinded.rs b/halo2_proofs/tests/vector-ops-unblinded.rs index e268e098f..2ede2017c 100644 --- a/halo2_proofs/tests/vector-ops-unblinded.rs +++ b/halo2_proofs/tests/vector-ops-unblinded.rs @@ -536,13 +536,13 @@ fn test_vector_ops_unbinded() { // the commitments will be the first columns of the proof transcript so we can compare them easily let proof_1 = halo2_debug::test_result( || test_prover(k, mul_circuit.clone(), true, c_mul.clone()), - "4cadce029aad5ba7ceafa4052656926698e9308932244e90b7ec63adffa5ba6f", + "1d0e66c45ff1868d2fa3de6cc4b7aa0f8c9d761929ed26c1307251a33f9c5950", ); // the commitments will be the first columns of the proof transcript so we can compare them easily let proof_2 = halo2_debug::test_result( || test_prover(k, add_circuit.clone(), true, c_add.clone()), - "c791ad2a321ef9d8ab8dd7f111e5c6599be63c0146fae664267407b02afb8c82", + "4d64c68078008db27906a54ecb25fb8f8b41d85850aeb2db136072baff266f3e", ); // the commitments will be the first columns of the proof transcript so we can compare them easily