Skip to content

Commit

Permalink
refactor: remove 'params from Params/ProverParams
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed Apr 25, 2024
1 parent 835d84e commit af68bf3
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 56 deletions.
6 changes: 3 additions & 3 deletions halo2_backend/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn keygen_vk<'params, C, P>(
) -> Result<VerifyingKey<C>, Error>
where
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
C::Scalar: FromUniformBytes<64>,
{
let cs_mid = &circuit.cs;
Expand Down Expand Up @@ -88,14 +88,14 @@ where
}

/// Generate a `ProvingKey` from a `VerifyingKey` and an instance of `CompiledCircuit`.
pub fn keygen_pk<'params, C, P>(
pub fn keygen_pk<C, P>(
params: &P,
vk: VerifyingKey<C>,
circuit: &CompiledCircuit<C::Scalar>,
) -> Result<ProvingKey<C>, Error>
where
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
{
let cs = &circuit.cs;

Expand Down
8 changes: 3 additions & 5 deletions halo2_backend/src/plonk/lookup/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ pub(in crate::plonk) struct Evaluated<C: CurveAffine> {
#[allow(clippy::too_many_arguments)]
pub(in crate::plonk) fn lookup_commit_permuted<
'a,
'params: 'a,
F: WithSmallOrderMulGroup<3>,
C,
P: Params<'params, C>,
P: Params<C>,
E: EncodedChallenge<C>,
R: RngCore,
T: TranscriptWrite<C, E>,
Expand Down Expand Up @@ -170,8 +169,7 @@ impl<C: CurveAffine> Permuted<C> {
/// added to the Lookup and finally returned by the method.
#[allow(clippy::too_many_arguments)]
pub(in crate::plonk) fn commit_product<
'params,
P: Params<'params, C>,
P: Params<C>,
E: EncodedChallenge<C>,
R: RngCore,
T: TranscriptWrite<C, E>,
Expand Down Expand Up @@ -397,7 +395,7 @@ type ExpressionPair<F> = (Polynomial<F, LagrangeCoeff>, Polynomial<F, LagrangeCo
/// - the first row in a sequence of like values in A' is the row
/// that has the corresponding value in S'.
/// This method returns (A', S') if no errors are encountered.
fn permute_expression_pair<'params, C: CurveAffine, P: Params<'params, C>, R: RngCore>(
fn permute_expression_pair<C: CurveAffine, P: Params<C>, R: RngCore>(
pk: &ProvingKey<C>,
params: &P,
domain: &EvaluationDomain<C::Scalar>,
Expand Down
8 changes: 4 additions & 4 deletions halo2_backend/src/plonk/permutation/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Assembly {
Ok(())
}

pub(crate) fn build_vk<'params, C: CurveAffine, P: Params<'params, C>>(
pub(crate) fn build_vk<C: CurveAffine, P: Params<C>>(
self,
params: &P,
domain: &EvaluationDomain<C::Scalar>,
Expand All @@ -126,7 +126,7 @@ impl Assembly {
build_vk(params, domain, p, |i, j| self.mapping[i][j])
}

pub(crate) fn build_pk<'params, C: CurveAffine, P: Params<'params, C>>(
pub(crate) fn build_pk<C: CurveAffine, P: Params<C>>(
self,
params: &P,
domain: &EvaluationDomain<C::Scalar>,
Expand All @@ -136,7 +136,7 @@ impl Assembly {
}
}

pub(crate) fn build_pk<'params, C: CurveAffine, P: Params<'params, C>>(
pub(crate) fn build_pk<C: CurveAffine, P: Params<C>>(
params: &P,
domain: &EvaluationDomain<C::Scalar>,
p: &Argument,
Expand Down Expand Up @@ -212,7 +212,7 @@ pub(crate) fn build_pk<'params, C: CurveAffine, P: Params<'params, C>>(
}
}

pub(crate) fn build_vk<'params, C: CurveAffine, P: Params<'params, C>>(
pub(crate) fn build_vk<C: CurveAffine, P: Params<C>>(
params: &P,
domain: &EvaluationDomain<C::Scalar>,
p: &Argument,
Expand Down
3 changes: 1 addition & 2 deletions halo2_backend/src/plonk/permutation/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ pub(crate) struct Evaluated<C: CurveAffine> {

#[allow(clippy::too_many_arguments)]
pub(in crate::plonk) fn permutation_commit<
'params,
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
E: EncodedChallenge<C>,
R: RngCore,
T: TranscriptWrite<C, E>,
Expand Down
5 changes: 2 additions & 3 deletions halo2_backend/src/plonk/shuffle/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(in crate::plonk) struct Evaluated<C: CurveAffine> {
/// - constructs A_compressed = \theta^{m-1} A_0 + theta^{m-2} A_1 + ... + \theta A_{m-2} + A_{m-1}
/// and S_compressed = \theta^{m-1} S_0 + theta^{m-2} S_1 + ... + \theta S_{m-2} + S_{m-1},
#[allow(clippy::too_many_arguments)]
fn shuffle_compress<'a, 'params: 'a, F: WithSmallOrderMulGroup<3>, C, P: Params<'params, C>>(
fn shuffle_compress<'a, 'params: 'a, F: WithSmallOrderMulGroup<3>, C, P: Params<C>>(
arg: &Argument<F>,
pk: &ProvingKey<C>,
params: &P,
Expand Down Expand Up @@ -96,10 +96,9 @@ where
#[allow(clippy::too_many_arguments)]
pub(in crate::plonk) fn shuffle_commit_product<
'a,
'params: 'a,
F: WithSmallOrderMulGroup<3>,
C,
P: Params<'params, C>,
P: Params<C>,
E: EncodedChallenge<C>,
R: RngCore,
T: TranscriptWrite<C, E>,
Expand Down
6 changes: 2 additions & 4 deletions halo2_backend/src/plonk/vanishing/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ pub(in crate::plonk) struct Evaluated<C: CurveAffine> {

impl<C: CurveAffine> Argument<C> {
pub(in crate::plonk) fn commit<
'params,
P: ParamsProver<'params, C>,
P: ParamsProver<C>,
E: EncodedChallenge<C>,
R: RngCore,
T: TranscriptWrite<C, E>,
Expand Down Expand Up @@ -100,8 +99,7 @@ impl<C: CurveAffine> Argument<C> {

impl<C: CurveAffine> Committed<C> {
pub(in crate::plonk) fn construct<
'params,
P: ParamsProver<'params, C>,
P: ParamsProver<C>,
E: EncodedChallenge<C>,
R: RngCore,
T: TranscriptWrite<C, E>,
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/plonk/vanishing/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
arithmetic::CurveAffine,
plonk::{ChallengeX, ChallengeY, Error, VerifyingKey},
poly::{
commitment::{Params, ParamsVerifier, MSM},
commitment::{ParamsVerifier, MSM},
VerifierQuery,
},
transcript::{read_n_points, EncodedChallenge, TranscriptRead},
Expand Down
15 changes: 7 additions & 8 deletions halo2_backend/src/poly/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait CommitmentScheme {
type Curve: CurveAffine<ScalarExt = Self::Scalar>;

/// Constant prover parameters
type ParamsProver: for<'params> ParamsProver<'params, Self::Curve>;
type ParamsProver: ParamsProver<Self::Curve>;

/// Constant verifier parameters
type ParamsVerifier: for<'params> ParamsVerifier<'params, Self::Curve>;
Expand All @@ -39,10 +39,7 @@ pub trait CommitmentScheme {
/// Common for Verifier and Prover.
///
/// Parameters for circuit synthesis and prover parameters.
pub trait Params<'params, C: CurveAffine>: Sized + Clone + Debug {
/// Multiscalar multiplication engine
type MSM: MSM<C> + 'params;

pub trait Params<C: CurveAffine>: Sized + Clone + Debug {
/// Logarithmic size of the circuit
fn k(&self) -> u32;

Expand All @@ -67,7 +64,7 @@ pub trait Params<'params, C: CurveAffine>: Sized + Clone + Debug {
}

/// Parameters for circuit synthesis and prover parameters.
pub trait ParamsProver<'params, C: CurveAffine>: Params<'params, C> {
pub trait ParamsProver<C: CurveAffine>: Params<C> {
/// Returns new instance of parameters
fn new(k: u32) -> Self;

Expand All @@ -86,7 +83,9 @@ pub trait ParamsProver<'params, C: CurveAffine>: Params<'params, C> {
}

/// Verifier specific functionality with circuit constraints
pub trait ParamsVerifier<'params, C: CurveAffine>: Params<'params, C> {
pub trait ParamsVerifier<'params, C: CurveAffine>: Params<C> {
/// Multiscalar multiplication engine
type MSM: MSM<C> + 'params;
/// Generates an empty multiscalar multiplication struct using the
/// appropriate params.
fn empty_msm(&'params self) -> Self::MSM;
Expand Down Expand Up @@ -199,7 +198,7 @@ pub trait Verifier<'params, Scheme: CommitmentScheme> {
Item = VerifierQuery<
'com,
Scheme::Curve,
<Scheme::ParamsVerifier as Params<'params, Scheme::Curve>>::MSM,
<Scheme::ParamsVerifier as ParamsVerifier<'params, Scheme::Curve>>::MSM,
>,
> + Clone;
}
Expand Down
7 changes: 3 additions & 4 deletions halo2_backend/src/poly/ipa/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ impl<C: CurveAffine> CommitmentScheme for IPACommitmentScheme<C> {
pub type ParamsVerifierIPA<C> = ParamsIPA<C>;

impl<'params, C: CurveAffine> ParamsVerifier<'params, C> for ParamsIPA<C> {
type MSM = MSMIPA<'params, C>;
fn empty_msm(&self) -> MSMIPA<C> {
MSMIPA::new(self)
}
}

impl<'params, C: CurveAffine> Params<'params, C> for ParamsIPA<C> {
type MSM = MSMIPA<'params, C>;

impl<C: CurveAffine> Params<C> for ParamsIPA<C> {
fn k(&self) -> u32 {
self.k
}
Expand Down Expand Up @@ -135,7 +134,7 @@ impl<'params, C: CurveAffine> Params<'params, C> for ParamsIPA<C> {
}
}

impl<'params, C: CurveAffine> ParamsProver<'params, C> for ParamsIPA<C> {
impl<C: CurveAffine> ParamsProver<C> for ParamsIPA<C> {
/// Initializes parameters for the curve, given a random oracle to draw
/// points from.
fn new(k: u32) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/poly/ipa/multiopen/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use halo2_middleware::ff::Field;

use super::{construct_intermediate_sets, ChallengeX1, ChallengeX2, ChallengeX3, ChallengeX4};
use crate::arithmetic::{eval_polynomial, lagrange_interpolate, CurveAffine};
use crate::poly::commitment::{Params, ParamsVerifier, Verifier, MSM};
use crate::poly::commitment::{ParamsVerifier, Verifier, MSM};
use crate::poly::ipa::commitment::IPACommitmentScheme;
use crate::poly::ipa::msm::MSMIPA;
use crate::poly::ipa::strategy::GuardIPA;
Expand Down
12 changes: 5 additions & 7 deletions halo2_backend/src/poly/kzg/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ pub struct ParamsVerifierKZG<E: Engine> {
pub(crate) s_g2: E::G2Affine,
}

impl<'params, E: Engine> Params<'params, E::G1Affine> for ParamsVerifierKZG<E>
impl<E: Engine> Params<E::G1Affine> for ParamsVerifierKZG<E>
where
E::G1Affine: SerdeCurveAffine<ScalarExt = <E as Engine>::Fr, CurveExt = <E as Engine>::G1>,
E::G1: CurveExt<AffineExt = E::G1Affine>,
E::G2Affine: SerdeCurveAffine,
{
type MSM = MSMKZG<E>;

fn k(&self) -> u32 {
self.k
}
Expand Down Expand Up @@ -87,6 +85,7 @@ where
E::G1: CurveExt<AffineExt = E::G1Affine>,
E::G2Affine: SerdeCurveAffine,
{
type MSM = MSMKZG<E>;
fn empty_msm(&'params self) -> MSMKZG<E> {
MSMKZG::new()
}
Expand Down Expand Up @@ -349,14 +348,12 @@ where
/// KZG multi-open verification parameters
// pub type ParamsVerifierKZG<E> = ParamsKZG<E>;

impl<'params, E: Engine> Params<'params, E::G1Affine> for ParamsKZG<E>
impl<E: Engine> Params<E::G1Affine> for ParamsKZG<E>
where
E::G1Affine: SerdeCurveAffine<ScalarExt = <E as Engine>::Fr, CurveExt = <E as Engine>::G1>,
E::G1: CurveExt<AffineExt = E::G1Affine>,
E::G2Affine: SerdeCurveAffine,
{
type MSM = MSMKZG<E>;

fn k(&self) -> u32 {
self.k
}
Expand Down Expand Up @@ -396,12 +393,13 @@ where
E::G1: CurveExt<AffineExt = E::G1Affine>,
E::G2Affine: SerdeCurveAffine,
{
type MSM = MSMKZG<E>;
fn empty_msm(&self) -> MSMKZG<E> {
MSMKZG::new()
}
}

impl<'params, E: Engine> ParamsProver<'params, E::G1Affine> for ParamsKZG<E>
impl<E: Engine> ParamsProver<E::G1Affine> for ParamsKZG<E>
where
E::G1Affine: SerdeCurveAffine<ScalarExt = <E as Engine>::Fr, CurveExt = <E as Engine>::G1>,
E::G1: CurveExt<AffineExt = E::G1Affine>,
Expand Down
28 changes: 14 additions & 14 deletions halo2_proofs/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ use halo2_middleware::ff::FromUniformBytes;
/// Generate a `VerifyingKey` from an instance of `Circuit`.
/// By default, selector compression is turned **ON**.
///
/// **NOTE**: This `keygen_vk` is legacy one, assuming that `compress_selector: true`.
/// Hence, it is HIGHLY recommended to pair this util with `keygen_pk`.
/// **NOTE**: This `keygen_vk` is legacy one, assuming that `compress_selector: true`.
/// Hence, it is HIGHLY recommended to pair this util with `keygen_pk`.
/// In addition, when using this for key generation, user MUST use `compress_selectors: true`.
pub fn keygen_vk<'params, C, P, ConcreteCircuit>(
pub fn keygen_vk<C, P, ConcreteCircuit>(
params: &P,
circuit: &ConcreteCircuit,
) -> Result<VerifyingKey<C>, Error>
where
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
ConcreteCircuit: Circuit<C::Scalar>,
C::Scalar: FromUniformBytes<64>,
{
Expand All @@ -33,16 +33,16 @@ where
///
/// **NOTE**: This `keygen_vk_custom` MUST share the same `compress_selectors` with
/// `ProvingKey` generation process.
/// Otherwise, the user could get unmatching pk/vk pair.
/// Otherwise, the user could get unmatching pk/vk pair.
/// Hence, it is HIGHLY recommended to pair this util with `keygen_pk_custom`.
pub fn keygen_vk_custom<'params, C, P, ConcreteCircuit>(
pub fn keygen_vk_custom<C, P, ConcreteCircuit>(
params: &P,
circuit: &ConcreteCircuit,
compress_selectors: bool,
) -> Result<VerifyingKey<C>, Error>
where
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
ConcreteCircuit: Circuit<C::Scalar>,
C::Scalar: FromUniformBytes<64>,
{
Expand All @@ -53,17 +53,17 @@ where
/// Generate a `ProvingKey` from a `VerifyingKey` and an instance of `Circuit`.
/// By default, selector compression is turned **ON**.
///
/// **NOTE**: This `keygen_pk` is legacy one, assuming that `compress_selector: true`.
/// Hence, it is HIGHLY recommended to pair this util with `keygen_vk`.
/// **NOTE**: This `keygen_pk` is legacy one, assuming that `compress_selector: true`.
/// Hence, it is HIGHLY recommended to pair this util with `keygen_vk`.
/// In addition, when using this for key generation, user MUST use `compress_selectors: true`.
pub fn keygen_pk<'params, C, P, ConcreteCircuit>(
pub fn keygen_pk<C, P, ConcreteCircuit>(
params: &P,
vk: VerifyingKey<C>,
circuit: &ConcreteCircuit,
) -> Result<ProvingKey<C>, Error>
where
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
ConcreteCircuit: Circuit<C::Scalar>,
{
keygen_pk_custom(params, vk, circuit, true)
Expand All @@ -75,17 +75,17 @@ where
///
/// **NOTE**: This `keygen_pk_custom` MUST share the same `compress_selectors` with
/// `VerifyingKey` generation process.
/// Otherwise, the user could get unmatching pk/vk pair.
/// Otherwise, the user could get unmatching pk/vk pair.
/// Hence, it is HIGHLY recommended to pair this util with `keygen_vk_custom`.
pub fn keygen_pk_custom<'params, C, P, ConcreteCircuit>(
pub fn keygen_pk_custom<C, P, ConcreteCircuit>(
params: &P,
vk: VerifyingKey<C>,
circuit: &ConcreteCircuit,
compress_selectors: bool,
) -> Result<ProvingKey<C>, Error>
where
C: CurveAffine,
P: Params<'params, C>,
P: Params<C>,
ConcreteCircuit: Circuit<C::Scalar>,
{
let (compiled_circuit, _, _) = compile_circuit(params.k(), circuit, compress_selectors)?;
Expand Down

0 comments on commit af68bf3

Please sign in to comment.