From 4a4d59450843008e081159ac75f10951fed037df Mon Sep 17 00:00:00 2001 From: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:17:18 -0700 Subject: [PATCH 1/2] feat: update snark-verifier --- snark-verifier-sdk/Cargo.toml | 2 +- snark-verifier-sdk/src/halo2/aggregation.rs | 6 +- .../examples/evm-verifier-with-accumulator.rs | 116 +++++------------- snark-verifier/examples/recursion.rs | 75 +++++------ snark-verifier/src/loader/halo2/shim.rs | 39 +++--- snark-verifier/src/pcs/kzg/accumulator.rs | 4 +- 6 files changed, 87 insertions(+), 155 deletions(-) diff --git a/snark-verifier-sdk/Cargo.toml b/snark-verifier-sdk/Cargo.toml index fa423daf..d9f02ea0 100644 --- a/snark-verifier-sdk/Cargo.toml +++ b/snark-verifier-sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snark-verifier-sdk" -version = "0.1.3" +version = "0.1.4" edition = "2021" [dependencies] diff --git a/snark-verifier-sdk/src/halo2/aggregation.rs b/snark-verifier-sdk/src/halo2/aggregation.rs index 60674a6c..cc5c97ff 100644 --- a/snark-verifier-sdk/src/halo2/aggregation.rs +++ b/snark-verifier-sdk/src/halo2/aggregation.rs @@ -2,11 +2,9 @@ use super::PlonkSuccinctVerifier; use crate::{BITS, LIMBS}; use halo2_base::{ gates::{ - builder::{ - BaseConfigParams, CircuitBuilderStage, GateThreadBuilder, MultiPhaseThreadBreakPoints, - PublicBaseConfig, RangeWithInstanceCircuitBuilder, + circuit::{ + builder::BaseCircuitBuilder, BaseCircuitParams, BaseConfig, CircuitBuilderStage, }, - flex_gate::GateStrategy, RangeChip, }, halo2_proofs::{ diff --git a/snark-verifier/examples/evm-verifier-with-accumulator.rs b/snark-verifier/examples/evm-verifier-with-accumulator.rs index 650598aa..645c71fd 100644 --- a/snark-verifier/examples/evm-verifier-with-accumulator.rs +++ b/snark-verifier/examples/evm-verifier-with-accumulator.rs @@ -1,6 +1,6 @@ use aggregation::{AggregationCircuit, AggregationConfigParams}; use halo2_base::{ - gates::builder::{BaseConfigParams, CircuitBuilderStage}, + gates::circuit::{BaseCircuitParams, CircuitBuilderStage}, halo2_proofs, utils::fs::gen_srs, }; @@ -202,18 +202,11 @@ mod application { mod aggregation { use crate::PlonkSuccinctVerifier; - use super::halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner}, - plonk::{self, Circuit}, - }; use super::{As, BITS, LIMBS}; use super::{Fr, G1Affine}; use halo2_base::gates::{ - builder::{ - BaseConfigParams, CircuitBuilderStage, GateThreadBuilder, MultiPhaseThreadBreakPoints, - PublicBaseConfig, RangeWithInstanceCircuitBuilder, - }, - RangeChip, + circuit::{builder::BaseCircuitBuilder, BaseCircuitParams, CircuitBuilderStage}, + flex_gate::MultiPhaseThreadBreakPoints, }; use halo2_ecc::bn254::FpChip; use itertools::Itertools; @@ -228,7 +221,7 @@ mod aggregation { util::arithmetic::fe_to_limbs, verifier::{plonk::PlonkProtocol, SnarkVerifier}, }; - use std::rc::Rc; + use std::{mem, rc::Rc}; const T: usize = 3; const RATE: usize = 2; @@ -311,14 +304,14 @@ mod aggregation { #[derive(Clone, Debug)] pub struct AggregationCircuit { - pub inner: RangeWithInstanceCircuitBuilder, + pub inner: BaseCircuitBuilder, pub as_proof: Vec, } impl AggregationCircuit { pub fn new( stage: CircuitBuilderStage, - config_params: BaseConfigParams, + circuit_params: BaseCircuitParams, break_points: Option, params_g0: G1Affine, snarks: impl IntoIterator, @@ -354,14 +347,15 @@ mod aggregation { (accumulator, transcript.finalize()) }; - // create thread builder and run aggregation witness gen - let builder = GateThreadBuilder::from_stage(stage); + let mut builder = BaseCircuitBuilder::from_stage(stage).use_params(circuit_params); // create halo2loader - let range = RangeChip::::default(config_params.lookup_bits.unwrap()); + let range = builder.range_chip(); let fp_chip = FpChip::::new(&range, BITS, LIMBS); let ecc_chip = BaseFieldEccChip::new(&fp_chip); - let loader = Halo2Loader::new(ecc_chip, builder); + let pool = mem::take(builder.pool(0)); + let loader = Halo2Loader::new(ecc_chip, pool); + // witness generation let KzgAccumulator { lhs, rhs } = aggregate(&svk, &loader, &snarks, as_proof.as_slice()); let lhs = lhs.assigned(); @@ -386,30 +380,12 @@ mod aggregation { } } - let builder = loader.take_ctx(); - let inner = RangeWithInstanceCircuitBuilder::from_stage( - stage, - builder, - config_params, - break_points, - assigned_instances, - ); - Self { inner, as_proof } - } - - pub fn config( - &self, - k: u32, - minimum_rows: Option, - lookup_bits: usize, - ) -> BaseConfigParams { - let mut params = self.inner.circuit.0.builder.borrow().config(k as usize, minimum_rows); - params.lookup_bits = Some(lookup_bits); - params - } - - pub fn break_points(&self) -> MultiPhaseThreadBreakPoints { - self.inner.circuit.0.break_points.borrow().clone() + *builder.pool(0) = loader.take_ctx(); + builder.assigned_instances[0] = assigned_instances; + if let Some(break_points) = break_points { + builder.set_break_points(break_points); + } + Self { inner: builder, as_proof } } pub fn num_instance() -> Vec { @@ -418,46 +394,17 @@ mod aggregation { } pub fn instances(&self) -> Vec> { - vec![self.inner.assigned_instances.iter().map(|v| *v.value()).collect_vec()] + self.inner + .assigned_instances + .iter() + .map(|v| v.iter().map(|v| *v.value()).collect_vec()) + .collect() } pub fn accumulator_indices() -> Vec<(usize, usize)> { (0..4 * LIMBS).map(|idx| (0, idx)).collect() } } - - impl Circuit for AggregationCircuit { - type Config = PublicBaseConfig; - type FloorPlanner = SimpleFloorPlanner; - type Params = BaseConfigParams; - - fn params(&self) -> Self::Params { - self.inner.circuit.params() - } - - fn configure_with_params( - meta: &mut plonk::ConstraintSystem, - params: Self::Params, - ) -> Self::Config { - RangeWithInstanceCircuitBuilder::configure_with_params(meta, params) - } - - fn without_witnesses(&self) -> Self { - unimplemented!() - } - - fn configure(_: &mut plonk::ConstraintSystem) -> Self::Config { - unimplemented!() - } - - fn synthesize( - &self, - config: Self::Config, - layouter: impl Layouter, - ) -> Result<(), plonk::Error> { - self.inner.synthesize(config, layouter) - } - } } fn gen_pk>(params: &ParamsKZG, circuit: &C) -> ProvingKey { @@ -573,33 +520,32 @@ fn main() { File::open(path).unwrap_or_else(|e| panic!("{path} does not exist: {e:?}")), ) .unwrap(); - let mut config_params = BaseConfigParams { + let mut circuit_params = BaseCircuitParams { k: agg_config.degree as usize, - strategy: Default::default(), num_advice_per_phase: vec![agg_config.num_advice], num_lookup_advice_per_phase: vec![agg_config.num_lookup_advice], num_fixed: agg_config.num_fixed, lookup_bits: Some(agg_config.lookup_bits), + num_instance_columns: 1, }; let mut agg_circuit = AggregationCircuit::new( CircuitBuilderStage::Mock, - config_params, + circuit_params, None, params_app.get_g()[0], snarks.clone(), ); - config_params = agg_circuit.config(agg_config.degree, Some(6), agg_config.lookup_bits); - agg_circuit.inner.circuit.0.config_params = config_params.clone(); + circuit_params = agg_circuit.inner.calculate_params(Some(9)); #[cfg(debug_assertions)] { - MockProver::run(agg_config.degree, &agg_circuit, agg_circuit.instances()) + MockProver::run(agg_config.degree, &agg_circuit.inner, agg_circuit.instances()) .unwrap() .assert_satisfied(); println!("mock prover passed"); } let params = gen_srs(agg_config.degree); - let pk = gen_pk(¶ms, &agg_circuit); + let pk = gen_pk(¶ms, &agg_circuit.inner); let deployment_code = gen_aggregation_evm_verifier( ¶ms, pk.get_vk(), @@ -607,12 +553,12 @@ fn main() { aggregation::AggregationCircuit::accumulator_indices(), ); - let break_points = agg_circuit.break_points(); + let break_points = agg_circuit.inner.break_points(); drop(agg_circuit); let agg_circuit = AggregationCircuit::new( CircuitBuilderStage::Prover, - config_params, + circuit_params, Some(break_points), params_app.get_g()[0], snarks, @@ -621,7 +567,7 @@ fn main() { let proof = gen_proof::<_, _, EvmTranscript, EvmTranscript>( ¶ms, &pk, - agg_circuit, + agg_circuit.inner, instances.clone(), ); evm_verify(deployment_code, instances, proof); diff --git a/snark-verifier/examples/recursion.rs b/snark-verifier/examples/recursion.rs index 9c9b169a..da34cb82 100644 --- a/snark-verifier/examples/recursion.rs +++ b/snark-verifier/examples/recursion.rs @@ -2,10 +2,8 @@ use ark_std::{end_timer, start_timer}; use common::*; -use halo2_base::gates::builder::BaseConfigParams; -use halo2_base::gates::flex_gate::GateStrategy; -use halo2_base::halo2_proofs; use halo2_base::utils::fs::gen_srs; +use halo2_base::{gates::circuit::BaseCircuitParams, halo2_proofs}; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner}, dev::MockProver, @@ -342,10 +340,12 @@ mod application { } mod recursion { + use std::mem; + use halo2_base::{ gates::{ - builder::{GateThreadBuilder, PublicBaseConfig, RangeWithInstanceCircuitBuilder}, - GateInstructions, RangeChip, RangeInstructions, + circuit::{builder::BaseCircuitBuilder, BaseCircuitParams, BaseConfig}, + GateInstructions, RangeInstructions, }, AssignedValue, }; @@ -426,7 +426,7 @@ mod recursion { .zip([rhs.lhs.assigned(), rhs.rhs.assigned()].iter()) .map(|(lhs, rhs)| { loader.ecc_chip().select( - loader.ctx_mut().main(0), + loader.ctx_mut().main(), EcPoint::clone(lhs), EcPoint::clone(rhs), *condition, @@ -471,9 +471,8 @@ mod recursion { round: usize, instances: Vec, as_proof: Vec, - lookup_bits: usize, - inner: RangeWithInstanceCircuitBuilder, + inner: BaseCircuitBuilder, } impl RecursionCircuit { @@ -489,7 +488,7 @@ mod recursion { initial_state: Fr, state: Fr, round: usize, - config_params: BaseConfigParams, + config_params: BaseCircuitParams, ) -> Self { let svk = params.get_g()[0].into(); let default_accumulator = KzgAccumulator::new(params.get_g()[1], params.get_g()[0]); @@ -544,42 +543,30 @@ mod recursion { .chain([preprocessed_digest, initial_state, state, Fr::from(round as u64)]) .collect(); - let builder = GateThreadBuilder::mock(); - let lookup_bits = config_params.lookup_bits.unwrap(); - let inner = RangeWithInstanceCircuitBuilder::mock(builder, config_params, vec![]); - let mut circuit = Self { - svk, - default_accumulator, - app, - previous, - round, - instances, - as_proof, - inner, - lookup_bits, - }; + let inner = BaseCircuitBuilder::new(false).use_params(config_params); + let mut circuit = + Self { svk, default_accumulator, app, previous, round, instances, as_proof, inner }; circuit.build(); circuit } fn build(&mut self) { - let range = RangeChip::::default(self.lookup_bits); + let range = self.inner.range_chip(); let main_gate = range.gate(); - let mut builder = GateThreadBuilder::mock(); - let ctx = &mut builder; + let pool = self.inner.pool(0); let [preprocessed_digest, initial_state, state, round] = [ self.instances[Self::PREPROCESSED_DIGEST_ROW], self.instances[Self::INITIAL_STATE_ROW], self.instances[Self::STATE_ROW], self.instances[Self::ROUND_ROW], ] - .map(|instance| main_gate.assign_integer(ctx, instance)); - let first_round = main_gate.is_zero(ctx.main(0), round); - let not_first_round = main_gate.not(ctx.main(0), first_round); + .map(|instance| main_gate.assign_integer(pool, instance)); + let first_round = main_gate.is_zero(pool.main(), round); + let not_first_round = main_gate.not(pool.main(), first_round); let fp_chip = FpChip::::new(&range, BITS, LIMBS); let ecc_chip = BaseFieldEccChip::new(&fp_chip); - let loader = Halo2Loader::new(ecc_chip, builder); + let loader = Halo2Loader::new(ecc_chip, mem::take(self.inner.pool(0))); let (mut app_instances, app_accumulators) = succinct_verify(&self.svk, &loader, &self.app, None); let (mut previous_instances, previous_accumulators) = @@ -610,8 +597,8 @@ mod recursion { let app_instances = app_instances.pop().unwrap(); let previous_instances = previous_instances.pop().unwrap(); - let mut builder = loader.take_ctx(); - let ctx = builder.main(0); + let mut pool = loader.take_ctx(); + let ctx = pool.main(); for (lhs, rhs) in [ // Propagate preprocessed_digest ( @@ -640,9 +627,9 @@ mod recursion { ] { ctx.constrain_equal(lhs, rhs); } - *self.inner.circuit.0.builder.borrow_mut() = builder; + *self.inner.pool(0) = pool; - self.inner.assigned_instances.extend( + self.inner.assigned_instances[0].extend( [lhs.x(), lhs.y(), rhs.x(), rhs.y()] .into_iter() .flat_map(|coordinate| coordinate.limbs()) @@ -654,7 +641,7 @@ mod recursion { fn initial_snark( params: &ParamsKZG, vk: Option<&VerifyingKey>, - config_params: BaseConfigParams, + config_params: BaseCircuitParams, ) -> Snark { let mut snark = gen_dummy_snark::(params, vk, config_params); let g = params.get_g(); @@ -685,12 +672,12 @@ mod recursion { } impl Circuit for RecursionCircuit { - type Config = PublicBaseConfig; + type Config = BaseConfig; type FloorPlanner = SimpleFloorPlanner; - type Params = BaseConfigParams; + type Params = BaseCircuitParams; fn params(&self) -> Self::Params { - self.inner.circuit.params() + self.inner.params() } fn without_witnesses(&self) -> Self { @@ -701,7 +688,7 @@ mod recursion { meta: &mut ConstraintSystem, params: Self::Params, ) -> Self::Config { - RangeWithInstanceCircuitBuilder::configure_with_params(meta, params) + BaseCircuitBuilder::configure_with_params(meta, params) } fn configure(_: &mut ConstraintSystem) -> Self::Config { @@ -732,7 +719,7 @@ mod recursion { } fn selectors(config: &Self::Config) -> Vec { - config.base.gate().basic_gates[0].iter().map(|gate| gate.q_enable).collect() + config.gate().basic_gates[0].iter().map(|gate| gate.q_enable).collect() } } @@ -740,7 +727,7 @@ mod recursion { recursion_params: &ParamsKZG, app_params: &ParamsKZG, app_vk: &VerifyingKey, - recursion_config: BaseConfigParams, + recursion_config: BaseCircuitParams, app_config: ConcreteCircuit::Params, ) -> ProvingKey where @@ -768,7 +755,7 @@ mod recursion { recursion_pk: &ProvingKey, initial_state: Fr, inputs: Vec, - config_params: BaseConfigParams, + config_params: BaseCircuitParams, ) -> (Fr, Snark) { let mut state = initial_state; let mut app = ConcreteCircuit::new(state); @@ -804,13 +791,13 @@ fn main() { serde_json::from_reader(fs::File::open("configs/example_recursion.json").unwrap()).unwrap(); let k = recursion_config.degree; let recursion_params = gen_srs(k); - let config_params = BaseConfigParams { - strategy: GateStrategy::Vertical, + let config_params = BaseCircuitParams { k: k as usize, num_advice_per_phase: vec![recursion_config.num_advice], num_lookup_advice_per_phase: vec![recursion_config.num_lookup_advice], num_fixed: recursion_config.num_fixed, lookup_bits: Some(recursion_config.lookup_bits), + num_instance_columns: 1, }; let app_pk = gen_pk(&app_params, &application::Square::default()); diff --git a/snark-verifier/src/loader/halo2/shim.rs b/snark-verifier/src/loader/halo2/shim.rs index 49bbad41..80d5eae2 100644 --- a/snark-verifier/src/loader/halo2/shim.rs +++ b/snark-verifier/src/loader/halo2/shim.rs @@ -143,9 +143,10 @@ mod halo2_lib { loader::halo2::{EccInstructions, IntegerInstructions}, util::arithmetic::{CurveAffine, PrimeField}, }; + use halo2_base::gates::flex_gate::threads::SinglePhaseCoreManager; use halo2_base::{ self, - gates::{builder::GateThreadBuilder, GateChip, GateInstructions, RangeInstructions}, + gates::{GateChip, GateInstructions, RangeInstructions}, utils::BigPrimeField, AssignedValue, QuantumCell::{Constant, Existing}, @@ -161,16 +162,16 @@ mod halo2_lib { type AssignedEcPoint = EcPoint<::ScalarExt, AssignedInteger>; impl IntegerInstructions for GateChip { - type Context = GateThreadBuilder; + type Context = SinglePhaseCoreManager; type AssignedCell = AssignedValue; type AssignedInteger = AssignedValue; fn assign_integer(&self, ctx: &mut Self::Context, integer: F) -> Self::AssignedInteger { - ctx.main(0).load_witness(integer) + ctx.main().load_witness(integer) } fn assign_constant(&self, ctx: &mut Self::Context, integer: F) -> Self::AssignedInteger { - ctx.main(0).load_constant(integer) + ctx.main().load_constant(integer) } fn sum_with_coeff_and_const( @@ -187,7 +188,7 @@ mod halo2_lib { } a.extend(values.iter().map(|(_, a)| Existing(*a.deref()))); b.extend(values.iter().map(|(c, _)| Constant(*c))); - self.inner_product(ctx.main(0), a, b) + self.inner_product(ctx.main(), a, b) } fn sum_products_with_coeff_and_const( @@ -201,9 +202,9 @@ mod halo2_lib { constant: F, ) -> Self::AssignedInteger { match values.len() { - 0 => ctx.main(0).load_constant(constant), + 0 => ctx.main().load_constant(constant), _ => self.sum_products_with_coeff_and_var( - ctx.main(0), + ctx.main(), values.iter().map(|(c, a, b)| (*c, Existing(*a.deref()), Existing(*b.deref()))), Constant(constant), ), @@ -216,11 +217,11 @@ mod halo2_lib { a: &Self::AssignedInteger, b: &Self::AssignedInteger, ) -> Self::AssignedInteger { - GateInstructions::sub(self, ctx.main(0), Existing(*a), Existing(*b)) + GateInstructions::sub(self, ctx.main(), Existing(*a), Existing(*b)) } fn neg(&self, ctx: &mut Self::Context, a: &Self::AssignedInteger) -> Self::AssignedInteger { - GateInstructions::neg(self, ctx.main(0), Existing(*a)) + GateInstructions::neg(self, ctx.main(), Existing(*a)) } fn invert( @@ -229,9 +230,9 @@ mod halo2_lib { a: &Self::AssignedInteger, ) -> Self::AssignedInteger { // make sure scalar != 0 - let is_zero = self.is_zero(ctx.main(0), *a); - self.assert_is_const(ctx.main(0), &is_zero, &F::ZERO); - GateInstructions::div_unsafe(self, ctx.main(0), Constant(F::ONE), Existing(*a)) + let is_zero = self.is_zero(ctx.main(), *a); + self.assert_is_const(ctx.main(), &is_zero, &F::ZERO); + GateInstructions::div_unsafe(self, ctx.main(), Constant(F::ONE), Existing(*a)) } fn assert_equal( @@ -240,7 +241,7 @@ mod halo2_lib { a: &Self::AssignedInteger, b: &Self::AssignedInteger, ) { - ctx.main(0).constrain_equal(a, b); + ctx.main().constrain_equal(a, b); } fn pow_var( @@ -250,7 +251,7 @@ mod halo2_lib { exponent: &Self::AssignedInteger, max_bits: usize, ) -> Self::AssignedInteger { - GateInstructions::pow_var(self, ctx.main(0), *base, *exponent, max_bits) + GateInstructions::pow_var(self, ctx.main(), *base, *exponent, max_bits) } } @@ -259,7 +260,7 @@ mod halo2_lib { C::ScalarExt: BigPrimeField, C::Base: BigPrimeField, { - type Context = GateThreadBuilder; + type Context = SinglePhaseCoreManager; type ScalarChip = GateChip; type AssignedCell = AssignedValue; type AssignedScalar = AssignedValue; @@ -270,11 +271,11 @@ mod halo2_lib { } fn assign_constant(&self, ctx: &mut Self::Context, point: C) -> Self::AssignedEcPoint { - self.assign_constant_point(ctx.main(0), point) + self.assign_constant_point(ctx.main(), point) } fn assign_point(&self, ctx: &mut Self::Context, point: C) -> Self::AssignedEcPoint { - self.assign_point(ctx.main(0), point) + self.assign_point(ctx.main(), point) } fn sum_with_const( @@ -290,7 +291,7 @@ mod halo2_lib { Some(constant) }; self.sum::( - ctx.main(0), + ctx.main(), constant.into_iter().chain(values.iter().map(|v| v.deref().clone())), ) } @@ -346,7 +347,7 @@ mod halo2_lib { a: &Self::AssignedEcPoint, b: &Self::AssignedEcPoint, ) { - self.assert_equal(ctx.main(0), a.clone(), b.clone()); + self.assert_equal(ctx.main(), a.clone(), b.clone()); } } } diff --git a/snark-verifier/src/pcs/kzg/accumulator.rs b/snark-verifier/src/pcs/kzg/accumulator.rs index 423ae7d5..37cb493f 100644 --- a/snark-verifier/src/pcs/kzg/accumulator.rs +++ b/snark-verifier/src/pcs/kzg/accumulator.rs @@ -220,7 +220,7 @@ mod halo2 { assert_eq!(limbs.len(), 2 * LIMBS); let ec_point = self.assign_point::( - ctx.main(0), + ctx.main(), ec_point_from_limbs::<_, LIMBS, BITS>( &limbs.iter().map(|limb| limb.value()).collect_vec(), ), @@ -230,7 +230,7 @@ mod halo2 { .iter() .zip_eq(iter::empty().chain(ec_point.x().limbs()).chain(ec_point.y().limbs())) { - ctx.main(0).constrain_equal(src, dst); + ctx.main().constrain_equal(src, dst); } ec_point From 24a681e7fc751b6bbd3f0929f0b17f2c82e6f3ab Mon Sep 17 00:00:00 2001 From: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com> Date: Mon, 28 Aug 2023 16:07:19 -0700 Subject: [PATCH 2/2] update: use `halo2-lib` v0.4.0 --- snark-verifier-sdk/Cargo.toml | 1 + snark-verifier-sdk/benches/read_pk.rs | 7 +- snark-verifier-sdk/benches/standard_plonk.rs | 19 +- snark-verifier-sdk/examples/n_as_witness.rs | 9 +- snark-verifier-sdk/examples/range_check.rs | 62 ++--- .../examples/vkey_as_witness.rs | 9 +- snark-verifier-sdk/src/halo2/aggregation.rs | 219 +++++++----------- snark-verifier/Cargo.toml | 2 +- 8 files changed, 135 insertions(+), 193 deletions(-) diff --git a/snark-verifier-sdk/Cargo.toml b/snark-verifier-sdk/Cargo.toml index d9f02ea0..a62b3b0c 100644 --- a/snark-verifier-sdk/Cargo.toml +++ b/snark-verifier-sdk/Cargo.toml @@ -19,6 +19,7 @@ bincode = "1.3.3" ark-std = { version = "0.3.0", features = ["print-trace"], optional = true } halo2-base = { git = "https://github.com/axiom-crypto/halo2-lib.git", branch = "develop", default-features = false } snark-verifier = { path = "../snark-verifier", default-features = false } +getset = "0.1.2" # loader_evm ethereum-types = { version = "0.14.1", default-features = false, features = ["std"], optional = true } diff --git a/snark-verifier-sdk/benches/read_pk.rs b/snark-verifier-sdk/benches/read_pk.rs index f87f52c8..4adc42fd 100644 --- a/snark-verifier-sdk/benches/read_pk.rs +++ b/snark-verifier-sdk/benches/read_pk.rs @@ -1,7 +1,7 @@ use ark_std::{end_timer, start_timer}; use criterion::Criterion; use criterion::{criterion_group, criterion_main}; -use halo2_base::gates::builder::CircuitBuilderStage; +use halo2_base::gates::circuit::CircuitBuilderStage; use halo2_base::halo2_proofs; use halo2_base::utils::fs::gen_srs; use halo2_proofs::halo2curves as halo2_curves; @@ -172,8 +172,8 @@ mod application { fn gen_application_snark(params: &ParamsKZG) -> Snark { let circuit = application::StandardPlonk::rand(OsRng); - let pk = gen_pk(params, &circuit, Some(Path::new("examples/app.pk"))); - gen_snark_shplonk(params, &pk, circuit, Some(Path::new("examples/app.snark"))) + let pk = gen_pk(params, &circuit, None); + gen_snark_shplonk(params, &pk, circuit, None::<&str>) } fn bench(c: &mut Criterion) { @@ -187,7 +187,6 @@ fn bench(c: &mut Criterion) { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Keygen, agg_config, - None, ¶ms, snarks, VerifierUniversality::None, diff --git a/snark-verifier-sdk/benches/standard_plonk.rs b/snark-verifier-sdk/benches/standard_plonk.rs index 873f77cb..9f566999 100644 --- a/snark-verifier-sdk/benches/standard_plonk.rs +++ b/snark-verifier-sdk/benches/standard_plonk.rs @@ -1,7 +1,7 @@ use ark_std::{end_timer, start_timer}; use criterion::{criterion_group, criterion_main}; use criterion::{BenchmarkId, Criterion}; -use halo2_base::gates::builder::CircuitBuilderStage; +use halo2_base::gates::circuit::CircuitBuilderStage; use halo2_base::halo2_proofs; use halo2_base::utils::fs::gen_srs; use halo2_proofs::halo2curves as halo2_curves; @@ -19,7 +19,6 @@ use snark_verifier_sdk::{ Snark, }; use snark_verifier_sdk::{CircuitExt, SHPLONK}; -use std::path::Path; mod application { use super::halo2_curves::bn256::Fr; @@ -175,8 +174,8 @@ mod application { fn gen_application_snark(params: &ParamsKZG) -> Snark { let circuit = application::StandardPlonk::rand(OsRng); - let pk = gen_pk(params, &circuit, Some(Path::new("app.pk"))); - gen_snark_shplonk(params, &pk, circuit, Some(Path::new("app.snark"))) + let pk = gen_pk(params, &circuit, None); + gen_snark_shplonk(params, &pk, circuit, None::<&str>) } fn bench(c: &mut Criterion) { @@ -190,16 +189,16 @@ fn bench(c: &mut Criterion) { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Keygen, agg_config, - None, ¶ms, snarks.clone(), VerifierUniversality::None, ); let start0 = start_timer!(|| "gen vk & pk"); - let pk = gen_pk(¶ms, &agg_circuit, Some(Path::new("agg.pk"))); + let pk = gen_pk(¶ms, &agg_circuit, None); end_timer!(start0); let break_points = agg_circuit.break_points(); + drop(agg_circuit); let mut group = c.benchmark_group("plonk-prover"); group.sample_size(10); @@ -211,11 +210,11 @@ fn bench(c: &mut Criterion) { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Prover, agg_config, - Some(break_points.clone()), params, snarks.clone(), VerifierUniversality::None, - ); + ) + .use_break_points(break_points.clone()); let instances = agg_circuit.instances(); gen_proof_shplonk(params, pk, agg_circuit, instances, None) }) @@ -229,11 +228,11 @@ fn bench(c: &mut Criterion) { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Prover, agg_config, - Some(break_points), ¶ms, snarks.clone(), VerifierUniversality::None, - ); + ) + .use_break_points(break_points); let num_instances = agg_circuit.num_instance(); let instances = agg_circuit.instances(); let proof = gen_evm_proof_shplonk(¶ms, &pk, agg_circuit, instances.clone()); diff --git a/snark-verifier-sdk/examples/n_as_witness.rs b/snark-verifier-sdk/examples/n_as_witness.rs index 3ee25f23..3561447f 100644 --- a/snark-verifier-sdk/examples/n_as_witness.rs +++ b/snark-verifier-sdk/examples/n_as_witness.rs @@ -1,4 +1,4 @@ -use halo2_base::gates::builder::CircuitBuilderStage; +use halo2_base::gates::circuit::CircuitBuilderStage; use halo2_base::halo2_proofs; use halo2_base::halo2_proofs::arithmetic::Field; use halo2_base::halo2_proofs::halo2curves::bn256::Fr; @@ -162,12 +162,11 @@ fn main() { let mut agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Keygen, AggregationConfigParams { degree: k, lookup_bits, ..Default::default() }, - None, ¶ms, vec![dummy_snark], VerifierUniversality::Full, ); - let agg_config = agg_circuit.config(Some(10)); + let agg_config = agg_circuit.calculate_params(Some(10)); let pk = gen_pk(¶ms, &agg_circuit, None); let break_points = agg_circuit.break_points(); @@ -177,11 +176,11 @@ fn main() { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Prover, agg_config, - Some(break_points.clone()), ¶ms, vec![snark], VerifierUniversality::Full, - ); + ) + .use_break_points(break_points.clone()); let _snark = gen_snark_shplonk(¶ms, &pk, agg_circuit, None::<&str>); println!("snark with k = {k} success"); } diff --git a/snark-verifier-sdk/examples/range_check.rs b/snark-verifier-sdk/examples/range_check.rs index c9200df7..2beb5a78 100644 --- a/snark-verifier-sdk/examples/range_check.rs +++ b/snark-verifier-sdk/examples/range_check.rs @@ -1,11 +1,8 @@ use ark_std::{end_timer, start_timer}; -use halo2_base::gates::builder::{ - BaseConfigParams, CircuitBuilderStage, GateThreadBuilder, RangeWithInstanceCircuitBuilder, -}; -use halo2_base::gates::flex_gate::GateStrategy; +use halo2_base::gates::circuit::builder::BaseCircuitBuilder; +use halo2_base::gates::circuit::{BaseCircuitParams, CircuitBuilderStage}; +use halo2_base::gates::{GateInstructions, RangeInstructions}; use halo2_base::halo2_proofs::halo2curves::bn256::Fr; -use halo2_base::halo2_proofs::plonk::Circuit; -use halo2_base::safe_types::{GateInstructions, RangeChip, RangeInstructions}; use halo2_base::utils::fs::gen_srs; use itertools::Itertools; @@ -18,43 +15,33 @@ use snark_verifier_sdk::{ }; fn generate_circuit(k: u32) -> Snark { - let mut builder = GateThreadBuilder::new(false); - let ctx = builder.main(0); let lookup_bits = k as usize - 1; - let range = RangeChip::::default(lookup_bits); + let circuit_params = BaseCircuitParams { + k: k as usize, + num_advice_per_phase: vec![10], + num_lookup_advice_per_phase: vec![5], + num_fixed: 1, + lookup_bits: Some(lookup_bits), + num_instance_columns: 1, + }; + let mut builder = BaseCircuitBuilder::new(false).use_params(circuit_params); + let range = builder.range_chip(); + + let ctx = builder.main(0); let x = ctx.load_witness(Fr::from(14)); range.range_check(ctx, x, 2 * lookup_bits + 1); range.gate().add(ctx, x, x); - let circuit = RangeWithInstanceCircuitBuilder::::keygen( - builder.clone(), - BaseConfigParams { - strategy: GateStrategy::Vertical, - k: k as usize, - num_advice_per_phase: vec![1], - num_lookup_advice_per_phase: vec![1], - num_fixed: 1, - lookup_bits: Some(lookup_bits), - }, - vec![], - ); let params = gen_srs(k); - - let pk = gen_pk(¶ms, &circuit, None); - let breakpoints = circuit.break_points(); - - let circuit = RangeWithInstanceCircuitBuilder::::prover( - builder.clone(), - circuit.params(), - breakpoints, - vec![], - ); - gen_snark_shplonk(¶ms, &pk, circuit, None::<&str>) + // do not call calculate_params, we want to use fixed params + let pk = gen_pk(¶ms, &builder, None); + // builder now has break_point set + gen_snark_shplonk(¶ms, &pk, builder, None::<&str>) } fn main() { - let dummy_snark = generate_circuit(13); + let dummy_snark = generate_circuit(9); let k = 14u32; let lookup_bits = k as usize - 1; @@ -62,28 +49,27 @@ fn main() { let mut agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Keygen, AggregationConfigParams { degree: k, lookup_bits, ..Default::default() }, - None, ¶ms, vec![dummy_snark], VerifierUniversality::Full, ); - let agg_config = agg_circuit.config(Some(10)); + let agg_config = agg_circuit.calculate_params(Some(10)); let start0 = start_timer!(|| "gen vk & pk"); let pk = gen_pk(¶ms, &agg_circuit, None); end_timer!(start0); let break_points = agg_circuit.break_points(); - let snarks = (14..17).map(generate_circuit).collect_vec(); + let snarks = (10..16).map(generate_circuit).collect_vec(); for (i, snark) in snarks.into_iter().enumerate() { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Prover, agg_config, - Some(break_points.clone()), ¶ms, vec![snark], VerifierUniversality::Full, - ); + ) + .use_break_points(break_points.clone()); let _snark = gen_snark_shplonk(¶ms, &pk, agg_circuit, None::<&str>); println!("snark {i} success"); } diff --git a/snark-verifier-sdk/examples/vkey_as_witness.rs b/snark-verifier-sdk/examples/vkey_as_witness.rs index a0eb30d2..ca066d80 100644 --- a/snark-verifier-sdk/examples/vkey_as_witness.rs +++ b/snark-verifier-sdk/examples/vkey_as_witness.rs @@ -1,6 +1,6 @@ use application::ComputeFlag; -use halo2_base::gates::builder::CircuitBuilderStage; +use halo2_base::gates::circuit::CircuitBuilderStage; use halo2_base::halo2_proofs; use halo2_base::halo2_proofs::arithmetic::Field; use halo2_base::halo2_proofs::halo2curves::bn256::Fr; @@ -157,12 +157,11 @@ fn main() { let mut agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Keygen, AggregationConfigParams { degree: k, lookup_bits, ..Default::default() }, - None, ¶ms, vec![dummy_snark], VerifierUniversality::PreprocessedAsWitness, ); - let agg_config = agg_circuit.config(Some(10)); + let agg_config = agg_circuit.calculate_params(Some(10)); let pk = gen_pk(¶ms, &agg_circuit, None); let break_points = agg_circuit.break_points(); @@ -173,11 +172,11 @@ fn main() { let agg_circuit = AggregationCircuit::new::( CircuitBuilderStage::Prover, agg_config, - Some(break_points.clone()), ¶ms, vec![snark], VerifierUniversality::PreprocessedAsWitness, - ); + ) + .use_break_points(break_points.clone()); let _snark = gen_snark_shplonk(¶ms, &pk, agg_circuit, None::<&str>); println!("snark {i} success"); } diff --git a/snark-verifier-sdk/src/halo2/aggregation.rs b/snark-verifier-sdk/src/halo2/aggregation.rs index cc5c97ff..f24dc96e 100644 --- a/snark-verifier-sdk/src/halo2/aggregation.rs +++ b/snark-verifier-sdk/src/halo2/aggregation.rs @@ -1,11 +1,12 @@ use super::PlonkSuccinctVerifier; use crate::{BITS, LIMBS}; +use getset::Getters; use halo2_base::{ gates::{ circuit::{ builder::BaseCircuitBuilder, BaseCircuitParams, BaseConfig, CircuitBuilderStage, }, - RangeChip, + flex_gate::MultiPhaseThreadBreakPoints, }, halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner}, @@ -33,7 +34,7 @@ use snark_verifier::{ }, verifier::SnarkVerifier, }; -use std::{fs::File, path::Path, rc::Rc}; +use std::{fs::File, mem, path::Path, rc::Rc}; use super::{CircuitExt, PoseidonTranscript, Snark, POSEIDON_SPEC}; @@ -220,23 +221,23 @@ impl AggregationConfigParams { } } -impl From for BaseConfigParams { +impl From for BaseCircuitParams { fn from(params: AggregationConfigParams) -> Self { - BaseConfigParams { - strategy: GateStrategy::Vertical, + BaseCircuitParams { k: params.degree as usize, num_advice_per_phase: vec![params.num_advice], num_lookup_advice_per_phase: vec![params.num_lookup_advice], num_fixed: params.num_fixed, lookup_bits: Some(params.lookup_bits), + num_instance_columns: 1, } } } -impl TryFrom<&BaseConfigParams> for AggregationConfigParams { +impl TryFrom<&BaseCircuitParams> for AggregationConfigParams { type Error = &'static str; - fn try_from(params: &BaseConfigParams) -> Result { + fn try_from(params: &BaseCircuitParams) -> Result { if params.num_advice_per_phase.iter().skip(1).any(|&n| n != 0) { return Err("AggregationConfigParams only supports 1 phase"); } @@ -246,6 +247,9 @@ impl TryFrom<&BaseConfigParams> for AggregationConfigParams { if params.lookup_bits.is_none() { return Err("AggregationConfigParams requires lookup_bits"); } + if params.num_instance_columns != 1 { + return Err("AggregationConfigParams only supports 1 instance column"); + } Ok(Self { degree: params.k as u32, num_advice: params.num_advice_per_phase[0], @@ -256,42 +260,29 @@ impl TryFrom<&BaseConfigParams> for AggregationConfigParams { } } -impl TryFrom for AggregationConfigParams { +impl TryFrom for AggregationConfigParams { type Error = &'static str; - fn try_from(value: BaseConfigParams) -> Result { + fn try_from(value: BaseCircuitParams) -> Result { Self::try_from(&value) } } -/// Holds virtual contexts for the cells used to verify a collection of snarks -#[derive(Clone, Debug)] -pub struct AggregationCtxBuilder { - /// Virtual region with virtual contexts (columns) - pub builder: GateThreadBuilder, - /// The limbs of the pair of elliptic curve points that need to be verified in a final pairing check. - pub accumulator: Vec>, - // the public instances from previous snarks that were aggregated - pub previous_instances: Vec>>, - /// This returns the assigned `preprocessed_digest` (vkey), optional `transcript_initial_state`, `domain.n` (optional), and `omega` (optional) values as a vector of assigned values, one for each aggregated snark. - /// These can then be exposed as public instances. - /// - /// This is only useful if preprocessed digest is loaded as witness (i.e., `universality != None`), so we set it to `None` if `universality == None`. - pub preprocessed_digests: Option>>>, -} - -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Getters)] pub struct AggregationCircuit { - pub inner: RangeWithInstanceCircuitBuilder, + /// Circuit builder consisting of virtual region managers + pub builder: BaseCircuitBuilder, // the public instances from previous snarks that were aggregated, now collected as PRIVATE assigned values // the user can optionally append these to `inner.assigned_instances` to expose them - pub previous_instances: Vec>>, + #[getset(get = "pub")] + previous_instances: Vec>>, /// This returns the assigned `preprocessed_digest` (vkey), optional `transcript_initial_state`, `domain.n` (optional), and `omega` (optional) values as a vector of assigned values, one for each aggregated snark. /// These can then be exposed as public instances. /// /// This is only useful if preprocessed digest is loaded as witness (i.e., `universality != None`), so we set it to `None` if `universality == None`. - pub preprocessed_digests: Option>>>, - // accumulation scheme proof, private input + #[getset(get = "pub")] + preprocessed_digests: Option>>>, + // accumulation scheme proof, no longer used // pub as_proof: Vec, } @@ -318,23 +309,23 @@ pub trait Halo2KzgAccumulationScheme<'a> = PolynomialCommitmentScheme< VerifyingKey = KzgAsVerifyingKey, > + AccumulationSchemeProver>; -impl AggregationCtxBuilder { - /// Given snarks, this runs the `GateThreadBuilder` to verify all the snarks. +impl AggregationCircuit { + /// Given snarks, this creates `BaseCircuitBuilder` and populates the circuit builder with the virtual cells and constraints necessary to verify all the snarks. /// - /// Also returns the limbs of the pair of elliptic curve points, referred to as the `accumulator`, that need to be verified in a final pairing check. + /// By default, the returned circuit has public instances equal to the limbs of the pair of elliptic curve points, referred to as the `accumulator`, that need to be verified in a final pairing check. /// /// # Universality /// - If `universality` is not `None`, then the verifying keys of each snark in `snarks` is loaded as a witness in the circuit. /// - Moreover, if `universality` is `Full`, then the number of rows `n` of each snark in `snarks` is also loaded as a witness. In this case the generator `omega` of the order `n` multiplicative subgroup of `F` is also loaded as a witness. - /// - By default, these witnesses are _private_ and returned in `self.preprocessed_ + /// - By default, these witnesses are _private_ and returned in `self.preprocessed_digests /// - The user can optionally modify the circuit after calling this function to add more instances to `assigned_instances` to expose. /// /// # Warning /// Will fail silently if `snarks` were created using a different multi-open scheme than `AS` /// where `AS` can be either [`crate::SHPLONK`] or [`crate::GWC`] (for original PLONK multi-open scheme) pub fn new( - witness_gen_only: bool, - lookup_bits: usize, + stage: CircuitBuilderStage, + config_params: AggregationConfigParams, params: &ParamsKZG, snarks: impl IntoIterator, universality: VerifierUniversality, @@ -376,14 +367,19 @@ impl AggregationCtxBuilder { (accumulator, transcript_write.finalize()) }; - // create thread builder and run aggregation witness gen - let builder = GateThreadBuilder::new(witness_gen_only); + let mut builder = BaseCircuitBuilder::from_stage(stage).use_params(config_params.into()); // create halo2loader - let range = RangeChip::::default(lookup_bits); + let range = builder.range_chip(); let fp_chip = FpChip::::new(&range, BITS, LIMBS); let ecc_chip = BaseFieldEccChip::new(&fp_chip); - let loader = Halo2Loader::new(ecc_chip, builder); - + // Take the phase 0 pool from `builder`; it needs to be owned by loader. + // We put it back later (below), so it should have same effect as just mutating `builder.pool(0)`. + let pool = mem::take(builder.pool(0)); + // range_chip has shared reference to LookupAnyManager, with shared CopyConstraintManager + // pool has shared reference to CopyConstraintManager + let loader = Halo2Loader::new(ecc_chip, pool); + + // run witness and copy constraint generation let SnarkAggregationWitness { previous_instances, accumulator, preprocessed_digests } = aggregate::(&svk, &loader, &snarks, as_proof.as_slice(), universality); let lhs = accumulator.lhs.assigned(); @@ -407,76 +403,16 @@ impl AggregationCtxBuilder { assert_eq!(lhs, rhs.value()); } } - - let builder = loader.take_ctx(); - Self { builder, accumulator, previous_instances, preprocessed_digests } - } -} - -impl AggregationCircuit { - /// Given snarks, this creates a circuit and runs the `GateThreadBuilder` to verify all the snarks. - /// By default, the returned circuit has public instances equal to the limbs of the pair of elliptic curve points, referred to as the `accumulator`, that need to be verified in a final pairing check. - /// - /// See [`AggregationCtxBuilder`] for more details. - /// - /// The user can optionally modify the circuit after calling this function to add more instances to `assigned_instances` to expose. - /// - /// Warning: will fail silently if `snarks` were created using a different multi-open scheme than `AS` - /// where `AS` can be either [`crate::SHPLONK`] or [`crate::GWC`] (for original PLONK multi-open scheme) - pub fn new( - stage: CircuitBuilderStage, - agg_config: AggregationConfigParams, - break_points: Option, - params: &ParamsKZG, - snarks: impl IntoIterator, - universality: VerifierUniversality, - ) -> Self - where - AS: for<'a> Halo2KzgAccumulationScheme<'a>, - { - let AggregationCtxBuilder { - builder, - accumulator, - previous_instances, - preprocessed_digests, - } = AggregationCtxBuilder::new::( - stage == CircuitBuilderStage::Prover, - agg_config.lookup_bits, - params, - snarks, - universality, + // put back `pool` into `builder` + *builder.pool(0) = loader.take_ctx(); + assert_eq!( + builder.assigned_instances.len(), + 1, + "AggregationCircuit must have exactly 1 instance column" ); - let inner = RangeWithInstanceCircuitBuilder::from_stage( - stage, - builder, - agg_config.into(), - break_points, - accumulator, - ); - Self { inner, previous_instances, preprocessed_digests } - } - - pub fn public( - stage: CircuitBuilderStage, - agg_config: AggregationConfigParams, - break_points: Option, - params: &ParamsKZG, - snarks: impl IntoIterator, - has_prev_accumulator: bool, - ) -> Self - where - AS: for<'a> Halo2KzgAccumulationScheme<'a>, - { - let mut private = Self::new::( - stage, - agg_config, - break_points, - params, - snarks, - VerifierUniversality::None, - ); - private.expose_previous_instances(has_prev_accumulator); - private + // expose accumulator as public instances + builder.assigned_instances[0] = accumulator; + Self { builder, previous_instances, preprocessed_digests } } /// Re-expose the previous public instances of aggregated snarks again. @@ -485,49 +421,72 @@ impl AggregationCircuit { pub fn expose_previous_instances(&mut self, has_prev_accumulator: bool) { let start = (has_prev_accumulator as usize) * 4 * LIMBS; for prev in self.previous_instances.iter() { - self.inner.assigned_instances.extend_from_slice(&prev[start..]); + self.builder.assigned_instances[0].extend_from_slice(&prev[start..]); } } - /// Auto-configure the circuit and change the circuit's internal configuration parameters. - pub fn config(&mut self, minimum_rows: Option) -> AggregationConfigParams { - self.inner.config(minimum_rows).try_into().unwrap() + /// The log_2 size of the lookup table + pub fn lookup_bits(&self) -> usize { + self.builder.config_params.lookup_bits.unwrap() + } + + /// Set config params + pub fn set_params(&mut self, params: AggregationConfigParams) { + self.builder.set_params(params.into()); } + /// Returns new with config params + pub fn use_params(mut self, params: AggregationConfigParams) -> Self { + self.set_params(params); + self + } + + /// The break points of the circuit. pub fn break_points(&self) -> MultiPhaseThreadBreakPoints { - self.inner.break_points() + self.builder.break_points() + } + + /// Sets the break points of the circuit. + pub fn set_break_points(&mut self, break_points: MultiPhaseThreadBreakPoints) { + self.builder.set_break_points(break_points); } - pub fn instance_count(&self) -> usize { - self.inner.instance_count() + /// Returns new with break points + pub fn use_break_points(mut self, break_points: MultiPhaseThreadBreakPoints) -> Self { + self.set_break_points(break_points); + self } - pub fn instance(&self) -> Vec { - self.inner.instance() + /// Auto-configure the circuit and change the circuit's internal configuration parameters. + pub fn calculate_params(&mut self, minimum_rows: Option) -> AggregationConfigParams { + self.builder.calculate_params(minimum_rows).try_into().unwrap() } } -impl CircuitExt for RangeWithInstanceCircuitBuilder { +impl CircuitExt for BaseCircuitBuilder { fn num_instance(&self) -> Vec { - vec![self.instance_count()] + self.assigned_instances.iter().map(|instances| instances.len()).collect() } fn instances(&self) -> Vec> { - vec![self.instance()] + self.assigned_instances + .iter() + .map(|instances| instances.iter().map(|v| *v.value()).collect()) + .collect() } fn selectors(config: &Self::Config) -> Vec { - config.base.gate().basic_gates[0].iter().map(|gate| gate.q_enable).collect() + config.gate().basic_gates[0].iter().map(|gate| gate.q_enable).collect() } } impl Circuit for AggregationCircuit { - type Config = PublicBaseConfig; + type Config = BaseConfig; type FloorPlanner = SimpleFloorPlanner; type Params = AggregationConfigParams; fn params(&self) -> Self::Params { - (&self.inner.circuit.0.config_params).try_into().unwrap() + (&self.builder.config_params).try_into().unwrap() } fn without_witnesses(&self) -> Self { @@ -538,7 +497,7 @@ impl Circuit for AggregationCircuit { meta: &mut ConstraintSystem, params: Self::Params, ) -> Self::Config { - RangeWithInstanceCircuitBuilder::configure_with_params(meta, params.into()) + BaseCircuitBuilder::configure_with_params(meta, params.into()) } fn configure(_: &mut ConstraintSystem) -> Self::Config { @@ -550,17 +509,17 @@ impl Circuit for AggregationCircuit { config: Self::Config, layouter: impl Layouter, ) -> Result<(), plonk::Error> { - self.inner.synthesize(config, layouter) + self.builder.synthesize(config, layouter) } } impl CircuitExt for AggregationCircuit { fn num_instance(&self) -> Vec { - self.inner.num_instance() + self.builder.num_instance() } fn instances(&self) -> Vec> { - self.inner.instances() + self.builder.instances() } fn accumulator_indices() -> Option> { @@ -568,7 +527,7 @@ impl CircuitExt for AggregationCircuit { } fn selectors(config: &Self::Config) -> Vec { - RangeWithInstanceCircuitBuilder::selectors(config) + BaseCircuitBuilder::selectors(config) } } diff --git a/snark-verifier/Cargo.toml b/snark-verifier/Cargo.toml index f4c4f4af..fbc40c85 100644 --- a/snark-verifier/Cargo.toml +++ b/snark-verifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "snark-verifier" -version = "0.1.3" +version = "0.1.4" edition = "2021" [dependencies]