mirror of https://github.com/zcash/halo2.git
Split `ConstraintSystem` into a builder type and a verifying key type
This is an initial refactor performed during Halo 2 Office Hours, to explore the effects of this split on the wider codebase. At the end, we discussed the result, and noted that the verifying key type still contains data in sub-types that is irrelevant to the actual verifying key. The verifying key type is also never exposed in the public API of the verifying key; `ConstraintSystem` was only public for its use in `Circuit::configure`. The likely next steps are: - Rework `PinnedConstraintSystem` to be the verifying key type, only storing the data needed for the transcript, but being an owned type that exposes immutable references via methods instead of its fields being `pub(crate)`. - Undo the `ConstraintSystemBuilder` rename, so we are just removing parts of the `ConstraintSystem` API. - Rework `ConstraintSystem::pinned` and `VerifyingKey::from_parts` to instead become the builder method for the verifying key type along with the data that is cached alongside it inside `VerifyingKey`. - Refactor the very few methods that we identified as only relevant to the verifying key type, as they are only used redundantly.
This commit is contained in:
parent
76b3f892a9
commit
521bc3d2d8
|
@ -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},
|
||||
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
@ -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 }>,
|
||||
|
|
|
@ -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;
|
||||
|
@ -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>,
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -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>,
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -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],
|
||||
|
@ -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| {
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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} |
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
@ -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>,
|
||||
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
@ -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>,
|
||||
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
@ -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>,
|
||||
|
@ -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| {
|
||||
|
|
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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| {
|
||||
|
|
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)]
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -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());
|
||||
|
|
|
@ -5,7 +5,8 @@ use group::ff::Field;
|
|||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Cell, Chip, Layouter, Region, Value},
|
||||
plonk::{
|
||||
Advice, Any, Column, ConstraintSystem, Constraints, Error, Expression, Fixed, Selector,
|
||||
Advice, Any, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Fixed,
|
||||
Selector,
|
||||
},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
@ -54,7 +55,7 @@ impl<F: Field, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
|||
// needs to be known wherever we implement the hashing gadget, but it isn't strictly
|
||||
// necessary for the permutation.
|
||||
pub fn configure<S: Spec<F, WIDTH, RATE>>(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
state: [Column<Advice>; WIDTH],
|
||||
partial_sbox: Column<Advice>,
|
||||
rc_a: [Column<Fixed>; WIDTH],
|
||||
|
@ -597,7 +598,7 @@ mod tests {
|
|||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
dev::MockProver,
|
||||
pasta::Fp,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
use pasta_curves::pallas;
|
||||
use rand::rngs::OsRng;
|
||||
|
@ -624,7 +625,7 @@ mod tests {
|
|||
PermuteCircuit::<S, WIDTH, RATE>(PhantomData)
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Pow5Config<Fp, WIDTH, RATE> {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Pow5Config<Fp, WIDTH, RATE> {
|
||||
let state = (0..WIDTH).map(|_| meta.advice_column()).collect::<Vec<_>>();
|
||||
let partial_sbox = meta.advice_column();
|
||||
|
||||
|
@ -743,7 +744,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Pow5Config<Fp, WIDTH, RATE> {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Pow5Config<Fp, WIDTH, RATE> {
|
||||
let state = (0..WIDTH).map(|_| meta.advice_column()).collect::<Vec<_>>();
|
||||
let partial_sbox = meta.advice_column();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::Sha256Instructions;
|
|||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Chip, Layouter, Region, Value},
|
||||
pasta::pallas,
|
||||
plonk::{Advice, Any, Assigned, Column, ConstraintSystem, Error},
|
||||
plonk::{Advice, Any, Assigned, Column, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
|
||||
mod compression;
|
||||
|
@ -266,7 +266,7 @@ impl Table16Chip {
|
|||
|
||||
/// Configures a circuit to include this chip.
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<pallas::Base>,
|
||||
meta: &mut ConstraintSystemBuilder<pallas::Base>,
|
||||
) -> <Self as Chip<pallas::Base>>::Config {
|
||||
// Columns required by this chip:
|
||||
let message_schedule = meta.advice_column();
|
||||
|
@ -457,7 +457,7 @@ mod tests {
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, SimpleFloorPlanner},
|
||||
pasta::pallas,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -473,7 +473,7 @@ mod tests {
|
|||
MyCircuit {}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
|
||||
Table16Chip::configure(meta)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use super::{
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, Value},
|
||||
pasta::pallas,
|
||||
plonk::{Advice, Column, ConstraintSystem, Error, Selector},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Error, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
@ -457,7 +457,7 @@ impl Table16Assignment for CompressionConfig {}
|
|||
|
||||
impl CompressionConfig {
|
||||
pub(super) fn configure(
|
||||
meta: &mut ConstraintSystem<pallas::Base>,
|
||||
meta: &mut ConstraintSystemBuilder<pallas::Base>,
|
||||
lookup: SpreadInputs,
|
||||
message_schedule: Column<Advice>,
|
||||
extras: [Column<Advice>; 6],
|
||||
|
@ -944,7 +944,7 @@ mod tests {
|
|||
circuit::{Layouter, SimpleFloorPlanner},
|
||||
dev::MockProver,
|
||||
pasta::pallas,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -959,7 +959,7 @@ mod tests {
|
|||
MyCircuit {}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
|
||||
Table16Chip::configure(meta)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use super::{super::BLOCK_SIZE, AssignedBits, BlockWord, SpreadInputs, Table16Ass
|
|||
use halo2_proofs::{
|
||||
circuit::Layouter,
|
||||
pasta::pallas,
|
||||
plonk::{Advice, Column, ConstraintSystem, Error, Selector},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Error, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,7 @@ impl MessageScheduleConfig {
|
|||
/// itself.
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
pub(super) fn configure(
|
||||
meta: &mut ConstraintSystem<pallas::Base>,
|
||||
meta: &mut ConstraintSystemBuilder<pallas::Base>,
|
||||
lookup: SpreadInputs,
|
||||
message_schedule: Column<Advice>,
|
||||
extras: [Column<Advice>; 6],
|
||||
|
@ -401,7 +401,7 @@ mod tests {
|
|||
circuit::{Layouter, SimpleFloorPlanner},
|
||||
dev::MockProver,
|
||||
pasta::pallas,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -416,7 +416,7 @@ mod tests {
|
|||
MyCircuit {}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
|
||||
Table16Chip::configure(meta)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use group::ff::{Field, PrimeField};
|
|||
use halo2_proofs::{
|
||||
circuit::{Chip, Layouter, Region, Value},
|
||||
pasta::pallas,
|
||||
plonk::{Advice, Column, ConstraintSystem, Error, TableColumn},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Error, TableColumn},
|
||||
poly::Rotation,
|
||||
};
|
||||
use std::convert::TryInto;
|
||||
|
@ -182,7 +182,7 @@ impl<F: Field> Chip<F> for SpreadTableChip<F> {
|
|||
|
||||
impl<F: PrimeField> SpreadTableChip<F> {
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
input_tag: Column<Advice>,
|
||||
input_dense: Column<Advice>,
|
||||
input_spread: Column<Advice>,
|
||||
|
@ -298,7 +298,7 @@ mod tests {
|
|||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
dev::MockProver,
|
||||
pasta::Fp,
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
@ -317,7 +317,7 @@ mod tests {
|
|||
MyCircuit {}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
let input_tag = meta.advice_column();
|
||||
let input_dense = meta.advice_column();
|
||||
let input_spread = meta.advice_column();
|
||||
|
|
|
@ -456,7 +456,7 @@ pub(crate) mod tests {
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
dev::MockProver,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
|
@ -532,7 +532,7 @@ pub(crate) mod tests {
|
|||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
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(),
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::marker::PhantomData;
|
|||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Chip, Layouter, Value},
|
||||
plonk::{
|
||||
Advice, Column, ConstraintSystem, Constraints, Error, Expression, Fixed, Selector,
|
||||
Advice, Column, ConstraintSystemBuilder, Constraints, Error, Expression, Fixed, Selector,
|
||||
TableColumn, VirtualCells,
|
||||
},
|
||||
poly::Rotation,
|
||||
|
@ -149,7 +149,7 @@ where
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<pallas::Base>,
|
||||
meta: &mut ConstraintSystemBuilder<pallas::Base>,
|
||||
advices: [Column<Advice>; 5],
|
||||
witness_pieces: Column<Advice>,
|
||||
fixed_y_q: Column<Fixed>,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use group::ff::PrimeField;
|
||||
use halo2_proofs::{
|
||||
circuit::{Layouter, Value},
|
||||
plonk::{ConstraintSystem, Error, Expression, TableColumn},
|
||||
plonk::{ConstraintSystemBuilder, Error, Expression, TableColumn},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ impl GeneratorTableConfig {
|
|||
/// this specific configuration sets up Sinsemilla-specific constraints
|
||||
/// controlled by `q_sinsemilla`, and would likely not apply to other chips.
|
||||
pub fn configure<Hash, Commit, F>(
|
||||
meta: &mut ConstraintSystem<pallas::Base>,
|
||||
meta: &mut ConstraintSystemBuilder<pallas::Base>,
|
||||
config: super::SinsemillaConfig<Hash, Commit, F>,
|
||||
) where
|
||||
Hash: HashDomains<pallas::Affine>,
|
||||
|
|
|
@ -192,7 +192,7 @@ pub mod tests {
|
|||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
dev::MockProver,
|
||||
pasta::pallas,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
|
@ -218,7 +218,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(),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Chip, Layouter, Value},
|
||||
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
use pasta_curves::pallas;
|
||||
|
@ -86,7 +86,7 @@ where
|
|||
{
|
||||
/// Configures the [`MerkleChip`].
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<pallas::Base>,
|
||||
meta: &mut ConstraintSystemBuilder<pallas::Base>,
|
||||
sinsemilla_config: SinsemillaConfig<Hash, Commit, F>,
|
||||
) -> MerkleConfig<Hash, Commit, F> {
|
||||
// All five advice columns are equality-enabled by SinsemillaConfig.
|
||||
|
|
|
@ -244,7 +244,7 @@ mod tests {
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, SimpleFloorPlanner},
|
||||
dev::{FailureLocation, MockProver, VerifyFailure},
|
||||
plonk::{Any, Circuit, ConstraintSystem, Constraints, Error, Selector},
|
||||
plonk::{Any, Circuit, ConstraintSystemBuilder, Constraints, Error, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
use pasta_curves::pallas;
|
||||
|
@ -276,7 +276,7 @@ mod tests {
|
|||
MyCircuit(self.0)
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<pallas::Base>) -> Self::Config {
|
||||
let selector = meta.selector();
|
||||
let advice = meta.advice_column();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::{bool_check, ternary, UtilitiesInstructions};
|
|||
use group::ff::{Field, PrimeField};
|
||||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Chip, Layouter, Value},
|
||||
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
@ -130,7 +130,7 @@ impl<F: PrimeField> CondSwapChip<F> {
|
|||
///
|
||||
/// `advices[0]` will be equality-enabled.
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
advices: [Column<Advice>; 5],
|
||||
) -> CondSwapConfig {
|
||||
let a = advices[0];
|
||||
|
@ -200,7 +200,7 @@ mod tests {
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
dev::MockProver,
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
use pasta_curves::pallas::Base;
|
||||
use rand::rngs::OsRng;
|
||||
|
@ -222,7 +222,7 @@ mod tests {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
let advices = [
|
||||
meta.advice_column(),
|
||||
meta.advice_column(),
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
use ff::PrimeFieldBits;
|
||||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Region, Value},
|
||||
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
||||
|
@ -68,7 +68,7 @@ impl<F: PrimeFieldBits, const WINDOW_NUM_BITS: usize> RunningSumConfig<F, WINDOW
|
|||
///
|
||||
/// `z` will be equality-enabled.
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
q_range_check: Selector,
|
||||
z: Column<Advice>,
|
||||
) -> Self {
|
||||
|
@ -212,7 +212,7 @@ mod tests {
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, SimpleFloorPlanner},
|
||||
dev::{FailureLocation, MockProver, VerifyFailure},
|
||||
plonk::{Any, Circuit, ConstraintSystem, Error},
|
||||
plonk::{Any, Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
use pasta_curves::pallas;
|
||||
use rand::rngs::OsRng;
|
||||
|
@ -252,7 +252,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
let z = meta.advice_column();
|
||||
let q_range_check = meta.selector();
|
||||
let constants = meta.fixed_column();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Layouter, Region},
|
||||
plonk::{Advice, Column, ConstraintSystem, Constraints, Error, Selector, TableColumn},
|
||||
plonk::{Advice, Column, ConstraintSystemBuilder, Constraints, Error, Selector, TableColumn},
|
||||
poly::Rotation,
|
||||
};
|
||||
use std::{convert::TryInto, marker::PhantomData};
|
||||
|
@ -78,7 +78,7 @@ impl<F: PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K> {
|
|||
///
|
||||
/// Both the `running_sum` and `constants` columns will be equality-enabled.
|
||||
pub fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
running_sum: Column<Advice>,
|
||||
table_idx: TableColumn,
|
||||
) -> Self {
|
||||
|
@ -176,7 +176,7 @@ impl<F: PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K> {
|
|||
/// Range check on an existing cell that is copied into this helper.
|
||||
///
|
||||
/// Returns an error if `element` is not in a column that was passed to
|
||||
/// [`ConstraintSystem::enable_equality`] during circuit configuration.
|
||||
/// [`ConstraintSystemBuilder::enable_equality`] during circuit configuration.
|
||||
pub fn copy_check(
|
||||
&self,
|
||||
mut layouter: impl Layouter<F>,
|
||||
|
@ -393,7 +393,7 @@ mod tests {
|
|||
use halo2_proofs::{
|
||||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
dev::{FailureLocation, MockProver, VerifyFailure},
|
||||
plonk::{Circuit, ConstraintSystem, Error},
|
||||
plonk::{Circuit, ConstraintSystemBuilder, Error},
|
||||
};
|
||||
use pasta_curves::pallas;
|
||||
|
||||
|
@ -415,7 +415,7 @@ mod tests {
|
|||
*self
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
let running_sum = meta.advice_column();
|
||||
let table_idx = meta.lookup_table_column();
|
||||
let constants = meta.fixed_column();
|
||||
|
@ -514,7 +514,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
let running_sum = meta.advice_column();
|
||||
let table_idx = meta.lookup_table_column();
|
||||
let constants = meta.fixed_column();
|
||||
|
|
|
@ -33,7 +33,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> MyConfig {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> MyConfig {
|
||||
let config = MyConfig {
|
||||
selector: meta.complex_selector(),
|
||||
table: meta.lookup_table_column(),
|
||||
|
|
|
@ -179,7 +179,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> PlonkConfig {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> PlonkConfig {
|
||||
meta.set_minimum_degree(5);
|
||||
|
||||
let a = meta.advice_column();
|
||||
|
|
|
@ -2,7 +2,9 @@ use ff::Field;
|
|||
use halo2_proofs::{
|
||||
circuit::{Cell, Layouter, Region, SimpleFloorPlanner, Value},
|
||||
pasta::Fp,
|
||||
plonk::{Advice, Assigned, Circuit, Column, ConstraintSystem, Error, Fixed, TableColumn},
|
||||
plonk::{
|
||||
Advice, Assigned, Circuit, Column, ConstraintSystemBuilder, Error, Fixed, TableColumn,
|
||||
},
|
||||
poly::Rotation,
|
||||
};
|
||||
use rand_core::OsRng;
|
||||
|
@ -170,7 +172,7 @@ impl<F: Field> Circuit<F> for MyCircuit<F> {
|
|||
}
|
||||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> PlonkConfig {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> PlonkConfig {
|
||||
let e = meta.advice_column();
|
||||
let a = meta.advice_column();
|
||||
let b = meta.advice_column();
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
|||
use group::ff::Field;
|
||||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystemBuilder, Error, Fixed, Instance, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
||||
|
@ -74,7 +74,7 @@ impl<F: Field> FieldChip<F> {
|
|||
}
|
||||
|
||||
fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
advice: [Column<Advice>; 2],
|
||||
instance: Column<Instance>,
|
||||
constant: Column<Fixed>,
|
||||
|
@ -253,7 +253,7 @@ impl<F: Field> Circuit<F> for MyCircuit<F> {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
// We create the two advice columns that FieldChip uses for I/O.
|
||||
let advice = [meta.advice_column(), meta.advice_column()];
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
|||
use group::ff::Field;
|
||||
use halo2_proofs::{
|
||||
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Instance, Selector},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystemBuilder, Error, Instance, Selector},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
||||
|
@ -153,7 +153,7 @@ impl<F: Field> AddChip<F> {
|
|||
}
|
||||
|
||||
fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
advice: [Column<Advice>; 2],
|
||||
) -> <Self as Chip<F>>::Config {
|
||||
let s_add = meta.selector();
|
||||
|
@ -255,7 +255,7 @@ impl<F: Field> MulChip<F> {
|
|||
}
|
||||
|
||||
fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
advice: [Column<Advice>; 2],
|
||||
) -> <Self as Chip<F>>::Config {
|
||||
for column in &advice {
|
||||
|
@ -376,7 +376,7 @@ impl<F: Field> FieldChip<F> {
|
|||
}
|
||||
|
||||
fn configure(
|
||||
meta: &mut ConstraintSystem<F>,
|
||||
meta: &mut ConstraintSystemBuilder<F>,
|
||||
advice: [Column<Advice>; 2],
|
||||
instance: Column<Instance>,
|
||||
) -> <Self as Chip<F>>::Config {
|
||||
|
@ -463,7 +463,7 @@ impl<F: Field> Circuit<F> for MyCircuit<F> {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
// We create the two advice columns that FieldChip uses for I/O.
|
||||
let advice = [meta.advice_column(), meta.advice_column()];
|
||||
|
||||
|
|
|
@ -384,7 +384,9 @@ mod tests {
|
|||
MyCircuit {}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut crate::plonk::ConstraintSystem<vesta::Scalar>) -> Self::Config {
|
||||
fn configure(
|
||||
meta: &mut crate::plonk::ConstraintSystemBuilder<vesta::Scalar>,
|
||||
) -> Self::Config {
|
||||
meta.advice_column()
|
||||
}
|
||||
|
||||
|
|
|
@ -498,7 +498,7 @@ mod tests {
|
|||
MyCircuit {}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut crate::plonk::ConstraintSystem<vesta::Scalar>) -> Self::Config {
|
||||
fn configure(meta: &mut crate::plonk::ConstraintSystemBuilder<vesta::Scalar>) -> Self::Config {
|
||||
meta.advice_column()
|
||||
}
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ mod tests {
|
|||
use crate::{
|
||||
circuit::{Layouter, SimpleFloorPlanner},
|
||||
dev::MockProver,
|
||||
plonk::{Circuit, ConstraintSystem},
|
||||
plonk::{Circuit, ConstraintSystemBuilder},
|
||||
poly::Rotation,
|
||||
};
|
||||
|
||||
|
@ -182,7 +182,7 @@ mod tests {
|
|||
Self
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
|
||||
let a = meta.advice_column();
|
||||
let table = meta.lookup_table_column();
|
||||
|
||||
|
@ -240,7 +240,7 @@ mod tests {
|
|||
Self
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
|
||||
let a = meta.advice_column();
|
||||
let table = meta.lookup_table_column();
|
||||
|
||||
|
@ -304,7 +304,7 @@ mod tests {
|
|||
Self
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
|
||||
let a = meta.advice_column();
|
||||
let table = meta.lookup_table_column();
|
||||
|
||||
|
@ -369,7 +369,7 @@ mod tests {
|
|||
Self
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
|
||||
let a = meta.advice_column();
|
||||
let table = (meta.lookup_table_column(), meta.lookup_table_column());
|
||||
meta.lookup(|cells| {
|
||||
|
|
|
@ -11,8 +11,8 @@ use crate::plonk::Assigned;
|
|||
use crate::{
|
||||
circuit,
|
||||
plonk::{
|
||||
permutation, Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Error, Expression,
|
||||
Fixed, FloorPlanner, Instance, Selector,
|
||||
permutation, Advice, Any, Assignment, Circuit, Column, ConstraintSystemBuilder, Error,
|
||||
Expression, Fixed, FloorPlanner, Instance, Selector,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -198,7 +198,7 @@ impl<F: Field> Mul<F> for Value<F> {
|
|||
/// Self::default()
|
||||
/// }
|
||||
///
|
||||
/// fn configure(meta: &mut ConstraintSystem<F>) -> MyConfig {
|
||||
/// fn configure(meta: &mut ConstraintSystemBuilder<F>) -> MyConfig {
|
||||
/// let a = meta.advice_column();
|
||||
/// let b = meta.advice_column();
|
||||
/// let c = meta.advice_column();
|
||||
|
@ -272,7 +272,7 @@ impl<F: Field> Mul<F> for Value<F> {
|
|||
pub struct MockProver<F: Field> {
|
||||
k: u32,
|
||||
n: u32,
|
||||
cs: ConstraintSystem<F>,
|
||||
cs: ConstraintSystemBuilder<F>,
|
||||
|
||||
/// The regions in the circuit.
|
||||
regions: Vec<Region>,
|
||||
|
@ -489,7 +489,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
) -> Result<Self, Error> {
|
||||
let n = 1 << k;
|
||||
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut cs);
|
||||
let cs = cs;
|
||||
|
||||
|
@ -497,7 +497,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
return Err(Error::not_enough_rows_available(k));
|
||||
}
|
||||
|
||||
if instance.len() != cs.num_instance_columns {
|
||||
if instance.len() != cs.cs.num_instance_columns {
|
||||
return Err(Error::InvalidInstances);
|
||||
}
|
||||
|
||||
|
@ -518,8 +518,8 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
// Fixed columns contain no blinding factors.
|
||||
let fixed = vec![vec![CellValue::Unassigned; n]; cs.num_fixed_columns];
|
||||
let selectors = vec![vec![false; n]; cs.num_selectors];
|
||||
let fixed = vec![vec![CellValue::Unassigned; n]; cs.cs.num_fixed_columns];
|
||||
let selectors = vec![vec![false; n]; cs.cs.num_selectors];
|
||||
// Advice columns contain blinding factors.
|
||||
let blinding_factors = cs.blinding_factors();
|
||||
let usable_rows = n - (blinding_factors + 1);
|
||||
|
@ -532,10 +532,10 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
}
|
||||
column
|
||||
};
|
||||
cs.num_advice_columns
|
||||
cs.cs.num_advice_columns
|
||||
];
|
||||
let permutation = permutation::keygen::Assembly::new(n, &cs.permutation);
|
||||
let constants = cs.constants.clone();
|
||||
let permutation = permutation::keygen::Assembly::new(n, &cs.cs.permutation);
|
||||
let constants = cs.cs.constants.clone();
|
||||
|
||||
let mut prover = MockProver {
|
||||
k,
|
||||
|
@ -577,6 +577,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
r.enabled_selectors.iter().flat_map(move |(selector, at)| {
|
||||
// Find the gates enabled by this selector
|
||||
self.cs
|
||||
.cs
|
||||
.gates
|
||||
.iter()
|
||||
// Assume that if a queried selector is enabled, the user wants to use the
|
||||
|
@ -638,6 +639,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
// Check that all gates are satisfied for all rows.
|
||||
let gate_errors =
|
||||
self.cs
|
||||
.cs
|
||||
.gates
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
@ -648,12 +650,12 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
move |(poly_index, poly)| match poly.evaluate(
|
||||
&|scalar| Value::Real(scalar),
|
||||
&|_| panic!("virtual selectors are removed during optimization"),
|
||||
&util::load(n, row, &self.cs.fixed_queries, &self.fixed),
|
||||
&util::load(n, row, &self.cs.advice_queries, &self.advice),
|
||||
&util::load(n, row, &self.cs.cs.fixed_queries, &self.fixed),
|
||||
&util::load(n, row, &self.cs.cs.advice_queries, &self.advice),
|
||||
&util::load_instance(
|
||||
n,
|
||||
row,
|
||||
&self.cs.instance_queries,
|
||||
&self.cs.cs.instance_queries,
|
||||
&self.instance,
|
||||
),
|
||||
&|a| -a,
|
||||
|
@ -670,7 +672,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
)
|
||||
.into(),
|
||||
location: FailureLocation::find_expressions(
|
||||
&self.cs,
|
||||
&self.cs.cs,
|
||||
&self.regions,
|
||||
(row - n) as usize,
|
||||
Some(poly).into_iter(),
|
||||
|
@ -678,12 +680,17 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
cell_values: util::cell_values(
|
||||
gate,
|
||||
poly,
|
||||
&util::load(n, row, &self.cs.fixed_queries, &self.fixed),
|
||||
&util::load(n, row, &self.cs.advice_queries, &self.advice),
|
||||
&util::load(n, row, &self.cs.cs.fixed_queries, &self.fixed),
|
||||
&util::load(
|
||||
n,
|
||||
row,
|
||||
&self.cs.cs.advice_queries,
|
||||
&self.advice,
|
||||
),
|
||||
&util::load_instance(
|
||||
n,
|
||||
row,
|
||||
&self.cs.instance_queries,
|
||||
&self.cs.cs.instance_queries,
|
||||
&self.instance,
|
||||
),
|
||||
),
|
||||
|
@ -704,6 +711,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
// Check that all lookups exist in their respective tables.
|
||||
let lookup_errors =
|
||||
self.cs
|
||||
.cs
|
||||
.lookups
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
@ -713,7 +721,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
&|scalar| Value::Real(scalar),
|
||||
&|_| panic!("virtual selectors are removed during optimization"),
|
||||
&|query| {
|
||||
let query = self.cs.fixed_queries[query.index];
|
||||
let query = self.cs.cs.fixed_queries[query.index];
|
||||
let column_index = query.0.index();
|
||||
let rotation = query.1 .0;
|
||||
self.fixed[column_index]
|
||||
|
@ -721,7 +729,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
.into()
|
||||
},
|
||||
&|query| {
|
||||
let query = self.cs.advice_queries[query.index];
|
||||
let query = self.cs.cs.advice_queries[query.index];
|
||||
let column_index = query.0.index();
|
||||
let rotation = query.1 .0;
|
||||
self.advice[column_index]
|
||||
|
@ -729,7 +737,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
.into()
|
||||
},
|
||||
&|query| {
|
||||
let query = self.cs.instance_queries[query.index];
|
||||
let query = self.cs.cs.instance_queries[query.index];
|
||||
let column_index = query.0.index();
|
||||
let rotation = query.1 .0;
|
||||
Value::Real(
|
||||
|
@ -814,7 +822,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
Some(VerifyFailure::Lookup {
|
||||
lookup_index,
|
||||
location: FailureLocation::find_expressions(
|
||||
&self.cs,
|
||||
&self.cs.cs,
|
||||
&self.regions,
|
||||
*input_row,
|
||||
lookup.input_expressions.iter(),
|
||||
|
@ -832,6 +840,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
// Original values of columns involved in the permutation.
|
||||
let original = |column, row| {
|
||||
self.cs
|
||||
.cs
|
||||
.permutation
|
||||
.get_columns()
|
||||
.get(column)
|
||||
|
@ -860,7 +869,7 @@ impl<F: Field + Ord> MockProver<F> {
|
|||
if original_cell == permuted_cell {
|
||||
None
|
||||
} else {
|
||||
let columns = self.cs.permutation.get_columns();
|
||||
let columns = self.cs.cs.permutation.get_columns();
|
||||
let column = columns.get(column).unwrap();
|
||||
Some(VerifyFailure::Permutation {
|
||||
column: (*column).into(),
|
||||
|
@ -927,7 +936,7 @@ mod tests {
|
|||
use crate::{
|
||||
circuit::{Layouter, SimpleFloorPlanner, Value},
|
||||
plonk::{
|
||||
Advice, Any, Circuit, Column, ConstraintSystem, Error, Expression, Selector,
|
||||
Advice, Any, Circuit, Column, ConstraintSystemBuilder, Error, Expression, Selector,
|
||||
TableColumn,
|
||||
},
|
||||
poly::Rotation,
|
||||
|
@ -949,7 +958,7 @@ mod tests {
|
|||
type Config = FaultyCircuitConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
|
||||
let a = meta.advice_column();
|
||||
let b = meta.advice_column();
|
||||
let q = meta.selector();
|
||||
|
@ -1023,7 +1032,7 @@ mod tests {
|
|||
type Config = FaultyCircuitConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<Fp>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {
|
||||
let a = meta.advice_column();
|
||||
let q = meta.complex_selector();
|
||||
let table = meta.lookup_table_column();
|
||||
|
|
|
@ -14,7 +14,7 @@ use group::prime::PrimeGroup;
|
|||
use crate::{
|
||||
circuit::{layouter::RegionColumn, Value},
|
||||
plonk::{
|
||||
Advice, Any, Assigned, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed,
|
||||
Advice, Any, Assigned, Assignment, Circuit, Column, ConstraintSystemBuilder, Error, Fixed,
|
||||
FloorPlanner, Instance, Selector,
|
||||
},
|
||||
poly::Rotation,
|
||||
|
@ -260,14 +260,14 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
|
|||
/// Panics if `k` is not large enough for the circuit.
|
||||
pub fn measure(k: u32, circuit: &ConcreteCircuit) -> Self {
|
||||
// Collect the layout details.
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut cs);
|
||||
let mut layout = Layout::new(k, 1 << k, cs.num_selectors);
|
||||
let mut layout = Layout::new(k, 1 << k, cs.cs.num_selectors);
|
||||
ConcreteCircuit::FloorPlanner::synthesize(
|
||||
&mut layout,
|
||||
circuit,
|
||||
config,
|
||||
cs.constants.clone(),
|
||||
cs.cs.constants.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let (cs, _) = cs.compress_selectors(layout.selectors);
|
||||
|
@ -278,14 +278,21 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
|
|||
let mut column_queries: HashMap<Column<Any>, HashSet<i32>> = HashMap::new();
|
||||
for (c, r) in iter::empty()
|
||||
.chain(
|
||||
cs.advice_queries
|
||||
cs.cs
|
||||
.advice_queries
|
||||
.iter()
|
||||
.map(|(c, r)| (Column::<Any>::from(*c), *r)),
|
||||
)
|
||||
.chain(cs.instance_queries.iter().map(|(c, r)| ((*c).into(), *r)))
|
||||
.chain(cs.fixed_queries.iter().map(|(c, r)| ((*c).into(), *r)))
|
||||
.chain(
|
||||
cs.permutation
|
||||
cs.cs
|
||||
.instance_queries
|
||||
.iter()
|
||||
.map(|(c, r)| ((*c).into(), *r)),
|
||||
)
|
||||
.chain(cs.cs.fixed_queries.iter().map(|(c, r)| ((*c).into(), *r)))
|
||||
.chain(
|
||||
cs.cs
|
||||
.permutation
|
||||
.get_columns()
|
||||
.into_iter()
|
||||
.map(|c| (c, Rotation::cur())),
|
||||
|
@ -309,7 +316,7 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
|
|||
// Include permutation polynomials in point sets.
|
||||
point_sets.insert(vec![0, 1]); // permutation_product_poly
|
||||
let max_deg = cs.degree();
|
||||
let permutation_cols = cs.permutation.get_columns().len();
|
||||
let permutation_cols = cs.cs.permutation.get_columns().len();
|
||||
if permutation_cols > max_deg - 2 {
|
||||
// permutation_product_poly for chaining chunks.
|
||||
point_sets.insert(vec![-((cs.blinding_factors() + 1) as i32), 0, 1]);
|
||||
|
@ -318,23 +325,23 @@ impl<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, Concrete
|
|||
CircuitCost {
|
||||
k,
|
||||
max_deg,
|
||||
advice_columns: cs.num_advice_columns,
|
||||
instance_queries: cs.instance_queries.len(),
|
||||
advice_queries: cs.advice_queries.len(),
|
||||
fixed_queries: cs.fixed_queries.len(),
|
||||
lookups: cs.lookups.len(),
|
||||
advice_columns: cs.cs.num_advice_columns,
|
||||
instance_queries: cs.cs.instance_queries.len(),
|
||||
advice_queries: cs.cs.advice_queries.len(),
|
||||
fixed_queries: cs.cs.fixed_queries.len(),
|
||||
lookups: cs.cs.lookups.len(),
|
||||
permutation_cols,
|
||||
point_sets: point_sets.len(),
|
||||
_marker: PhantomData::default(),
|
||||
max_rows: layout.total_rows,
|
||||
max_advice_rows: layout.total_advice_rows,
|
||||
max_fixed_rows: layout.total_fixed_rows,
|
||||
num_advice_columns: cs.num_advice_columns,
|
||||
num_fixed_columns: cs.num_fixed_columns,
|
||||
num_instance_columns: cs.num_instance_columns,
|
||||
num_total_columns: cs.num_instance_columns
|
||||
+ cs.num_advice_columns
|
||||
+ cs.num_fixed_columns,
|
||||
num_advice_columns: cs.cs.num_advice_columns,
|
||||
num_fixed_columns: cs.cs.num_fixed_columns,
|
||||
num_instance_columns: cs.cs.num_instance_columns,
|
||||
num_total_columns: cs.cs.num_instance_columns
|
||||
+ cs.cs.num_advice_columns
|
||||
+ cs.cs.num_fixed_columns,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,7 +538,7 @@ mod tests {
|
|||
Self
|
||||
}
|
||||
|
||||
fn configure(_meta: &mut ConstraintSystem<Fp>) -> Self::Config {}
|
||||
fn configure(_meta: &mut ConstraintSystemBuilder<Fp>) -> Self::Config {}
|
||||
|
||||
fn synthesize(
|
||||
&self,
|
||||
|
|
|
@ -400,7 +400,7 @@ fn render_lookup<F: Field>(
|
|||
) {
|
||||
let n = prover.n as i32;
|
||||
let cs = &prover.cs;
|
||||
let lookup = &cs.lookups[lookup_index];
|
||||
let lookup = &cs.cs.lookups[lookup_index];
|
||||
|
||||
// Get the absolute row on which the lookup's inputs are being queried, so we can
|
||||
// fetch the input values.
|
||||
|
@ -469,15 +469,15 @@ fn render_lookup<F: Field>(
|
|||
&|_| panic!("virtual selectors are removed during optimization"),
|
||||
&cell_value(
|
||||
Any::Fixed,
|
||||
&util::load(n, row, &cs.fixed_queries, &prover.fixed),
|
||||
&util::load(n, row, &cs.cs.fixed_queries, &prover.fixed),
|
||||
),
|
||||
&cell_value(
|
||||
Any::Advice,
|
||||
&util::load(n, row, &cs.advice_queries, &prover.advice),
|
||||
&util::load(n, row, &cs.cs.advice_queries, &prover.advice),
|
||||
),
|
||||
&cell_value(
|
||||
Any::Instance,
|
||||
&util::load_instance(n, row, &cs.instance_queries, &prover.instance),
|
||||
&util::load_instance(n, row, &cs.cs.instance_queries, &prover.instance),
|
||||
),
|
||||
&|a| a,
|
||||
&|mut a, mut b| {
|
||||
|
@ -541,7 +541,7 @@ impl VerifyFailure {
|
|||
column,
|
||||
offset,
|
||||
} => render_cell_not_assigned(
|
||||
&prover.cs.gates,
|
||||
&prover.cs.cs.gates,
|
||||
gate,
|
||||
region,
|
||||
*gate_offset,
|
||||
|
@ -552,9 +552,12 @@ impl VerifyFailure {
|
|||
constraint,
|
||||
location,
|
||||
cell_values,
|
||||
} => {
|
||||
render_constraint_not_satisfied(&prover.cs.gates, constraint, location, cell_values)
|
||||
}
|
||||
} => render_constraint_not_satisfied(
|
||||
&prover.cs.cs.gates,
|
||||
constraint,
|
||||
location,
|
||||
cell_values,
|
||||
),
|
||||
Self::Lookup {
|
||||
lookup_index,
|
||||
location,
|
||||
|
|
|
@ -7,7 +7,7 @@ use ff::PrimeField;
|
|||
|
||||
use crate::{
|
||||
dev::util,
|
||||
plonk::{Circuit, ConstraintSystem},
|
||||
plonk::{Circuit, ConstraintSystemBuilder},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -51,7 +51,7 @@ struct Gate {
|
|||
/// Self::default()
|
||||
/// }
|
||||
///
|
||||
/// fn configure(meta: &mut ConstraintSystem<F>) -> MyConfig {
|
||||
/// fn configure(meta: &mut ConstraintSystemBuilder<F>) -> MyConfig {
|
||||
/// let a = meta.advice_column();
|
||||
/// let b = meta.advice_column();
|
||||
/// let c = meta.advice_column();
|
||||
|
@ -102,10 +102,11 @@ impl CircuitGates {
|
|||
/// Collects the gates from within the circuit.
|
||||
pub fn collect<F: PrimeField, C: Circuit<F>>() -> Self {
|
||||
// Collect the graph details.
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let _ = C::configure(&mut cs);
|
||||
|
||||
let gates = cs
|
||||
.cs
|
||||
.gates
|
||||
.iter()
|
||||
.map(|gate| Gate {
|
||||
|
@ -185,6 +186,7 @@ impl CircuitGates {
|
|||
.collect();
|
||||
|
||||
let (total_negations, total_additions, total_multiplications) = cs
|
||||
.cs
|
||||
.gates
|
||||
.iter()
|
||||
.flat_map(|gate| {
|
||||
|
|
|
@ -4,7 +4,7 @@ use tabbycat::{AttrList, Edge, GraphBuilder, GraphType, Identity, StmtList};
|
|||
use crate::{
|
||||
circuit::Value,
|
||||
plonk::{
|
||||
Advice, Any, Assigned, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed,
|
||||
Advice, Any, Assigned, Assignment, Circuit, Column, ConstraintSystemBuilder, Error, Fixed,
|
||||
FloorPlanner, Instance, Selector,
|
||||
},
|
||||
};
|
||||
|
@ -21,10 +21,10 @@ pub fn circuit_dot_graph<F: Field, ConcreteCircuit: Circuit<F>>(
|
|||
circuit: &ConcreteCircuit,
|
||||
) -> String {
|
||||
// Collect the graph details.
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut cs);
|
||||
let mut graph = Graph::default();
|
||||
ConcreteCircuit::FloorPlanner::synthesize(&mut graph, circuit, config, cs.constants).unwrap();
|
||||
ConcreteCircuit::FloorPlanner::synthesize(&mut graph, circuit, config, cs.cs.constants).unwrap();
|
||||
|
||||
// Construct the node labels. We need to store these, because tabbycat operates on
|
||||
// string references, and we need those references to live long enough.
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::ops::Range;
|
|||
use crate::{
|
||||
circuit::layouter::RegionColumn,
|
||||
dev::cost::Layout,
|
||||
plonk::{Any, Circuit, Column, ConstraintSystem, FloorPlanner},
|
||||
plonk::{Any, Circuit, Column, ConstraintSystemBuilder, FloorPlanner},
|
||||
};
|
||||
|
||||
/// Graphical renderer for circuit layouts.
|
||||
|
@ -93,23 +93,24 @@ impl CircuitLayout {
|
|||
|
||||
let n = 1 << k;
|
||||
// Collect the layout details.
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut cs);
|
||||
let mut layout = Layout::new(k, n, cs.num_selectors);
|
||||
let mut layout = Layout::new(k, n, cs.cs.num_selectors);
|
||||
ConcreteCircuit::FloorPlanner::synthesize(
|
||||
&mut layout,
|
||||
circuit,
|
||||
config,
|
||||
cs.constants.clone(),
|
||||
cs.cs.constants.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let (cs, selector_polys) = cs.compress_selectors(layout.selectors);
|
||||
let non_selector_fixed_columns = cs.num_fixed_columns - selector_polys.len();
|
||||
let non_selector_fixed_columns = cs.cs.num_fixed_columns - selector_polys.len();
|
||||
|
||||
// Figure out what order to render the columns in.
|
||||
// TODO: For now, just render them in the order they were configured.
|
||||
let total_columns = cs.num_instance_columns + cs.num_advice_columns + cs.num_fixed_columns;
|
||||
let column_index = |cs: &ConstraintSystem<F>, column: RegionColumn| {
|
||||
let total_columns =
|
||||
cs.cs.num_instance_columns + cs.cs.num_advice_columns + cs.cs.num_fixed_columns;
|
||||
let column_index = |cs: &ConstraintSystemBuilder<F>, column: RegionColumn| {
|
||||
let column: Column<Any> = match column {
|
||||
RegionColumn::Column(col) => col,
|
||||
RegionColumn::Selector(selector) => cs.selector_map[selector.0].into(),
|
||||
|
@ -117,8 +118,8 @@ impl CircuitLayout {
|
|||
column.index()
|
||||
+ match column.column_type() {
|
||||
Any::Instance => 0,
|
||||
Any::Advice => cs.num_instance_columns,
|
||||
Any::Fixed => cs.num_instance_columns + cs.num_advice_columns,
|
||||
Any::Advice => cs.cs.num_instance_columns,
|
||||
Any::Fixed => cs.cs.num_instance_columns + cs.cs.num_advice_columns,
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -140,14 +141,17 @@ impl CircuitLayout {
|
|||
))?;
|
||||
root.draw(&Rectangle::new(
|
||||
[
|
||||
(cs.num_instance_columns, 0),
|
||||
(cs.num_instance_columns + cs.num_advice_columns, view_bottom),
|
||||
(cs.cs.num_instance_columns, 0),
|
||||
(
|
||||
cs.cs.num_instance_columns + cs.cs.num_advice_columns,
|
||||
view_bottom,
|
||||
),
|
||||
],
|
||||
ShapeStyle::from(&RED.mix(0.2)).filled(),
|
||||
))?;
|
||||
root.draw(&Rectangle::new(
|
||||
[
|
||||
(cs.num_instance_columns + cs.num_advice_columns, 0),
|
||||
(cs.cs.num_instance_columns + cs.cs.num_advice_columns, 0),
|
||||
(total_columns, view_bottom),
|
||||
],
|
||||
ShapeStyle::from(&BLUE.mix(0.2)).filled(),
|
||||
|
@ -156,8 +160,8 @@ impl CircuitLayout {
|
|||
root.draw(&Rectangle::new(
|
||||
[
|
||||
(
|
||||
cs.num_instance_columns
|
||||
+ cs.num_advice_columns
|
||||
cs.cs.num_instance_columns
|
||||
+ cs.cs.num_advice_columns
|
||||
+ non_selector_fixed_columns,
|
||||
0,
|
||||
),
|
||||
|
|
|
@ -6,7 +6,7 @@ use tracing::{debug, debug_span, span::EnteredSpan};
|
|||
use crate::{
|
||||
circuit::{layouter::RegionLayouter, AssignedCell, Cell, Layouter, Region, Table, Value},
|
||||
plonk::{
|
||||
Advice, Any, Assigned, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed,
|
||||
Advice, Any, Assigned, Assignment, Circuit, Column, ConstraintSystemBuilder, Error, Fixed,
|
||||
FloorPlanner, Instance, Selector,
|
||||
},
|
||||
};
|
||||
|
@ -50,7 +50,7 @@ use crate::{
|
|||
/// Self { some_witness: Value::unknown() }
|
||||
/// }
|
||||
///
|
||||
/// fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
/// fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
/// // ..
|
||||
/// # todo!()
|
||||
/// }
|
||||
|
@ -126,7 +126,7 @@ impl<'c, F: Field, C: Circuit<F>> Circuit<F> for TracingCircuit<'c, F, C> {
|
|||
Self::owned(self.inner_ref().without_witnesses())
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {
|
||||
let _span = debug_span!("configure").entered();
|
||||
C::configure(meta)
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ pub struct VerifyingKey<C: CurveAffine> {
|
|||
cs: ConstraintSystem<C::Scalar>,
|
||||
/// Cached maximum degree of `cs` (which doesn't change after construction).
|
||||
cs_degree: usize,
|
||||
/// Cached number of blinding factors (which doesn't change after construction).
|
||||
num_blinding_factors: usize,
|
||||
/// The representative of this `VerifyingKey` in transcripts.
|
||||
transcript_repr: C::Scalar,
|
||||
}
|
||||
|
@ -57,17 +59,19 @@ where
|
|||
domain: EvaluationDomain<C::Scalar>,
|
||||
fixed_commitments: Vec<C>,
|
||||
permutation: permutation::VerifyingKey<C>,
|
||||
cs: ConstraintSystem<C::Scalar>,
|
||||
cs: ConstraintSystemBuilder<C::Scalar>,
|
||||
) -> Self {
|
||||
// Compute cached values.
|
||||
let cs_degree = cs.degree();
|
||||
let num_blinding_factors = cs.blinding_factors();
|
||||
|
||||
let mut vk = Self {
|
||||
domain,
|
||||
fixed_commitments,
|
||||
permutation,
|
||||
cs,
|
||||
cs: cs.cs,
|
||||
cs_degree,
|
||||
num_blinding_factors,
|
||||
// Temporary, this is not pinned.
|
||||
transcript_repr: C::Scalar::ZERO,
|
||||
};
|
||||
|
|
|
@ -305,7 +305,7 @@ pub struct InstanceQuery {
|
|||
///
|
||||
/// A lookup table can be loaded into this column via [`Layouter::assign_table`]. Columns
|
||||
/// can currently only contain a single table, but they may be used in multiple lookup
|
||||
/// arguments via [`ConstraintSystem::lookup`].
|
||||
/// arguments via [`ConstraintSystemBuilder::lookup`].
|
||||
///
|
||||
/// Lookup table columns are always "encumbered" by the lookup arguments they are used in;
|
||||
/// they cannot simultaneously be used as general fixed columns.
|
||||
|
@ -329,7 +329,7 @@ impl TableColumn {
|
|||
}
|
||||
|
||||
/// Enable equality on this TableColumn.
|
||||
pub fn enable_equality<F: Field>(&self, meta: &mut ConstraintSystem<F>) {
|
||||
pub fn enable_equality<F: Field>(&self, meta: &mut ConstraintSystemBuilder<F>) {
|
||||
meta.enable_equality(self.inner)
|
||||
}
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ pub trait Circuit<F: Field> {
|
|||
|
||||
/// The circuit is given an opportunity to describe the exact gate
|
||||
/// arrangement, column arrangement, etc.
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config;
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> Self::Config;
|
||||
|
||||
/// Given the provided `cs`, synthesize the circuit. The concrete type of
|
||||
/// the caller will be different depending on the context, and they may or
|
||||
|
@ -928,6 +928,22 @@ impl<F: Field> Gate<F> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A builder type for a [`ConstraintSystem`].
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ConstraintSystemBuilder<F: Field> {
|
||||
pub(crate) cs: ConstraintSystem<F>,
|
||||
|
||||
/// This is a cached vector that maps virtual selectors to the concrete
|
||||
/// fixed column that they were compressed into. This is just used by dev
|
||||
/// tooling right now.
|
||||
pub(crate) selector_map: Vec<Column<Fixed>>,
|
||||
|
||||
// Contains an integer for each advice column
|
||||
// identifying how many distinct queries it has
|
||||
// so far; should be same length as num_advice_columns.
|
||||
num_advice_queries: Vec<usize>,
|
||||
}
|
||||
|
||||
/// This is a description of the circuit environment, such as the gate, column and
|
||||
/// permutation arrangements.
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -937,17 +953,8 @@ pub struct ConstraintSystem<F: Field> {
|
|||
pub(crate) num_instance_columns: usize,
|
||||
pub(crate) num_selectors: usize,
|
||||
|
||||
/// This is a cached vector that maps virtual selectors to the concrete
|
||||
/// fixed column that they were compressed into. This is just used by dev
|
||||
/// tooling right now.
|
||||
pub(crate) selector_map: Vec<Column<Fixed>>,
|
||||
|
||||
pub(crate) gates: Vec<Gate<F>>,
|
||||
pub(crate) advice_queries: Vec<(Column<Advice>, Rotation)>,
|
||||
// Contains an integer for each advice column
|
||||
// identifying how many distinct queries it has
|
||||
// so far; should be same length as num_advice_columns.
|
||||
num_advice_queries: Vec<usize>,
|
||||
pub(crate) instance_queries: Vec<(Column<Instance>, Rotation)>,
|
||||
pub(crate) fixed_queries: Vec<(Column<Fixed>, Rotation)>,
|
||||
|
||||
|
@ -1000,11 +1007,9 @@ impl<F: Field> Default for ConstraintSystem<F> {
|
|||
num_advice_columns: 0,
|
||||
num_instance_columns: 0,
|
||||
num_selectors: 0,
|
||||
selector_map: vec![],
|
||||
gates: vec![],
|
||||
fixed_queries: Vec::new(),
|
||||
advice_queries: Vec::new(),
|
||||
num_advice_queries: Vec::new(),
|
||||
instance_queries: Vec::new(),
|
||||
permutation: permutation::Argument::new(),
|
||||
lookups: Vec::new(),
|
||||
|
@ -1034,15 +1039,17 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
minimum_degree: &self.minimum_degree,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> ConstraintSystemBuilder<F> {
|
||||
/// Enables this fixed column to be used for global constant assignments.
|
||||
///
|
||||
/// # Side-effects
|
||||
///
|
||||
/// The column will be equality-enabled.
|
||||
pub fn enable_constant(&mut self, column: Column<Fixed>) {
|
||||
if !self.constants.contains(&column) {
|
||||
self.constants.push(column);
|
||||
if !self.cs.constants.contains(&column) {
|
||||
self.cs.constants.push(column);
|
||||
self.enable_equality(column);
|
||||
}
|
||||
}
|
||||
|
@ -1051,7 +1058,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
pub fn enable_equality<C: Into<Column<Any>>>(&mut self, column: C) {
|
||||
let column = column.into();
|
||||
self.query_any_index(column, Rotation::cur());
|
||||
self.permutation.add_column(column);
|
||||
self.cs.permutation.add_column(column);
|
||||
}
|
||||
|
||||
/// Add a lookup argument for some input expressions and table columns.
|
||||
|
@ -1076,39 +1083,39 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let index = self.lookups.len();
|
||||
let index = self.cs.lookups.len();
|
||||
|
||||
self.lookups.push(lookup::Argument::new(table_map));
|
||||
self.cs.lookups.push(lookup::Argument::new(table_map));
|
||||
|
||||
index
|
||||
}
|
||||
|
||||
fn query_fixed_index(&mut self, column: Column<Fixed>) -> usize {
|
||||
// Return existing query, if it exists
|
||||
for (index, fixed_query) in self.fixed_queries.iter().enumerate() {
|
||||
for (index, fixed_query) in self.cs.fixed_queries.iter().enumerate() {
|
||||
if fixed_query == &(column, Rotation::cur()) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new query
|
||||
let index = self.fixed_queries.len();
|
||||
self.fixed_queries.push((column, Rotation::cur()));
|
||||
let index = self.cs.fixed_queries.len();
|
||||
self.cs.fixed_queries.push((column, Rotation::cur()));
|
||||
|
||||
index
|
||||
}
|
||||
|
||||
pub(crate) fn query_advice_index(&mut self, column: Column<Advice>, at: Rotation) -> usize {
|
||||
// Return existing query, if it exists
|
||||
for (index, advice_query) in self.advice_queries.iter().enumerate() {
|
||||
for (index, advice_query) in self.cs.advice_queries.iter().enumerate() {
|
||||
if advice_query == &(column, at) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new query
|
||||
let index = self.advice_queries.len();
|
||||
self.advice_queries.push((column, at));
|
||||
let index = self.cs.advice_queries.len();
|
||||
self.cs.advice_queries.push((column, at));
|
||||
self.num_advice_queries[column.index] += 1;
|
||||
|
||||
index
|
||||
|
@ -1116,15 +1123,15 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
|
||||
fn query_instance_index(&mut self, column: Column<Instance>, at: Rotation) -> usize {
|
||||
// Return existing query, if it exists
|
||||
for (index, instance_query) in self.instance_queries.iter().enumerate() {
|
||||
for (index, instance_query) in self.cs.instance_queries.iter().enumerate() {
|
||||
if instance_query == &(column, at) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new query
|
||||
let index = self.instance_queries.len();
|
||||
self.instance_queries.push((column, at));
|
||||
let index = self.cs.instance_queries.len();
|
||||
self.cs.instance_queries.push((column, at));
|
||||
|
||||
index
|
||||
}
|
||||
|
@ -1138,7 +1145,9 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> ConstraintSystem<F> {
|
||||
pub(crate) fn get_advice_query_index(&self, column: Column<Advice>, at: Rotation) -> usize {
|
||||
for (index, advice_query) in self.advice_queries.iter().enumerate() {
|
||||
if advice_query == &(column, at) {
|
||||
|
@ -1183,12 +1192,14 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> ConstraintSystemBuilder<F> {
|
||||
/// Sets the minimum degree required by the circuit, which can be set to a
|
||||
/// larger amount than actually needed. This can be used, for example, to
|
||||
/// force the permutation argument to involve more columns in the same set.
|
||||
pub fn set_minimum_degree(&mut self, degree: usize) {
|
||||
self.minimum_degree = Some(degree);
|
||||
self.cs.minimum_degree = Some(degree);
|
||||
}
|
||||
|
||||
/// Creates a new gate.
|
||||
|
@ -1218,7 +1229,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
"Gates must contain at least one constraint."
|
||||
);
|
||||
|
||||
self.gates.push(Gate {
|
||||
self.cs.gates.push(Gate {
|
||||
name,
|
||||
constraint_names,
|
||||
polys,
|
||||
|
@ -1237,14 +1248,14 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
pub(crate) fn compress_selectors(mut self, selectors: Vec<Vec<bool>>) -> (Self, Vec<Vec<F>>) {
|
||||
// The number of provided selector assignments must be the number we
|
||||
// counted for this constraint system.
|
||||
assert_eq!(selectors.len(), self.num_selectors);
|
||||
assert_eq!(selectors.len(), self.cs.num_selectors);
|
||||
|
||||
// Compute the maximal degree of every selector. We only consider the
|
||||
// expressions in gates, as lookup arguments cannot support simple
|
||||
// selectors. Selectors that are complex or do not appear in any gates
|
||||
// will have degree zero.
|
||||
let mut degrees = vec![0; selectors.len()];
|
||||
for expr in self.gates.iter().flat_map(|gate| gate.polys.iter()) {
|
||||
for expr in self.cs.gates.iter().flat_map(|gate| gate.polys.iter()) {
|
||||
if let Some(selector) = expr.extract_simple_selector() {
|
||||
degrees[selector.0] = max(degrees[selector.0], expr.degree());
|
||||
}
|
||||
|
@ -1324,13 +1335,18 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
}
|
||||
|
||||
// Substitute selectors for the real fixed columns in all gates
|
||||
for expr in self.gates.iter_mut().flat_map(|gate| gate.polys.iter_mut()) {
|
||||
for expr in self
|
||||
.cs
|
||||
.gates
|
||||
.iter_mut()
|
||||
.flat_map(|gate| gate.polys.iter_mut())
|
||||
{
|
||||
replace_selectors(expr, &selector_replacements, false);
|
||||
}
|
||||
|
||||
// Substitute non-simple selectors for the real fixed columns in all
|
||||
// lookup expressions
|
||||
for expr in self.lookups.iter_mut().flat_map(|lookup| {
|
||||
for expr in self.cs.lookups.iter_mut().flat_map(|lookup| {
|
||||
lookup
|
||||
.input_expressions
|
||||
.iter_mut()
|
||||
|
@ -1347,16 +1363,16 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
/// selectors. Also, simple selectors may not appear in lookup argument
|
||||
/// inputs.
|
||||
pub fn selector(&mut self) -> Selector {
|
||||
let index = self.num_selectors;
|
||||
self.num_selectors += 1;
|
||||
let index = self.cs.num_selectors;
|
||||
self.cs.num_selectors += 1;
|
||||
Selector(index, true)
|
||||
}
|
||||
|
||||
/// Allocate a new complex selector that can appear anywhere
|
||||
/// within expressions.
|
||||
pub fn complex_selector(&mut self) -> Selector {
|
||||
let index = self.num_selectors;
|
||||
self.num_selectors += 1;
|
||||
let index = self.cs.num_selectors;
|
||||
self.cs.num_selectors += 1;
|
||||
Selector(index, false)
|
||||
}
|
||||
|
||||
|
@ -1370,20 +1386,20 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
/// Allocate a new fixed column
|
||||
pub fn fixed_column(&mut self) -> Column<Fixed> {
|
||||
let tmp = Column {
|
||||
index: self.num_fixed_columns,
|
||||
index: self.cs.num_fixed_columns,
|
||||
column_type: Fixed,
|
||||
};
|
||||
self.num_fixed_columns += 1;
|
||||
self.cs.num_fixed_columns += 1;
|
||||
tmp
|
||||
}
|
||||
|
||||
/// Allocate a new advice column
|
||||
pub fn advice_column(&mut self) -> Column<Advice> {
|
||||
let tmp = Column {
|
||||
index: self.num_advice_columns,
|
||||
index: self.cs.num_advice_columns,
|
||||
column_type: Advice,
|
||||
};
|
||||
self.num_advice_columns += 1;
|
||||
self.cs.num_advice_columns += 1;
|
||||
self.num_advice_queries.push(0);
|
||||
tmp
|
||||
}
|
||||
|
@ -1391,10 +1407,10 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
/// Allocate a new instance column
|
||||
pub fn instance_column(&mut self) -> Column<Instance> {
|
||||
let tmp = Column {
|
||||
index: self.num_instance_columns,
|
||||
index: self.cs.num_instance_columns,
|
||||
column_type: Instance,
|
||||
};
|
||||
self.num_instance_columns += 1;
|
||||
self.cs.num_instance_columns += 1;
|
||||
tmp
|
||||
}
|
||||
|
||||
|
@ -1403,13 +1419,14 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
pub fn degree(&self) -> usize {
|
||||
// The permutation argument will serve alongside the gates, so must be
|
||||
// accounted for.
|
||||
let mut degree = self.permutation.required_degree();
|
||||
let mut degree = self.cs.permutation.required_degree();
|
||||
|
||||
// The lookup argument also serves alongside the gates and must be accounted
|
||||
// for.
|
||||
degree = std::cmp::max(
|
||||
degree,
|
||||
self.lookups
|
||||
self.cs
|
||||
.lookups
|
||||
.iter()
|
||||
.map(|l| l.required_degree())
|
||||
.max()
|
||||
|
@ -1420,14 +1437,15 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
// correct degree and that our extended domain is the right size.
|
||||
degree = std::cmp::max(
|
||||
degree,
|
||||
self.gates
|
||||
self.cs
|
||||
.gates
|
||||
.iter()
|
||||
.flat_map(|gate| gate.polynomials().iter().map(|poly| poly.degree()))
|
||||
.max()
|
||||
.unwrap_or(0),
|
||||
);
|
||||
|
||||
std::cmp::max(degree, self.minimum_degree.unwrap_or(1))
|
||||
std::cmp::max(degree, self.cs.minimum_degree.unwrap_or(1))
|
||||
}
|
||||
|
||||
/// Compute the number of blinding factors necessary to perfectly blind
|
||||
|
@ -1476,13 +1494,13 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
/// table.
|
||||
#[derive(Debug)]
|
||||
pub struct VirtualCells<'a, F: Field> {
|
||||
meta: &'a mut ConstraintSystem<F>,
|
||||
meta: &'a mut ConstraintSystemBuilder<F>,
|
||||
queried_selectors: Vec<Selector>,
|
||||
queried_cells: Vec<VirtualCell>,
|
||||
}
|
||||
|
||||
impl<'a, F: Field> VirtualCells<'a, F> {
|
||||
fn new(meta: &'a mut ConstraintSystem<F>) -> Self {
|
||||
fn new(meta: &'a mut ConstraintSystemBuilder<F>) -> Self {
|
||||
VirtualCells {
|
||||
meta,
|
||||
queried_selectors: vec![],
|
||||
|
|
|
@ -31,9 +31,9 @@ pub enum Error {
|
|||
/// Instance provided exceeds number of available rows
|
||||
InstanceTooLarge,
|
||||
/// Circuit synthesis requires global constants, but circuit configuration did not
|
||||
/// call [`ConstraintSystem::enable_constant`] on fixed columns with sufficient space.
|
||||
/// call [`ConstraintSystemBuilder::enable_constant`] on fixed columns with sufficient space.
|
||||
///
|
||||
/// [`ConstraintSystem::enable_constant`]: crate::plonk::ConstraintSystem::enable_constant
|
||||
/// [`ConstraintSystemBuilder::enable_constant`]: crate::plonk::ConstraintSystemBuilder::enable_constant
|
||||
NotEnoughColumnsForConstants,
|
||||
/// The instance sets up a copy constraint involving a column that has not been
|
||||
/// included in the permutation.
|
||||
|
|
|
@ -6,11 +6,9 @@ use ff::{Field, FromUniformBytes};
|
|||
use group::Curve;
|
||||
|
||||
use super::{
|
||||
circuit::{
|
||||
Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Fixed, FloorPlanner, Instance,
|
||||
Selector,
|
||||
},
|
||||
permutation, Assigned, Error, LagrangeCoeff, Polynomial, ProvingKey, VerifyingKey,
|
||||
circuit::{Advice, Any, Assignment, Circuit, Column, Fixed, FloorPlanner, Instance, Selector},
|
||||
permutation, Assigned, ConstraintSystemBuilder, Error, LagrangeCoeff, Polynomial, ProvingKey,
|
||||
VerifyingKey,
|
||||
};
|
||||
use crate::{
|
||||
arithmetic::CurveAffine,
|
||||
|
@ -26,14 +24,14 @@ pub(crate) fn create_domain<C, ConcreteCircuit>(
|
|||
params: &Params<C>,
|
||||
) -> (
|
||||
EvaluationDomain<C::Scalar>,
|
||||
ConstraintSystem<C::Scalar>,
|
||||
ConstraintSystemBuilder<C::Scalar>,
|
||||
ConcreteCircuit::Config,
|
||||
)
|
||||
where
|
||||
C: CurveAffine,
|
||||
ConcreteCircuit: Circuit<C::Scalar>,
|
||||
{
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut cs);
|
||||
|
||||
let degree = cs.degree();
|
||||
|
@ -203,9 +201,9 @@ where
|
|||
|
||||
let mut assembly: Assembly<C::Scalar> = Assembly {
|
||||
k: params.k,
|
||||
fixed: vec![domain.empty_lagrange_assigned(); cs.num_fixed_columns],
|
||||
permutation: permutation::keygen::Assembly::new(params.n as usize, &cs.permutation),
|
||||
selectors: vec![vec![false; params.n as usize]; cs.num_selectors],
|
||||
fixed: vec![domain.empty_lagrange_assigned(); cs.cs.num_fixed_columns],
|
||||
permutation: permutation::keygen::Assembly::new(params.n as usize, &cs.cs.permutation),
|
||||
selectors: vec![vec![false; params.n as usize]; cs.cs.num_selectors],
|
||||
usable_rows: 0..params.n as usize - (cs.blinding_factors() + 1),
|
||||
_marker: std::marker::PhantomData,
|
||||
};
|
||||
|
@ -215,7 +213,7 @@ where
|
|||
&mut assembly,
|
||||
circuit,
|
||||
config,
|
||||
cs.constants.clone(),
|
||||
cs.cs.constants.clone(),
|
||||
)?;
|
||||
|
||||
let mut fixed = batch_invert_assigned(assembly.fixed);
|
||||
|
@ -226,9 +224,11 @@ where
|
|||
.map(|poly| domain.lagrange_from_vec(poly)),
|
||||
);
|
||||
|
||||
// This is post-optimization.
|
||||
|
||||
let permutation_vk = assembly
|
||||
.permutation
|
||||
.build_vk(params, &domain, &cs.permutation);
|
||||
.build_vk(params, &domain, &cs.cs.permutation);
|
||||
|
||||
let fixed_commitments = fixed
|
||||
.iter()
|
||||
|
@ -253,7 +253,7 @@ where
|
|||
C: CurveAffine,
|
||||
ConcreteCircuit: Circuit<C::Scalar>,
|
||||
{
|
||||
let mut cs = ConstraintSystem::default();
|
||||
let mut cs = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut cs);
|
||||
|
||||
let cs = cs;
|
||||
|
@ -264,9 +264,9 @@ where
|
|||
|
||||
let mut assembly: Assembly<C::Scalar> = Assembly {
|
||||
k: params.k,
|
||||
fixed: vec![vk.domain.empty_lagrange_assigned(); cs.num_fixed_columns],
|
||||
permutation: permutation::keygen::Assembly::new(params.n as usize, &cs.permutation),
|
||||
selectors: vec![vec![false; params.n as usize]; cs.num_selectors],
|
||||
fixed: vec![vk.domain.empty_lagrange_assigned(); cs.cs.num_fixed_columns],
|
||||
permutation: permutation::keygen::Assembly::new(params.n as usize, &cs.cs.permutation),
|
||||
selectors: vec![vec![false; params.n as usize]; cs.cs.num_selectors],
|
||||
usable_rows: 0..params.n as usize - (cs.blinding_factors() + 1),
|
||||
_marker: std::marker::PhantomData,
|
||||
};
|
||||
|
@ -276,7 +276,7 @@ where
|
|||
&mut assembly,
|
||||
circuit,
|
||||
config,
|
||||
cs.constants.clone(),
|
||||
cs.cs.constants.clone(),
|
||||
)?;
|
||||
|
||||
let mut fixed = batch_invert_assigned(assembly.fixed);
|
||||
|
@ -299,7 +299,7 @@ where
|
|||
|
||||
let permutation_pk = assembly
|
||||
.permutation
|
||||
.build_pk(params, &vk.domain, &cs.permutation);
|
||||
.build_pk(params, &vk.domain, &cs.cs.permutation);
|
||||
|
||||
// Compute l_0(X)
|
||||
// TODO: this can be done more efficiently
|
||||
|
|
|
@ -264,7 +264,7 @@ impl<C: CurveAffine, Ev: Copy + Send + Sync> Permuted<C, Ev> {
|
|||
mut rng: R,
|
||||
transcript: &mut T,
|
||||
) -> Result<Committed<C, Ev>, Error> {
|
||||
let blinding_factors = pk.vk.cs.blinding_factors();
|
||||
let blinding_factors = pk.vk.num_blinding_factors;
|
||||
// Goal is to compute the products of fractions
|
||||
//
|
||||
// Numerator: (\theta^{m-1} a_0(\omega^i) + \theta^{m-2} a_1(\omega^i) + ... + \theta a_{m-2}(\omega^i) + a_{m-1}(\omega^i) + \beta)
|
||||
|
@ -568,7 +568,7 @@ fn permute_expression_pair<C: CurveAffine, R: RngCore>(
|
|||
input_expression: &Polynomial<C::Scalar, LagrangeCoeff>,
|
||||
table_expression: &Polynomial<C::Scalar, LagrangeCoeff>,
|
||||
) -> Result<ExpressionPair<C::Scalar>, Error> {
|
||||
let blinding_factors = pk.vk.cs.blinding_factors();
|
||||
let blinding_factors = pk.vk.num_blinding_factors;
|
||||
let usable_rows = params.n as usize - (blinding_factors + 1);
|
||||
|
||||
let mut permuted_input_expression: Vec<C::Scalar> = input_expression.to_vec();
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Argument {
|
|||
// 3 circuit for the permutation argument.
|
||||
assert!(pk.vk.cs_degree >= 3);
|
||||
let chunk_len = pk.vk.cs_degree - 2;
|
||||
let blinding_factors = pk.vk.cs.blinding_factors();
|
||||
let blinding_factors = pk.vk.num_blinding_factors;
|
||||
|
||||
// Each column gets its own delta power.
|
||||
let mut deltaomega = C::Scalar::ONE;
|
||||
|
@ -214,7 +214,7 @@ impl<C: CurveAffine, Ev: Copy + Send + Sync> Committed<C, Ev> {
|
|||
impl Iterator<Item = poly::Ast<Ev, C::Scalar, ExtendedLagrangeCoeff>> + 'a,
|
||||
) {
|
||||
let chunk_len = pk.vk.cs_degree - 2;
|
||||
let blinding_factors = pk.vk.cs.blinding_factors();
|
||||
let blinding_factors = pk.vk.num_blinding_factors;
|
||||
let last_rotation = Rotation(-((blinding_factors + 1) as i32));
|
||||
|
||||
let constructed = Constructed {
|
||||
|
@ -346,7 +346,7 @@ impl<C: CurveAffine> Constructed<C> {
|
|||
transcript: &mut T,
|
||||
) -> Result<Evaluated<C>, Error> {
|
||||
let domain = &pk.vk.domain;
|
||||
let blinding_factors = pk.vk.cs.blinding_factors();
|
||||
let blinding_factors = pk.vk.num_blinding_factors;
|
||||
|
||||
{
|
||||
let mut sets = self.sets.iter();
|
||||
|
@ -391,7 +391,7 @@ impl<C: CurveAffine> Evaluated<C> {
|
|||
pk: &'a plonk::ProvingKey<C>,
|
||||
x: ChallengeX<C>,
|
||||
) -> impl Iterator<Item = ProverQuery<'a, C>> + Clone {
|
||||
let blinding_factors = pk.vk.cs.blinding_factors();
|
||||
let blinding_factors = pk.vk.num_blinding_factors;
|
||||
let x_next = pk.vk.domain.rotate_omega(*x, Rotation::next());
|
||||
let x_last = pk
|
||||
.vk
|
||||
|
|
|
@ -193,7 +193,7 @@ impl<C: CurveAffine> Evaluated<C> {
|
|||
vk: &'r plonk::VerifyingKey<C>,
|
||||
x: ChallengeX<C>,
|
||||
) -> impl Iterator<Item = VerifierQuery<'r, 'params, C>> + Clone {
|
||||
let blinding_factors = vk.cs.blinding_factors();
|
||||
let blinding_factors = vk.num_blinding_factors;
|
||||
let x_next = vk.domain.rotate_omega(*x, Rotation::next());
|
||||
let x_last = vk
|
||||
.domain
|
||||
|
|
|
@ -5,17 +5,14 @@ use std::iter;
|
|||
use std::ops::RangeTo;
|
||||
|
||||
use super::{
|
||||
circuit::{
|
||||
Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Fixed, FloorPlanner, Instance,
|
||||
Selector,
|
||||
},
|
||||
circuit::{Advice, Any, Assignment, Circuit, Column, Fixed, FloorPlanner, Instance, Selector},
|
||||
lookup, permutation, vanishing, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX,
|
||||
ChallengeY, Error, ProvingKey,
|
||||
};
|
||||
use crate::{
|
||||
arithmetic::{eval_polynomial, CurveAffine},
|
||||
circuit::Value,
|
||||
plonk::Assigned,
|
||||
plonk::{Assigned, ConstraintSystemBuilder},
|
||||
poly::{
|
||||
self,
|
||||
commitment::{Blind, Params},
|
||||
|
@ -60,7 +57,7 @@ pub fn create_proof<
|
|||
pk.vk.hash_into(transcript)?;
|
||||
|
||||
let domain = &pk.vk.domain;
|
||||
let mut meta = ConstraintSystem::default();
|
||||
let mut meta = ConstraintSystemBuilder::default();
|
||||
let config = ConcreteCircuit::configure(&mut meta);
|
||||
|
||||
// Selector optimizations cannot be applied here; use the ConstraintSystem
|
||||
|
@ -81,7 +78,7 @@ pub fn create_proof<
|
|||
.map(|values| {
|
||||
let mut poly = domain.empty_lagrange();
|
||||
assert_eq!(poly.len(), params.n as usize);
|
||||
if values.len() > (poly.len() - (meta.blinding_factors() + 1)) {
|
||||
if values.len() > (poly.len() - (pk.vk.num_blinding_factors + 1)) {
|
||||
return Err(Error::InstanceTooLarge);
|
||||
}
|
||||
for (poly, value) in poly.iter_mut().zip(values.iter()) {
|
||||
|
@ -266,7 +263,7 @@ pub fn create_proof<
|
|||
}
|
||||
}
|
||||
|
||||
let unusable_rows_start = params.n as usize - (meta.blinding_factors() + 1);
|
||||
let unusable_rows_start = params.n as usize - (pk.vk.num_blinding_factors + 1);
|
||||
|
||||
let mut witness = WitnessCollection {
|
||||
k: params.k,
|
||||
|
@ -746,7 +743,7 @@ fn test_create_proof() {
|
|||
*self
|
||||
}
|
||||
|
||||
fn configure(_meta: &mut ConstraintSystem<F>) -> Self::Config {}
|
||||
fn configure(_meta: &mut ConstraintSystemBuilder<F>) -> Self::Config {}
|
||||
|
||||
fn synthesize(
|
||||
&self,
|
||||
|
|
|
@ -90,7 +90,7 @@ pub fn verify_proof<
|
|||
instance
|
||||
.iter()
|
||||
.map(|instance| {
|
||||
if instance.len() > params.n as usize - (vk.cs.blinding_factors() + 1) {
|
||||
if instance.len() > params.n as usize - (vk.num_blinding_factors + 1) {
|
||||
return Err(Error::InstanceTooLarge);
|
||||
}
|
||||
let mut poly = instance.to_vec();
|
||||
|
@ -205,7 +205,7 @@ pub fn verify_proof<
|
|||
// x^n
|
||||
let xn = x.pow(&[params.n, 0, 0, 0]);
|
||||
|
||||
let blinding_factors = vk.cs.blinding_factors();
|
||||
let blinding_factors = vk.num_blinding_factors;
|
||||
let l_evals = vk
|
||||
.domain
|
||||
.l_i_range(*x, xn, (-((blinding_factors + 1) as i32))..=0);
|
||||
|
|
|
@ -9,7 +9,8 @@ use halo2_proofs::dev::MockProver;
|
|||
use halo2_proofs::pasta::{Eq, EqAffine, Fp};
|
||||
use halo2_proofs::plonk::{
|
||||
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Assigned, BatchVerifier, Circuit,
|
||||
Column, ConstraintSystem, Error, Fixed, SingleVerifier, TableColumn, VerificationStrategy,
|
||||
Column, ConstraintSystemBuilder, Error, Fixed, SingleVerifier, TableColumn,
|
||||
VerificationStrategy,
|
||||
};
|
||||
use halo2_proofs::poly::commitment::{Guard, MSM};
|
||||
use halo2_proofs::poly::{commitment::Params, Rotation};
|
||||
|
@ -272,7 +273,7 @@ fn plonk_api() {
|
|||
}
|
||||
}
|
||||
|
||||
fn configure(meta: &mut ConstraintSystem<F>) -> PlonkConfig {
|
||||
fn configure(meta: &mut ConstraintSystemBuilder<F>) -> PlonkConfig {
|
||||
let e = meta.advice_column();
|
||||
let a = meta.advice_column();
|
||||
let b = meta.advice_column();
|
||||
|
|
Loading…
Reference in New Issue