Modify Assignment::copy() to take Permutation instead of usize

This commit is contained in:
therealyingtong 2021-02-19 14:53:26 +08:00
parent 340fb2b6df
commit d82a0c85b1
7 changed files with 39 additions and 30 deletions

View File

@ -17,7 +17,7 @@ use std::marker::PhantomData;
#[derive(Copy, Clone, Debug)]
pub struct Variable(Column<Advice>, usize);
#[derive(Copy, Clone)]
#[derive(Clone)]
struct PLONKConfig {
a: Column<Advice>,
b: Column<Advice>,
@ -29,7 +29,7 @@ struct PLONKConfig {
sm: Column<Fixed>,
sp: Column<Fixed>,
perm: usize,
perm: Permutation,
}
trait StandardCS<FF: FieldExt> {
@ -170,8 +170,13 @@ impl<'a, FF: FieldExt, CS: Assignment<FF>> StandardCS<FF> 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<F>(&mut self, f: F) -> Result<Variable, Error>
where

View File

@ -332,7 +332,7 @@ impl<'r, 'a, C: Chip, CS: Assignment<C::Field> + 'a> RegionLayouter<C>
.ok_or(Error::SynthesisError)?;
self.layouter.cs.copy(
permutation.index(),
permutation,
left_column,
*self.layouter.regions[*left.region_index] + left.row_offset,
right_column,

View File

@ -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<F: Field + Group> Assignment<F> for MockProver<F> {
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<NR, N>(&mut self, _: N)

View File

@ -210,7 +210,7 @@ fn test_proving() {
// Initialize the polynomial commitment parameters
let params: Params<EqAffine> = Params::new(K);
#[derive(Copy, Clone)]
#[derive(Clone)]
struct PLONKConfig {
a: Column<Advice>,
b: Column<Advice>,
@ -226,8 +226,8 @@ fn test_proving() {
sl: Column<Fixed>,
sl2: Column<Fixed>,
perm: usize,
perm2: usize,
perm: Permutation,
perm2: Permutation,
}
trait StandardCS<FF: FieldExt> {
@ -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,

View File

@ -137,11 +137,7 @@ pub struct Permutation {
impl Permutation {
/// Configures a new permutation for the given columns.
pub fn new<F: FieldExt>(meta: &mut ConstraintSystem<F>, columns: &[Column<Any>]) -> 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<F: Field> {
/// 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<F: Field> ConstraintSystem<F> {
}
}
/// Add a permutation argument for some advice columns
pub fn permutation(&mut self, columns: &[Column<Any>]) -> usize {
/// Add a permutation argument for some columns
pub fn permutation(&mut self, columns: &[Column<Any>]) -> Permutation {
let index = self.permutations.len();
for column in columns {
@ -487,7 +483,10 @@ impl<F: Field> ConstraintSystem<F> {
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.

View File

@ -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<F: Field> Assignment<F> for Assembly<F> {
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<NR, N>(&mut self, _: N)

View File

@ -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<C: CurveAffine, T: TranscriptWrite<C>, ConcreteCircuit: Circ
fn copy(
&mut self,
_: usize,
_: &Permutation,
_: usize,
_: usize,
_: usize,