Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split ConstraintSystem into a builder type and a verifying key type #781

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions halo2_gadgets/benches/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use halo2_proofs::{
pasta::Fp,
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Circuit, Column,
ConstraintSystem, Error, Instance, SingleVerifier,
ConstraintSystemBuilder, Error, Instance, SingleVerifier,
},
poly::commitment::Params,
transcript::{Blake2bRead, Blake2bWrite, Challenge255},
Expand Down Expand Up @@ -52,7 +52,7 @@ where
}
}

fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
let state = (0..WIDTH).map(|_| meta.advice_column()).collect::<Vec<_>>();
let expected = meta.instance_column();
meta.enable_equality(expected);
Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
pasta::{pallas, EqAffine},
plonk::{
create_proof, keygen_pk, keygen_vk, verify_proof, Circuit, ConstraintSystem, Error,
create_proof, keygen_pk, keygen_vk, verify_proof, Circuit, ConstraintSystemBuilder, Error,
SingleVerifier,
},
poly::commitment::Params,
Expand Down Expand Up @@ -32,7 +32,7 @@ fn bench(name: &str, k: u32, c: &mut Criterion) {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
Table16Chip::configure(meta)
}

Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ pub(crate) mod tests {
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
dev::MockProver,
plonk::{Circuit, ConstraintSystem, Error},
plonk::{Circuit, ConstraintSystemBuilder, Error},
};
use lazy_static::lazy_static;
use pasta_curves::pallas;
Expand Down Expand Up @@ -736,7 +736,7 @@ pub(crate) mod tests {
MyCircuit { test_errors: false }
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
4 changes: 2 additions & 2 deletions halo2_gadgets/src/ecc/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ff::PrimeField;
use group::prime::PrimeCurveAffine;
use halo2_proofs::{
circuit::{AssignedCell, Chip, Layouter, Value},
plonk::{Advice, Assigned, Column, ConstraintSystem, Error, Fixed},
plonk::{Advice, Assigned, Column, ConstraintSystemBuilder, Error, Fixed},
};
use pasta_curves::{arithmetic::CurveAffine, pallas};

Expand Down Expand Up @@ -261,7 +261,7 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> EccChip<FixedPoints> {
/// All columns in `advices` will be equality-enabled.
#[allow(non_snake_case)]
pub fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
advices: [Column<Advice>; 10],
lagrange_coeffs: [Column<Fixed>; 8],
range_check: LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>,
Expand Down
8 changes: 5 additions & 3 deletions halo2_gadgets/src/ecc/chip/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use super::EccPoint;
use group::ff::PrimeField;
use halo2_proofs::{
circuit::Region,
plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Expression, Selector},
plonk::{
Advice, Assigned, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Selector,
},
poly::Rotation,
};
use pasta_curves::pallas;
Expand Down Expand Up @@ -36,7 +38,7 @@ pub struct Config {
impl Config {
#[allow(clippy::too_many_arguments)]
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
x_p: Column<Advice>,
y_p: Column<Advice>,
x_qr: Column<Advice>,
Expand Down Expand Up @@ -74,7 +76,7 @@ impl Config {
[self.x_qr, self.y_qr].into_iter().collect()
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// https://p.z.cash/halo2-0.1:ecc-complete-addition
meta.create_gate("complete addition", |meta| {
let q_add = meta.query_selector(self.q_add);
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip/add_incomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashSet;
use super::NonIdentityEccPoint;
use halo2_proofs::{
circuit::Region,
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector},
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Selector},
poly::Rotation,
};
use pasta_curves::pallas;
Expand All @@ -23,7 +23,7 @@ pub struct Config {

impl Config {
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
x_p: Column<Advice>,
y_p: Column<Advice>,
x_qr: Column<Advice>,
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Config {
.collect()
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// https://p.z.cash/halo2-0.1:ecc-incomplete-addition
meta.create_gate("incomplete addition", |meta| {
let q_add_incomplete = meta.query_selector(self.q_add_incomplete);
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use ff::{Field, PrimeField};
use halo2_proofs::{
circuit::{AssignedCell, Layouter, Region, Value},
plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Selector},
plonk::{Advice, Assigned, Column, ConstraintSystemBuilder, Constraints, Error, Selector},
poly::Rotation,
};
use uint::construct_uint;
Expand Down Expand Up @@ -63,7 +63,7 @@ pub struct Config {

impl Config {
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
add_config: add::Config,
lookup_config: LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>,
advices: [Column<Advice>; 10],
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Config {
config
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// If `lsb` is 0, (x, y) = (x_p, -y_p). If `lsb` is 1, (x, y) = (0,0).
// https://p.z.cash/halo2-0.1:ecc-var-mul-lsb-gate?partial
meta.create_gate("LSB check", |meta| {
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utilities::{bool_check, ternary};

use halo2_proofs::{
circuit::{Region, Value},
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Expression, Selector},
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Selector},
poly::Rotation,
};

Expand All @@ -22,7 +22,7 @@ pub struct Config {

impl Config {
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
z_complete: Column<Advice>,
add_config: add::Config,
) -> Self {
Expand All @@ -43,7 +43,7 @@ impl Config {
/// This is used to check the bits used in complete addition, since the incomplete
/// addition gate (controlled by `q_mul`) already checks scalar decomposition for
/// the other bits.
fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// | y_p | z_complete |
// --------------------
// | y_p | z_{i + 1} |
Expand Down
7 changes: 4 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul/incomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use group::ff::PrimeField;
use halo2_proofs::{
circuit::{Region, Value},
plonk::{
Advice, Column, ConstraintSystem, Constraints, Error, Expression, Selector, VirtualCells,
Advice, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Selector,
VirtualCells,
},
poly::Rotation,
};
Expand Down Expand Up @@ -73,7 +74,7 @@ pub(crate) struct Config<const NUM_BITS: usize> {

impl<const NUM_BITS: usize> Config<NUM_BITS> {
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
z: Column<Advice>,
x_a: Column<Advice>,
x_p: Column<Advice>,
Expand Down Expand Up @@ -104,7 +105,7 @@ impl<const NUM_BITS: usize> Config<NUM_BITS> {
}

// Gate for incomplete addition part of variable-base scalar multiplication.
fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// Closure to compute x_{R,i} = λ_{1,i}^2 - x_{A,i} - x_{P,i}
let x_r = |meta: &mut VirtualCells<pallas::Base>, rotation: Rotation| {
self.double_and_add.x_r(meta, rotation)
Expand Down
8 changes: 5 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use group::ff::PrimeField;
use halo2_proofs::circuit::AssignedCell;
use halo2_proofs::{
circuit::Layouter,
plonk::{Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Expression, Selector},
plonk::{
Advice, Assigned, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Selector,
},
poly::Rotation,
};
use pasta_curves::pallas;
Expand All @@ -26,7 +28,7 @@ pub struct Config {

impl Config {
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
lookup_config: LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>,
advices: [Column<Advice>; 3],
) -> Self {
Expand All @@ -45,7 +47,7 @@ impl Config {
config
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// https://p.z.cash/halo2-0.1:ecc-var-mul-overflow
meta.create_gate("overflow checks", |meta| {
let q_mul_overflow = meta.query_selector(self.q_mul_overflow);
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul_fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use group::{
use halo2_proofs::{
circuit::{AssignedCell, Region, Value},
plonk::{
Advice, Column, ConstraintSystem, Constraints, Error, Expression, Fixed, Selector,
Advice, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Fixed, Selector,
VirtualCells,
},
poly::Rotation,
Expand Down Expand Up @@ -54,7 +54,7 @@ pub struct Config<FixedPoints: super::FixedPoints<pallas::Affine>> {
impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
#[allow(clippy::too_many_arguments)]
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
lagrange_coeffs: [Column<Fixed>; H],
window: Column<Advice>,
u: Column<Advice>,
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
/// This gate is not used in the mul_fixed::full_width helper, since the full-width
/// scalar is witnessed directly as three-bit windows instead of being decomposed
/// via a running sum.
fn running_sum_coords_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn running_sum_coords_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
meta.create_gate("Running sum coordinates check", |meta| {
let q_mul_fixed_running_sum =
meta.query_selector(self.running_sum_config.q_range_check());
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use group::ff::PrimeField;
use halo2_proofs::{
circuit::{AssignedCell, Layouter},
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Expression, Selector},
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Selector},
poly::Rotation,
};
use pasta_curves::pallas;
Expand All @@ -27,7 +27,7 @@ pub struct Config<Fixed: FixedPoints<pallas::Affine>> {

impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
pub(crate) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
canon_advices: [Column<Advice>; 3],
lookup_config: LookupRangeCheckConfig<pallas::Base, { sinsemilla::K }>,
super_config: super::Config<Fixed>,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
config
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// Check that the base field element is canonical.
// https://p.z.cash/halo2-0.1:ecc-fixed-mul-base-canonicity
meta.create_gate("Canonicity checks", |meta| {
Expand Down
6 changes: 3 additions & 3 deletions halo2_gadgets/src/ecc/chip/mul_fixed/full_width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use arrayvec::ArrayVec;
use ff::PrimeField;
use halo2_proofs::{
circuit::{AssignedCell, Layouter, Region, Value},
plonk::{ConstraintSystem, Constraints, Error, Selector},
plonk::{ConstraintSystemBuilder, Constraints, Error, Selector},
poly::Rotation,
};
use pasta_curves::pallas;
Expand All @@ -18,7 +18,7 @@ pub struct Config<Fixed: FixedPoints<pallas::Affine>> {

impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
pub(crate) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
super_config: super::Config<Fixed>,
) -> Self {
let config = Self {
Expand All @@ -31,7 +31,7 @@ impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
config
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// Check that each window `k` is within 3 bits
// https://p.z.cash/halo2-0.1:ecc-fixed-mul-full-word
meta.create_gate("Full-width fixed-base scalar mul", |meta| {
Expand Down
10 changes: 5 additions & 5 deletions halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{ecc::chip::MagnitudeSign, utilities::bool_check};

use halo2_proofs::{
circuit::{Layouter, Region},
plonk::{ConstraintSystem, Constraints, Error, Expression, Selector},
plonk::{ConstraintSystemBuilder, Constraints, Error, Expression, Selector},
poly::Rotation,
};
use pasta_curves::pallas;
Expand All @@ -19,7 +19,7 @@ pub struct Config<Fixed: FixedPoints<pallas::Affine>> {

impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
pub(crate) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
super_config: super::Config<Fixed>,
) -> Self {
let config = Self {
Expand All @@ -32,7 +32,7 @@ impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
config
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
// Gate contains the following constraints:
// - https://p.z.cash/halo2-0.1:ecc-fixed-mul-short-msb
// - https://p.z.cash/halo2-0.1:ecc-fixed-mul-short-conditional-neg
Expand Down Expand Up @@ -409,7 +409,7 @@ pub mod tests {
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner},
dev::{FailureLocation, MockProver, VerifyFailure},
plonk::{Circuit, ConstraintSystem, Error},
plonk::{Circuit, ConstraintSystemBuilder, Error},
};

#[derive(Default)]
Expand All @@ -432,7 +432,7 @@ pub mod tests {
Self::default()
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
let advices = [
meta.advice_column(),
meta.advice_column(),
Expand Down
8 changes: 4 additions & 4 deletions halo2_gadgets/src/ecc/chip/witness_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use group::prime::PrimeCurveAffine;
use halo2_proofs::{
circuit::{AssignedCell, Region, Value},
plonk::{
Advice, Assigned, Column, ConstraintSystem, Constraints, Error, Expression, Selector,
VirtualCells,
Advice, Assigned, Column, ConstraintSystemBuilder, Constraints, Error, Expression,
Selector, VirtualCells,
},
poly::Rotation,
};
Expand All @@ -29,7 +29,7 @@ pub struct Config {

impl Config {
pub(super) fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
meta: &mut ConstraintSystemBuilder<pallas::Base>,
x: Column<Advice>,
y: Column<Advice>,
) -> Self {
Expand All @@ -45,7 +45,7 @@ impl Config {
config
}

fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
fn create_gate(&self, meta: &mut ConstraintSystemBuilder<pallas::Base>) {
let curve_eqn = |meta: &mut VirtualCells<pallas::Base>| {
let x = meta.query_advice(self.x, Rotation::cur());
let y = meta.query_advice(self.y, Rotation::cur());
Expand Down
Loading