Skip to content

Commit

Permalink
Make legacy wrappers over v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ed255 committed Jan 4, 2024
1 parent 568b0e5 commit ca9d052
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 10 deletions.
3 changes: 2 additions & 1 deletion halo2_proofs/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub struct VerifyingKey<C: CurveAffine> {
domain: EvaluationDomain<C::Scalar>,
fixed_commitments: Vec<C>,
permutation: permutation::VerifyingKey<C>,
cs: ConstraintSystem<C::Scalar>,
/// TODO: Remove pub
pub cs: ConstraintSystem<C::Scalar>,
/// Cached maximum degree of `cs` (which doesn't change after construction).
cs_degree: usize,
/// The representative of this `VerifyingKey` in transcripts.
Expand Down
4 changes: 3 additions & 1 deletion halo2_proofs/src/plonk/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ where
C::Scalar: FromUniformBytes<64>,
{
let (compiled_circuit, _, _) = compile_circuit(params.k(), circuit, compress_selectors)?;
keygen_vk_v2(params, &compiled_circuit)
let mut vk = keygen_vk_v2(params, &compiled_circuit)?;
vk.compress_selectors = compress_selectors;
Ok(vk)
}

// TODO: Remove
Expand Down
4 changes: 3 additions & 1 deletion halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ impl<
let params = self.params;
let meta = &self.pk.vk.cs;
// let queries = &self.pk.vk.queries;
// println!("DBG commit_phase gate {:?}", meta.gates()[0]);
// println!("DBG commit_phase queries {:?}", meta.advice_queries());

let mut rng = &mut self.rng;

Expand Down Expand Up @@ -888,7 +890,7 @@ pub fn create_proof_legacy<
pk: &ProvingKey<Scheme::Curve>,
circuits: &[ConcreteCircuit],
instances: &[&[&[Scheme::Scalar]]],
mut rng: R,
rng: R,
transcript: &mut T,
) -> Result<(), Error>
where
Expand Down
14 changes: 8 additions & 6 deletions halo2_proofs/tests/frontend_backend_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use halo2_proofs::arithmetic::Field;
use halo2_proofs::circuit::{AssignedCell, Cell, Layouter, Region, SimpleFloorPlanner, Value};

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `Cell`

warning: unused import: `Cell` --> halo2_proofs/tests/frontend_backend_split.rs:11:43 | 11 | use halo2_proofs::circuit::{AssignedCell, Cell, Layouter, Region, SimpleFloorPlanner, Value}; | ^^^^

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `Cell`

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with all features

unused import: `Cell`

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with basic features

unused import: `Cell`

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with all features

unused import: `Cell`

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with basic features

unused import: `Cell`

Check warning on line 11 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with all features

