diff --git a/examples/performance_model.rs b/examples/performance_model.rs index 8cd9c53..1138bc0 100644 --- a/examples/performance_model.rs +++ b/examples/performance_model.rs @@ -17,7 +17,7 @@ use std::marker::PhantomData; #[derive(Copy, Clone, Debug)] pub struct Variable(Column, usize); -#[derive(Copy, Clone)] +#[derive(Clone)] struct PLONKConfig { a: Column, b: Column, @@ -29,7 +29,7 @@ struct PLONKConfig { sm: Column, sp: Column, - perm: usize, + perm: Permutation, } trait StandardCS { @@ -170,8 +170,13 @@ impl<'a, FF: FieldExt, CS: Assignment> StandardCS for StandardPLONK<'a, _ => unreachable!(), }; - self.cs - .copy(self.config.perm, left_column, left.1, right_column, right.1) + self.cs.copy( + &self.config.perm, + left_column, + left.1, + right_column, + right.1, + ) } fn public_input(&mut self, f: F) -> Result where diff --git a/src/circuit/layouter.rs b/src/circuit/layouter.rs index 13b5311..9561657 100644 --- a/src/circuit/layouter.rs +++ b/src/circuit/layouter.rs @@ -332,7 +332,7 @@ impl<'r, 'a, C: Chip, CS: Assignment + 'a> RegionLayouter .ok_or(Error::SynthesisError)?; self.layouter.cs.copy( - permutation.index(), + permutation, left_column, *self.layouter.regions[*left.region_index] + left.row_offset, right_column, diff --git a/src/dev.rs b/src/dev.rs index 7bdbcee..f7fd500 100644 --- a/src/dev.rs +++ b/src/dev.rs @@ -6,7 +6,7 @@ use crate::{ arithmetic::{FieldExt, Group}, plonk::{ permutation, Advice, Assignment, Circuit, Column, ColumnType, ConstraintSystem, Error, - Expression, Fixed, + Expression, Fixed, Permutation, }, poly::Rotation, }; @@ -211,18 +211,18 @@ impl Assignment for MockProver { fn copy( &mut self, - permutation: usize, + permutation: &Permutation, left_column: usize, left_row: usize, right_column: usize, right_row: usize, ) -> Result<(), crate::plonk::Error> { // Check bounds first - if permutation >= self.permutations.len() { + if permutation.index() >= self.permutations.len() { return Err(Error::BoundsFailure); } - self.permutations[permutation].copy(left_column, left_row, right_column, right_row) + self.permutations[permutation.index()].copy(left_column, left_row, right_column, right_row) } fn push_namespace(&mut self, _: N) diff --git a/src/plonk.rs b/src/plonk.rs index 0a7e1a6..8199e38 100644 --- a/src/plonk.rs +++ b/src/plonk.rs @@ -210,7 +210,7 @@ fn test_proving() { // Initialize the polynomial commitment parameters let params: Params = Params::new(K); - #[derive(Copy, Clone)] + #[derive(Clone)] struct PLONKConfig { a: Column, b: Column, @@ -226,8 +226,8 @@ fn test_proving() { sl: Column, sl2: Column, - perm: usize, - perm2: usize, + perm: Permutation, + perm2: Permutation, } trait StandardCS { @@ -393,10 +393,15 @@ fn test_proving() { _ => unreachable!(), }; - self.cs - .copy(self.config.perm, left_column, left.1, right_column, right.1)?; self.cs.copy( - self.config.perm2, + &self.config.perm, + left_column, + left.1, + right_column, + right.1, + )?; + self.cs.copy( + &self.config.perm2, left_column, left.1, right_column, diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 0ca2a13..85cef67 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -137,11 +137,7 @@ pub struct Permutation { impl Permutation { /// Configures a new permutation for the given columns. pub fn new(meta: &mut ConstraintSystem, columns: &[Column]) -> Self { - let index = meta.permutation(columns); - Permutation { - index, - mapping: columns.iter().copied().collect(), - } + meta.permutation(columns) } /// Returns index of permutation @@ -208,7 +204,7 @@ pub trait Assignment { /// Assign two advice columns to have the same value fn copy( &mut self, - permutation: usize, + permutation: &Permutation, left_column: usize, left_row: usize, right_column: usize, @@ -477,8 +473,8 @@ impl ConstraintSystem { } } - /// Add a permutation argument for some advice columns - pub fn permutation(&mut self, columns: &[Column]) -> usize { + /// Add a permutation argument for some columns + pub fn permutation(&mut self, columns: &[Column]) -> Permutation { let index = self.permutations.len(); for column in columns { @@ -487,7 +483,10 @@ impl ConstraintSystem { self.permutations .push(permutation::Argument::new(columns.to_vec())); - index + Permutation { + index, + mapping: columns.to_vec(), + } } /// Add a lookup argument for some input expressions and table expressions. diff --git a/src/plonk/keygen.rs b/src/plonk/keygen.rs index 18cbafb..7531ec6 100644 --- a/src/plonk/keygen.rs +++ b/src/plonk/keygen.rs @@ -3,7 +3,7 @@ use group::Curve; use super::{ circuit::{Advice, Assignment, Circuit, Column, ConstraintSystem, Fixed}, - permutation, Error, LagrangeCoeff, Polynomial, ProvingKey, VerifyingKey, + permutation, Error, LagrangeCoeff, Permutation, Polynomial, ProvingKey, VerifyingKey, }; use crate::arithmetic::CurveAffine; use crate::poly::{ @@ -116,18 +116,18 @@ impl Assignment for Assembly { fn copy( &mut self, - permutation: usize, + permutation: &Permutation, left_column: usize, left_row: usize, right_column: usize, right_row: usize, ) -> Result<(), Error> { // Check bounds first - if permutation >= self.permutations.len() { + if permutation.index() >= self.permutations.len() { return Err(Error::BoundsFailure); } - self.permutations[permutation].copy(left_column, left_row, right_column, right_row) + self.permutations[permutation.index()].copy(left_column, left_row, right_column, right_row) } fn push_namespace(&mut self, _: N) diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index e919fd9..21b7680 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -5,7 +5,7 @@ use std::iter; use super::{ circuit::{Advice, Assignment, Circuit, Column, ConstraintSystem, Fixed}, lookup, permutation, vanishing, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, - ChallengeY, Error, ProvingKey, + ChallengeY, Error, Permutation, ProvingKey, }; use crate::arithmetic::{eval_polynomial, CurveAffine, FieldExt}; use crate::poly::{ @@ -159,7 +159,7 @@ pub fn create_proof, ConcreteCircuit: Circ fn copy( &mut self, - _: usize, + _: &Permutation, _: usize, _: usize, _: usize,