Skip to content

Commit

Permalink
refactor: move some types from common to backend (post-split)(plonk-0) (
Browse files Browse the repository at this point in the history
privacy-scaling-explorations#287)

* refactor: move "Challenge*" from "halo2_common" to "halo2_backend"

* refactor: move the "transcript" from "halo2_common" to "halo2_backend"

* chore: correct the imports
  • Loading branch information
duguorong009 authored Feb 28, 2024
1 parent 06d7007 commit 1650a0b
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion halo2_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub mod arithmetic;
mod helpers;
pub mod plonk;
pub mod poly;
pub mod transcript;

// Internal re-exports
pub use halo2_common::circuit;
pub use halo2_common::multicore;
pub use halo2_common::transcript;
pub use halo2_common::SerdeFormat;
22 changes: 21 additions & 1 deletion halo2_backend/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::poly::{
Coeff, EvaluationDomain, ExtendedLagrangeCoeff, LagrangeCoeff, PinnedEvaluationDomain,
Polynomial,
};
use crate::transcript::{ChallengeScalar, EncodedChallenge, Transcript};
use evaluation::Evaluator;
use halo2_common::plonk::{Circuit, ConstraintSystem, PinnedConstraintSystem};
use halo2_common::transcript::{EncodedChallenge, Transcript};
use halo2_common::SerdeFormat;

use std::io;
Expand Down Expand Up @@ -455,3 +455,23 @@ impl<C: CurveAffine> VerifyingKey<C> {
&self.domain
}
}

#[derive(Clone, Copy, Debug)]
pub struct Theta;
pub type ChallengeTheta<F> = ChallengeScalar<F, Theta>;

#[derive(Clone, Copy, Debug)]
pub struct Beta;
pub type ChallengeBeta<F> = ChallengeScalar<F, Beta>;

#[derive(Clone, Copy, Debug)]
pub struct Gamma;
pub type ChallengeGamma<F> = ChallengeScalar<F, Gamma>;

#[derive(Clone, Copy, Debug)]
pub struct Y;
pub type ChallengeY<F> = ChallengeScalar<F, Y>;

