Skip to content

Commit

Permalink
Merge branch 'main' into draft@remove-compress-selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
duguorong009 committed Apr 12, 2024
2 parents 8b3bdf5 + d03d6c7 commit 6bd4c1f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 47 deletions.
10 changes: 5 additions & 5 deletions halo2_backend/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
},
};
use halo2_middleware::circuit::{
Any, ColumnMid, CompiledCircuitV2, ConstraintSystemMid, ExpressionMid, VarMid,
Any, ColumnMid, CompiledCircuit, ConstraintSystemMid, ExpressionMid, VarMid,
};
use halo2_middleware::{lookup, poly::Rotation, shuffle};
use std::collections::HashMap;
Expand All @@ -40,9 +40,9 @@ where
}

/// Generate a `VerifyingKey` from an instance of `CompiledCircuit`.
pub fn keygen_vk_v2<'params, C, P>(
pub fn keygen_vk<'params, C, P>(
params: &P,
circuit: &CompiledCircuitV2<C::Scalar>,
circuit: &CompiledCircuit<C::Scalar>,
) -> Result<VerifyingKey<C>, Error>
where
C: CurveAffine,
Expand Down Expand Up @@ -88,10 +88,10 @@ where
}

/// Generate a `ProvingKey` from a `VerifyingKey` and an instance of `CompiledCircuit`.
pub fn keygen_pk_v2<'params, C, P>(
pub fn keygen_pk<'params, C, P>(
params: &P,
vk: VerifyingKey<C>,
circuit: &CompiledCircuitV2<C::Scalar>,
circuit: &CompiledCircuit<C::Scalar>,
) -> Result<ProvingKey<C>, Error>
where
C: CurveAffine,
Expand Down
34 changes: 17 additions & 17 deletions halo2_backend/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::plonk::{
ProvingKey,
};
use crate::poly::{
commitment::{Blind, CommitmentScheme, Params, Prover},
commitment::{self, Blind, CommitmentScheme, Params},
Basis, Coeff, LagrangeCoeff, Polynomial, ProverQuery,
};
use crate::transcript::{EncodedChallenge, TranscriptWrite};
Expand All @@ -39,29 +39,29 @@ struct AdviceSingle<C: CurveAffine, B: Basis> {
}

/// The prover object used to create proofs interactively by passing the witnesses to commit at
/// each phase. This works for a single proof. This is a wrapper over ProverV2.
/// each phase. This works for a single proof. This is a wrapper over Prover.
#[derive(Debug)]
pub struct ProverV2Single<
pub struct ProverSingle<
'a,
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
M: MsmAccel<Scheme::Curve>,
>(ProverV2<'a, 'params, Scheme, P, E, R, T, M>);
>(Prover<'a, 'params, Scheme, P, E, R, T, M>);

