diff --git a/examples/performance_model.rs b/examples/performance_model.rs index 1138bc0..1d5d1d7 100644 --- a/examples/performance_model.rs +++ b/examples/performance_model.rs @@ -157,24 +157,11 @@ impl<'a, FF: FieldExt, CS: Assignment> StandardCS for StandardPLONK<'a, )) } fn copy(&mut self, left: Variable, right: Variable) -> Result<(), Error> { - let left_column = match left.0 { - x if x == self.config.a => 0, - x if x == self.config.b => 1, - x if x == self.config.c => 2, - _ => unreachable!(), - }; - let right_column = match right.0 { - x if x == self.config.a => 0, - x if x == self.config.b => 1, - x if x == self.config.c => 2, - _ => unreachable!(), - }; - self.cs.copy( &self.config.perm, - left_column, + left.0.into(), left.1, - right_column, + right.0.into(), right.1, ) } diff --git a/src/circuit/layouter.rs b/src/circuit/layouter.rs index 9561657..8ff687d 100644 --- a/src/circuit/layouter.rs +++ b/src/circuit/layouter.rs @@ -320,22 +320,11 @@ impl<'r, 'a, C: Chip, CS: Assignment + 'a> RegionLayouter left: Cell, right: Cell, ) -> Result<(), Error> { - let left_column = permutation - .mapping() - .iter() - .position(|c| c == &left.column) - .ok_or(Error::SynthesisError)?; - let right_column = permutation - .mapping() - .iter() - .position(|c| c == &right.column) - .ok_or(Error::SynthesisError)?; - self.layouter.cs.copy( permutation, - left_column, + left.column, *self.layouter.regions[*left.region_index] + left.row_offset, - right_column, + right.column, *self.layouter.regions[*right.region_index] + right.row_offset, )?; diff --git a/src/dev.rs b/src/dev.rs index f7fd500..f89a733 100644 --- a/src/dev.rs +++ b/src/dev.rs @@ -5,7 +5,7 @@ use ff::Field; use crate::{ arithmetic::{FieldExt, Group}, plonk::{ - permutation, Advice, Assignment, Circuit, Column, ColumnType, ConstraintSystem, Error, + permutation, Advice, Any, Assignment, Circuit, Column, ColumnType, ConstraintSystem, Error, Expression, Fixed, Permutation, }, poly::Rotation, @@ -212,9 +212,9 @@ impl Assignment for MockProver { fn copy( &mut self, permutation: &Permutation, - left_column: usize, + left_column: Column, left_row: usize, - right_column: usize, + right_column: Column, right_row: usize, ) -> Result<(), crate::plonk::Error> { // Check bounds first @@ -222,7 +222,23 @@ impl Assignment for MockProver { return Err(Error::BoundsFailure); } - self.permutations[permutation.index()].copy(left_column, left_row, right_column, right_row) + let left_column_index = permutation + .mapping() + .iter() + .position(|c| c == &left_column) + .ok_or(Error::SynthesisError)?; + let right_column_index = permutation + .mapping() + .iter() + .position(|c| c == &right_column) + .ok_or(Error::SynthesisError)?; + + self.permutations[permutation.index()].copy( + left_column_index, + left_row, + right_column_index, + right_row, + ) } fn push_namespace(&mut self, _: N) diff --git a/src/plonk.rs b/src/plonk.rs index 8199e38..f321fe2 100644 --- a/src/plonk.rs +++ b/src/plonk.rs @@ -380,31 +380,18 @@ fn test_proving() { )) } fn copy(&mut self, left: Variable, right: Variable) -> Result<(), Error> { - let left_column = match left.0 { - x if x == self.config.a => 0, - x if x == self.config.b => 1, - x if x == self.config.c => 2, - _ => unreachable!(), - }; - let right_column = match right.0 { - x if x == self.config.a => 0, - x if x == self.config.b => 1, - x if x == self.config.c => 2, - _ => unreachable!(), - }; - self.cs.copy( &self.config.perm, - left_column, + left.0.into(), left.1, - right_column, + right.0.into(), right.1, )?; self.cs.copy( &self.config.perm2, - left_column, + left.0.into(), left.1, - right_column, + right.0.into(), right.1, ) } diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 85cef67..4893ddd 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -205,9 +205,9 @@ pub trait Assignment { fn copy( &mut self, permutation: &Permutation, - left_column: usize, + left_column: Column, left_row: usize, - right_column: usize, + right_column: Column, right_row: usize, ) -> Result<(), Error>; diff --git a/src/plonk/keygen.rs b/src/plonk/keygen.rs index 7531ec6..dfe0fe2 100644 --- a/src/plonk/keygen.rs +++ b/src/plonk/keygen.rs @@ -2,7 +2,7 @@ use ff::Field; use group::Curve; use super::{ - circuit::{Advice, Assignment, Circuit, Column, ConstraintSystem, Fixed}, + circuit::{Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Fixed}, permutation, Error, LagrangeCoeff, Permutation, Polynomial, ProvingKey, VerifyingKey, }; use crate::arithmetic::CurveAffine; @@ -117,9 +117,9 @@ impl Assignment for Assembly { fn copy( &mut self, permutation: &Permutation, - left_column: usize, + left_column: Column, left_row: usize, - right_column: usize, + right_column: Column, right_row: usize, ) -> Result<(), Error> { // Check bounds first @@ -127,7 +127,23 @@ impl Assignment for Assembly { return Err(Error::BoundsFailure); } - self.permutations[permutation.index()].copy(left_column, left_row, right_column, right_row) + let left_column_index = permutation + .mapping() + .iter() + .position(|c| c == &left_column) + .ok_or(Error::SynthesisError)?; + let right_column_index = permutation + .mapping() + .iter() + .position(|c| c == &right_column) + .ok_or(Error::SynthesisError)?; + + self.permutations[permutation.index()].copy( + left_column_index, + left_row, + right_column_index, + right_row, + ) } fn push_namespace(&mut self, _: N) diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index 21b7680..1f3d986 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -3,7 +3,7 @@ use group::Curve; use std::iter; use super::{ - circuit::{Advice, Assignment, Circuit, Column, ConstraintSystem, Fixed}, + circuit::{Advice, Any, Assignment, Circuit, Column, ConstraintSystem, Fixed}, lookup, permutation, vanishing, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error, Permutation, ProvingKey, }; @@ -160,9 +160,9 @@ pub fn create_proof, ConcreteCircuit: Circ fn copy( &mut self, _: &Permutation, + _: Column, _: usize, - _: usize, - _: usize, + _: Column, _: usize, ) -> Result<(), Error> { // We only care about advice columns here