#[derive(Clone, Copy, Debug)]
pub struct X;
pub type ChallengeX<F> = ChallengeScalar<F, X>;
5 changes: 2 additions & 3 deletions halo2_backend/src/plonk/lookup/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::Argument;
use crate::plonk::evaluation::evaluate;
use crate::{
arithmetic::{eval_polynomial, parallelize, CurveAffine},
plonk::{ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX},
poly::{
commitment::{Blind, Params},
Coeff, EvaluationDomain, LagrangeCoeff, Polynomial, ProverQuery,
Expand All @@ -13,9 +14,7 @@ use group::{
ff::{BatchInvert, Field},
Curve,
};
use halo2_common::plonk::{
ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, Error, Expression,
};
use halo2_common::plonk::{Error, Expression};
use halo2_middleware::ff::WithSmallOrderMulGroup;
use halo2_middleware::poly::Rotation;
use rand_core::RngCore;
Expand Down
6 changes: 2 additions & 4 deletions halo2_backend/src/plonk/lookup/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use std::iter;
use super::Argument;
use crate::{
arithmetic::CurveAffine,
plonk::VerifyingKey,
plonk::{ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, VerifyingKey},
poly::{commitment::MSM, VerifierQuery},
transcript::{EncodedChallenge, TranscriptRead},
};
use halo2_common::plonk::{
ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, Error, Expression,
};
use halo2_common::plonk::{Error, Expression};
use halo2_middleware::ff::Field;
use halo2_middleware::poly::Rotation;

Expand Down
4 changes: 2 additions & 2 deletions halo2_backend/src/plonk/permutation/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use std::iter::{self, ExactSizeIterator};
use super::Argument;
use crate::{
arithmetic::{eval_polynomial, parallelize, CurveAffine},
plonk::{self, permutation::ProvingKey},
plonk::{self, permutation::ProvingKey, ChallengeBeta, ChallengeGamma, ChallengeX},
poly::{
commitment::{Blind, Params},
Coeff, ExtendedLagrangeCoeff, LagrangeCoeff, Polynomial, ProverQuery,
},
transcript::{EncodedChallenge, TranscriptWrite},
};
use halo2_common::plonk::{ChallengeBeta, ChallengeGamma, ChallengeX, Error};
use halo2_common::plonk::Error;
use halo2_middleware::circuit::Any;
use halo2_middleware::poly::Rotation;

Expand Down
4 changes: 2 additions & 2 deletions halo2_backend/src/plonk/permutation/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::iter;
use super::{Argument, VerifyingKey};
use crate::{
arithmetic::CurveAffine,
plonk::{self},
plonk::{self, ChallengeBeta, ChallengeGamma, ChallengeX},
poly::{commitment::MSM, VerifierQuery},
transcript::{EncodedChallenge, TranscriptRead},
};
use halo2_common::plonk::{ChallengeBeta, ChallengeGamma, ChallengeX, Error};
use halo2_common::plonk::Error;
use halo2_middleware::circuit::Any;
use halo2_middleware::poly::Rotation;

Expand Down
11 changes: 6 additions & 5 deletions halo2_backend/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ 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;
use crate::plonk::{lookup, permutation, shuffle, vanishing, ProvingKey};
use crate::plonk::{
lookup, permutation, shuffle, vanishing, ChallengeBeta, ChallengeGamma, ChallengeTheta,
ChallengeX, ChallengeY, ProvingKey,
};
use crate::poly::{
commitment::{Blind, CommitmentScheme, Params, Prover},
Basis, Coeff, LagrangeCoeff, Polynomial, ProverQuery,
};

use crate::transcript::{EncodedChallenge, TranscriptWrite};
use group::prime::PrimeCurveAffine;
use halo2_common::plonk::{
circuit::sealed, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error,
};
use halo2_common::transcript::{EncodedChallenge, TranscriptWrite};
use halo2_common::plonk::{circuit::sealed, Error};

/// Collection of instance data used during proving for a single circuit proof.
#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion halo2_backend/src/plonk/shuffle/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use super::Argument;
use crate::plonk::evaluation::evaluate;
use crate::{
arithmetic::{eval_polynomial, parallelize, CurveAffine},
plonk::{ChallengeGamma, ChallengeTheta, ChallengeX},
poly::{
commitment::{Blind, Params},
Coeff, EvaluationDomain, LagrangeCoeff, Polynomial, ProverQuery,
},
transcript::{EncodedChallenge, TranscriptWrite},
};
use group::{ff::BatchInvert, Curve};
use halo2_common::plonk::{ChallengeGamma, ChallengeTheta, ChallengeX, Error, Expression};
use halo2_common::plonk::{Error, Expression};
use halo2_middleware::ff::WithSmallOrderMulGroup;
use halo2_middleware::poly::Rotation;
use rand_core::RngCore;
Expand Down
4 changes: 2 additions & 2 deletions halo2_backend/src/plonk/shuffle/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::iter;
use super::Argument;
use crate::{
arithmetic::CurveAffine,
plonk::VerifyingKey,
plonk::{ChallengeGamma, ChallengeTheta, ChallengeX, VerifyingKey},
poly::{commitment::MSM, VerifierQuery},
transcript::{EncodedChallenge, TranscriptRead},
};
use halo2_common::plonk::{ChallengeGamma, ChallengeTheta, ChallengeX, Error, Expression};
use halo2_common::plonk::{Error, Expression};
use halo2_middleware::ff::Field;
use halo2_middleware::poly::Rotation;

Expand Down
3 changes: 2 additions & 1 deletion halo2_backend/src/plonk/vanishing/prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, iter};

use group::Curve;
use halo2_common::plonk::{ChallengeX, Error};
use halo2_common::plonk::Error;
use halo2_middleware::ff::Field;
use rand_chacha::ChaCha20Rng;
use rand_core::{RngCore, SeedableRng};
Expand All @@ -10,6 +10,7 @@ use super::Argument;
use crate::{
arithmetic::{eval_polynomial, parallelize, CurveAffine},
multicore::current_num_threads,
plonk::ChallengeX,
poly::{
commitment::{Blind, ParamsProver},
Coeff, EvaluationDomain, ExtendedLagrangeCoeff, Polynomial, ProverQuery,
Expand Down
4 changes: 2 additions & 2 deletions halo2_backend/src/plonk/vanishing/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::iter;

use halo2_common::plonk::{ChallengeX, ChallengeY, Error};
use halo2_common::plonk::Error;
use halo2_middleware::ff::Field;

use crate::{
arithmetic::CurveAffine,
plonk::VerifyingKey,
plonk::{ChallengeX, ChallengeY, VerifyingKey},
poly::{
commitment::{Params, MSM},
VerifierQuery,
Expand Down
4 changes: 1 addition & 3 deletions halo2_backend/src/plonk/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use group::Curve;
use halo2_common::plonk::{
ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error,
};
use halo2_middleware::ff::{Field, FromUniformBytes, WithSmallOrderMulGroup};
use std::iter;

Expand All @@ -10,6 +7,7 @@ use crate::arithmetic::compute_inner_product;
use crate::plonk::lookup::verifier::lookup_read_permuted_commitments;
use crate::plonk::permutation::verifier::permutation_read_product_commitments;
use crate::plonk::shuffle::verifier::shuffle_read_product_commitment;
use crate::plonk::{ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error};
use crate::poly::commitment::{CommitmentScheme, Verifier};
use crate::poly::VerificationStrategy;
use crate::poly::{
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion halo2_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod circuit;
pub use halo2curves;
pub mod multicore;
pub mod plonk;
pub mod transcript;

pub mod helpers;
pub use helpers::SerdeFormat;
Expand Down
21 changes: 0 additions & 21 deletions halo2_common/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! [halo]: https://eprint.iacr.org/2019/1021
//! [plonk]: https://eprint.iacr.org/2019/953

use crate::transcript::ChallengeScalar;
use halo2_middleware::circuit::{Advice, Fixed, Instance};
use halo2_middleware::ff::Field;
use halo2_middleware::poly::Rotation;
Expand Down Expand Up @@ -443,26 +442,6 @@ impl Queries {
}
}

#[derive(Clone, Copy, Debug)]
pub struct Theta;
pub type ChallengeTheta<F> = ChallengeScalar<F, Theta>;

#[derive(Clone, Copy, Debug)]
pub struct Beta;
pub type ChallengeBeta<F> = ChallengeScalar<F, Beta>;

#[derive(Clone, Copy, Debug)]
pub struct Gamma;
pub type ChallengeGamma<F> = ChallengeScalar<F, Gamma>;

#[derive(Clone, Copy, Debug)]
pub struct Y;
pub type ChallengeY<F> = ChallengeScalar<F, Y>;

#[derive(Clone, Copy, Debug)]
pub struct X;
pub type ChallengeX<F> = ChallengeScalar<F, X>;

#[cfg(test)]
mod tests {
use halo2curves::pasta::Fp;
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub mod poly {
/// This module contains utilities and traits for dealing with Fiat-Shamir
/// transcripts.
pub mod transcript {
pub use halo2_common::transcript::{
pub use halo2_backend::transcript::{
Blake2bRead, Blake2bWrite, Challenge255, EncodedChallenge, TranscriptReadBuffer,
TranscriptWriterBuffer,
};
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::poly::commitment::{CommitmentScheme, Params, Prover};
use halo2_backend::plonk::{prover::ProverV2, ProvingKey};
use halo2_backend::transcript::{EncodedChallenge, TranscriptWrite};
use halo2_common::plonk::{circuit::Circuit, Error};
use halo2_common::transcript::{EncodedChallenge, TranscriptWrite};
use halo2_frontend::circuit::{compile_circuit, WitnessCalculator};
use halo2_middleware::ff::{FromUniformBytes, WithSmallOrderMulGroup};
use rand_core::RngCore;
Expand Down
16 changes: 9 additions & 7 deletions halo2_proofs/tests/frontend_backend_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

use halo2_backend::plonk::{
keygen::{keygen_pk_v2, keygen_vk_v2},
prover::ProverV2Single,
verifier::{verify_proof, verify_proof_single},
use halo2_backend::{
plonk::{
keygen::{keygen_pk_v2, keygen_vk_v2},
prover::ProverV2Single,
verifier::{verify_proof, verify_proof_single},
},
transcript::{
Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer,
},
};
use halo2_common::{
circuit::{AssignedCell, Layouter, Region, SimpleFloorPlanner, Value},
plonk::{
circuit::{Challenge, Column},
Circuit, ConstraintSystem, Error, Expression, FirstPhase, SecondPhase, Selector,
},
transcript::{
Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer,
},
};
use halo2_frontend::{
circuit::{compile_circuit, WitnessCalculator},
Expand Down

0 comments on commit 1650a0b

Please sign in to comment.