impl<
'a,
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
M: MsmAccel<Scheme::Curve>,
> ProverV2Single<'a, 'params, Scheme, P, E, R, T, M>
> ProverSingle<'a, 'params, Scheme, P, E, R, T, M>
{
/// Create a new prover object
pub fn new_with_engine(
Expand All @@ -77,7 +77,7 @@ impl<
where
Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
{
Ok(Self(ProverV2::new_with_engine(
Ok(Self(Prover::new_with_engine(
engine,
params,
pk,
Expand All @@ -95,12 +95,12 @@ impl<
instance: &[&[Scheme::Scalar]],
rng: R,
transcript: &'a mut T,
) -> Result<ProverV2Single<'a, 'params, Scheme, P, E, R, T, H2cEngine>, Error>
) -> Result<ProverSingle<'a, 'params, Scheme, P, E, R, T, H2cEngine>, Error>
where
Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
{
let engine = PlonkEngineConfig::build_default();
ProverV2Single::new_with_engine(engine, params, pk, instance, rng, transcript)
ProverSingle::new_with_engine(engine, params, pk, instance, rng, transcript)
}

/// Commit the `witness` at `phase` and return the challenges after `phase`.
Expand All @@ -127,11 +127,11 @@ impl<
/// The prover object used to create proofs interactively by passing the witnesses to commit at
/// each phase. This supports batch proving.
#[derive(Debug)]
pub struct ProverV2<
pub struct Prover<
'a,
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
Expand Down Expand Up @@ -163,12 +163,12 @@ impl<
'a,
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
M: MsmAccel<Scheme::Curve>,
> ProverV2<'a, 'params, Scheme, P, E, R, T, M>
> Prover<'a, 'params, Scheme, P, E, R, T, M>
{
/// Create a new prover object
pub fn new_with_engine(
Expand Down Expand Up @@ -289,7 +289,7 @@ impl<

let challenges = HashMap::<usize, Scheme::Scalar>::with_capacity(meta.num_challenges);

Ok(ProverV2 {
Ok(Prover {
engine,
params,
pk,
Expand Down Expand Up @@ -912,11 +912,11 @@ impl<
circuits_instances: &[&[&[Scheme::Scalar]]],
rng: R,
transcript: &'a mut T,
) -> Result<ProverV2<'a, 'params, Scheme, P, E, R, T, H2cEngine>, Error>
) -> Result<Prover<'a, 'params, Scheme, P, E, R, T, H2cEngine>, Error>
where
Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
{
let engine = PlonkEngineConfig::build_default();
ProverV2::new_with_engine(engine, params, pk, circuits_instances, rng, transcript)
Prover::new_with_engine(engine, params, pk, circuits_instances, rng, transcript)
}
}
8 changes: 4 additions & 4 deletions halo2_frontend/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::plonk::{
Advice, Assignment, Circuit, ConstraintSystem, FirstPhase, Fixed, FloorPlanner, Instance,
SecondPhase, SelectorsToFixed, ThirdPhase,
};
use halo2_middleware::circuit::{Any, CompiledCircuitV2, PreprocessingV2};
use halo2_middleware::circuit::{Any, CompiledCircuit, Preprocessing};
use halo2_middleware::ff::{BatchInvert, Field};
use std::collections::BTreeSet;
use std::collections::HashMap;
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn compile_circuit<F: Field, ConcreteCircuit: Circuit<F>>(
compress_selectors: bool,
) -> Result<
(
CompiledCircuitV2<F>,
CompiledCircuit<F>,
ConcreteCircuit::Config,
ConstraintSystem<F>,
),
Expand Down Expand Up @@ -116,15 +116,15 @@ pub fn compile_circuit<F: Field, ConcreteCircuit: Circuit<F>>(
#[cfg(feature = "thread-safe-region")]
assembly.permutation.copies.sort();

let preprocessing = PreprocessingV2 {
let preprocessing = Preprocessing {
permutation: halo2_middleware::permutation::AssemblyMid {
copies: assembly.permutation.copies,
},
fixed,
};

Ok((
CompiledCircuitV2 {
CompiledCircuit {
cs: cs.clone().into(),
preprocessing,
},
Expand Down
6 changes: 3 additions & 3 deletions halo2_middleware/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ pub struct ConstraintSystemMid<F: Field> {

/// Data that needs to be preprocessed from a circuit
#[derive(Debug, Clone)]
pub struct PreprocessingV2<F: Field> {
pub struct Preprocessing<F: Field> {
pub permutation: permutation::AssemblyMid,
pub fixed: Vec<Vec<F>>,
}

/// This is a description of a low level Plonkish compiled circuit. Contains the Constraint System
/// as well as the fixed columns and copy constraints information.
#[derive(Debug, Clone)]
pub struct CompiledCircuitV2<F: Field> {
pub preprocessing: PreprocessingV2<F>,
pub struct CompiledCircuit<F: Field> {
pub preprocessing: Preprocessing<F>,
pub cs: ConstraintSystemMid<F>,
}

Expand Down
6 changes: 3 additions & 3 deletions halo2_proofs/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::plonk::Error;
use halo2_backend::plonk::{
keygen::{keygen_pk_v2, keygen_vk_v2},
keygen::{keygen_pk as backend_keygen_pk, keygen_vk as backend_keygen_vk},
ProvingKey, VerifyingKey,
};
use halo2_backend::{arithmetic::CurveAffine, poly::commitment::Params};
Expand Down Expand Up @@ -47,7 +47,7 @@ where
C::Scalar: FromUniformBytes<64>,
{
let (compiled_circuit, _, _) = compile_circuit(params.k(), circuit, compress_selectors)?;
Ok(keygen_vk_v2(params, &compiled_circuit)?)
Ok(backend_keygen_vk(params, &compiled_circuit)?)
}

/// Generate a `ProvingKey` from a `VerifyingKey` and an instance of `Circuit`.
Expand Down Expand Up @@ -89,5 +89,5 @@ where
ConcreteCircuit: Circuit<C::Scalar>,
{
let (compiled_circuit, _, _) = compile_circuit(params.k(), circuit, compress_selectors)?;
Ok(keygen_pk_v2(params, vk, &compiled_circuit)?)
Ok(backend_keygen_pk(params, vk, &compiled_circuit)?)
}
12 changes: 6 additions & 6 deletions halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::plonk::{Error, ErrorBack};
use crate::poly::commitment::{CommitmentScheme, Params, Prover};
use crate::poly::commitment::{self, CommitmentScheme, Params};
use crate::transcript::{EncodedChallenge, TranscriptWrite};
use halo2_backend::plonk::{prover::ProverV2, ProvingKey};
use halo2_backend::plonk::{prover::Prover, ProvingKey};
use halo2_frontend::circuit::{compile_circuit_cs, WitnessCalculator};
use halo2_frontend::plonk::Circuit;
use halo2_middleware::ff::{FromUniformBytes, WithSmallOrderMulGroup};
Expand All @@ -19,7 +19,7 @@ use std::collections::HashMap;
pub fn create_proof_with_engine<
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
Expand Down Expand Up @@ -49,7 +49,7 @@ where
pub fn create_proof<
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
Expand Down Expand Up @@ -80,7 +80,7 @@ where
pub fn create_proof_custom_with_engine<
'params,
Scheme: CommitmentScheme,
P: Prover<'params, Scheme>,
P: commitment::Prover<'params, Scheme>,
E: EncodedChallenge<Scheme::Curve>,
R: RngCore,
T: TranscriptWrite<Scheme::Curve, E>,
Expand Down Expand Up @@ -112,7 +112,7 @@ where
.enumerate()
.map(|(i, circuit)| WitnessCalculator::new(params.k(), circuit, &config, &cs, instances[i]))
.collect();
let mut prover = ProverV2::<Scheme, P, _, _, _, _>::new_with_engine(
let mut prover = Prover::<Scheme, P, _, _, _, _>::new_with_engine(
engine, params, pk, instances, rng, transcript,
)?;
let mut challenges = HashMap::new();
Expand Down
19 changes: 10 additions & 9 deletions halo2_proofs/tests/frontend_backend_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ static ALLOC: dhat::Alloc = dhat::Alloc;

use halo2_backend::{
plonk::{
keygen::{keygen_pk_v2, keygen_vk_v2},
prover::ProverV2Single,
keygen::{keygen_pk, keygen_vk},
prover::ProverSingle,
verifier::{verify_proof, verify_proof_single},
},
transcript::{
Expand Down Expand Up @@ -508,7 +508,9 @@ fn test_mycircuit_full_legacy() {
#[cfg(feature = "heap-profiling")]
let _profiler = dhat::Profiler::new_heap();

use halo2_proofs::plonk::{create_proof, keygen_pk, keygen_vk};
use halo2_proofs::plonk::{
create_proof, keygen_pk as keygen_pk_legacy, keygen_vk as keygen_vk_legacy,
};

let k = K;
let circuit: MyCircuit<Fr, WIDTH_FACTOR> = MyCircuit::new(k, 42);
Expand All @@ -518,8 +520,8 @@ fn test_mycircuit_full_legacy() {
let params = ParamsKZG::<Bn256>::setup(k, &mut rng);
let verifier_params = params.verifier_params();
let start = Instant::now();
let vk = keygen_vk(&params, &circuit).expect("keygen_vk should not fail");
let pk = keygen_pk(&params, vk.clone(), &circuit).expect("keygen_pk should not fail");
let vk = keygen_vk_legacy(&params, &circuit).expect("keygen_vk should not fail");
let pk = keygen_pk_legacy(&params, vk.clone(), &circuit).expect("keygen_pk should not fail");
println!("Keygen: {:?}", start.elapsed());

// Proving
Expand Down Expand Up @@ -580,9 +582,8 @@ fn test_mycircuit_full_split() {
let params = ParamsKZG::<Bn256>::setup(k, &mut rng);
let verifier_params = params.verifier_params();
let start = Instant::now();
let vk = keygen_vk_v2(&params, &compiled_circuit).expect("keygen_vk should not fail");
let pk =
keygen_pk_v2(&params, vk.clone(), &compiled_circuit).expect("keygen_pk should not fail");
let vk = keygen_vk(&params, &compiled_circuit).expect("keygen_vk should not fail");
let pk = keygen_pk(&params, vk.clone(), &compiled_circuit).expect("keygen_pk should not fail");
println!("Keygen: {:?}", start.elapsed());
drop(compiled_circuit);

Expand All @@ -597,7 +598,7 @@ fn test_mycircuit_full_split() {
let start = Instant::now();
let mut witness_calc = WitnessCalculator::new(k, &circuit, &config, &cs, instances_slice);
let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]);
let mut prover = ProverV2Single::<
let mut prover = ProverSingle::<
KZGCommitmentScheme<Bn256>,
ProverSHPLONK<'_, Bn256>,
_,
Expand Down

0 comments on commit 6bd4c1f

Please sign in to comment.