unused import: `Cell`
use halo2_proofs::dev::MockProver;
use halo2_proofs::plonk::{
compile_circuit, create_proof, keygen_pk, keygen_pk_v2, keygen_vk, keygen_vk_v2, verify_proof,
verify_proof_single, Advice, Assigned, Challenge, Circuit, Column, CompiledCircuitV2,
ConstraintSystem, ConstraintSystemV2Backend, Error, Expression, FirstPhase, Fixed, Instance,
ProverV2Single, ProvingKey, SecondPhase, Selector, TableColumn, VerifyingKey,
WitnessCalculator,
compile_circuit, keygen_pk_v2, keygen_vk_v2, verify_proof, verify_proof_single, Advice,
Assigned, Challenge, Circuit, Column, CompiledCircuitV2, ConstraintSystem,

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`

warning: unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey` --> halo2_proofs/tests/frontend_backend_split.rs:15:5 | 15 | Assigned, Challenge, Circuit, Column, CompiledCircuitV2, ConstraintSystem, | ^^^^^^^^ ^^^^^^^^^^^^^^^^^ 16 | ConstraintSystemV2Backend, Error, Expression, FirstPhase, Fixed, Instance, ProverV2Single, | ^^^^^^^^^^^^^^^^^^^^^^^^^ 17 | ProvingKey, SecondPhase, Selector, TableColumn, VerifyingKey, WitnessCalculator, | ^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with all features

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with basic features

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with all features

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with basic features

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`

Check warning on line 15 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with all features

unused imports: `Assigned`, `CompiledCircuitV2`, `ConstraintSystemV2Backend`, `ProvingKey`, `TableColumn`, `VerifyingKey`
ConstraintSystemV2Backend, Error, Expression, FirstPhase, Fixed, Instance, ProverV2Single,
ProvingKey, SecondPhase, Selector, TableColumn, VerifyingKey, WitnessCalculator,
};
use halo2_proofs::poly::commitment::{CommitmentScheme, ParamsProver, Prover, Verifier};

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `Verifier`

warning: unused import: `Verifier` --> halo2_proofs/tests/frontend_backend_split.rs:19:78 | 19 | use halo2_proofs::poly::commitment::{CommitmentScheme, ParamsProver, Prover, Verifier}; | ^^^^^^^^

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `Prover`

warning: unused import: `Prover` --> halo2_proofs/tests/frontend_backend_split.rs:19:70 | 19 | use halo2_proofs::poly::commitment::{CommitmentScheme, ParamsProver, Prover, Verifier}; | ^^^^^^

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `CommitmentScheme`

warning: unused import: `CommitmentScheme` --> halo2_proofs/tests/frontend_backend_split.rs:19:38 | 19 | use halo2_proofs::poly::commitment::{CommitmentScheme, ParamsProver, Prover, Verifier}; | ^^^^^^^^^^^^^^^^

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `CommitmentScheme`

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with all features

unused import: `CommitmentScheme`

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with basic features

unused import: `CommitmentScheme`

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on macOS-latest with all features

unused import: `CommitmentScheme`

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with basic features

unused import: `CommitmentScheme`

Check warning on line 19 in halo2_proofs/tests/frontend_backend_split.rs

View workflow job for this annotation

GitHub Actions / Test on windows-latest with all features

unused import: `CommitmentScheme`
use halo2_proofs::poly::Rotation;
Expand Down Expand Up @@ -161,9 +160,9 @@ impl<F: Field + From<u64>, const WIDTH_FACTOR: usize> MyCircuit<F, WIDTH_FACTOR>

meta.create_gate("gate_a", |meta| {
let s_gate = meta.query_selector(s_gate);
let b = meta.query_advice(b, Rotation::cur());
let a1 = meta.query_advice(a, Rotation::next());
let a0 = meta.query_advice(a, Rotation::cur());
let b = meta.query_advice(b, Rotation::cur());
let c = meta.query_advice(c, Rotation::cur());
let d = meta.query_fixed(d, Rotation::cur());

Expand Down Expand Up @@ -488,6 +487,7 @@ fn test_mycircuit_full_legacy() {
create_proof_legacy as create_proof, keygen_pk_legacy as keygen_pk,
keygen_vk_legacy as keygen_vk,
};
// use halo2_proofs::plonk::{create_proof, keygen_pk, keygen_vk};

let k = K;
let circuit: MyCircuit<Fr, WIDTH_FACTOR> = MyCircuit::new(k, 42);
Expand All @@ -498,6 +498,8 @@ fn test_mycircuit_full_legacy() {
let verifier_params = params.verifier_params();
let start = Instant::now();
let vk = keygen_vk(&params, &circuit).expect("keygen_vk should not fail");
// println!("DBG gate {:?}", vk.cs.gates()[0]);
// println!("DBG queries {:?}", vk.cs.advice_queries());
let pk = keygen_pk(&params, vk.clone(), &circuit).expect("keygen_pk should not fail");
println!("Keygen: {:?}", start.elapsed());

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.66.0
1.75.0
137 changes: 137 additions & 0 deletions scratch
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
DBG collected queries
Queries {
advice: [
(
Column {
index: 0,
column_type: Advice,
},
Rotation(
0,
),
),
(
Column {
index: 0,
column_type: Advice,
},
Rotation(
1,
),
),
(
Column {
index: 1,
column_type: Advice,
},
Rotation(
0,
),
),
(
Column {
index: 2,
column_type: Advice,
},
Rotation(
0,
),
),
],
instance: [],
fixed: [
(
Column {
index: 0,
column_type: Fixed,
},
Rotation(
0,
),
),
(
Column {
index: 5,
column_type: Fixed,
},
Rotation(
0,
),
),
],
num_advice_queries: [
2,
1,
1,
0,
],
}
DBG collected queries
Queries {
advice: [
(
Column {
index: 0,
column_type: Advice,
},
Rotation(
0,
),
),
(
Column {
index: 0,
column_type: Advice,
},
Rotation(
1,
),
),
(
Column {
index: 1,
column_type: Advice,
},
Rotation(
0,
),
),
(
Column {
index: 2,
column_type: Advice,
},
Rotation(
0,
),
),
],
instance: [],
fixed: [
(
Column {
index: 0,
column_type: Fixed,
},
Rotation(
0,
),
),
( # EXTRA
Column {
index: 5,
column_type: Fixed,
},
Rotation(
0,
),
),
],
num_advice_queries: [
2,
1,
1,
0,
],
}

0 comments on commit ca9d052

Please sign in to comment.