diff --git a/examples/simple-example.rs b/examples/simple-example.rs index 0acc59b9..c69009c3 100644 --- a/examples/simple-example.rs +++ b/examples/simple-example.rs @@ -4,9 +4,11 @@ use std::marker::PhantomData; use halo2::{ arithmetic::FieldExt, - circuit::{layouter::SingleChip, Cell, Chip, Layouter, Permutation}, + circuit::{layouter::SingleChip, Cell, Chip, Layouter}, dev::VerifyFailure, - plonk::{Advice, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed, Instance}, + plonk::{ + Advice, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Permutation, + }, poly::Rotation, }; diff --git a/src/circuit.rs b/src/circuit.rs index b414211b..71780e2e 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -4,7 +4,7 @@ use std::{fmt, marker::PhantomData}; use crate::{ arithmetic::FieldExt, - plonk::{Advice, Any, Column, ConstraintSystem, Error, Fixed}, + plonk::{Advice, Any, Column, Error, Fixed, Permutation}, }; pub mod layouter; @@ -73,24 +73,6 @@ pub struct Cell { column: Column, } -/// A permutation configured by a chip. -#[derive(Clone, Debug)] -pub struct Permutation { - index: usize, - mapping: Vec>, -} - -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(), - } - } -} - /// A region of the circuit in which a [`Chip`] can assign cells. /// /// Inside a region, the chip may freely use relative offsets; the [`Layouter`] will diff --git a/src/circuit/layouter.rs b/src/circuit/layouter.rs index e9c20d33..13b5311b 100644 --- a/src/circuit/layouter.rs +++ b/src/circuit/layouter.rs @@ -5,8 +5,8 @@ use std::collections::{HashMap, HashSet}; use std::fmt; use std::marker::PhantomData; -use super::{Cell, Chip, Layouter, Permutation, Region, RegionIndex, RegionStart}; -use crate::plonk::{Advice, Any, Assignment, Column, Error, Fixed}; +use super::{Cell, Chip, Layouter, Region, RegionIndex, RegionStart}; +use crate::plonk::{Advice, Any, Assignment, Column, Error, Fixed, Permutation}; /// Helper trait for implementing a custom [`Layouter`]. /// @@ -321,18 +321,18 @@ impl<'r, 'a, C: Chip, CS: Assignment + 'a> RegionLayouter right: Cell, ) -> Result<(), Error> { let left_column = permutation - .mapping + .mapping() .iter() .position(|c| c == &left.column) .ok_or(Error::SynthesisError)?; let right_column = permutation - .mapping + .mapping() .iter() .position(|c| c == &right.column) .ok_or(Error::SynthesisError)?; self.layouter.cs.copy( - permutation.index, + permutation.index(), left_column, *self.layouter.regions[*left.region_index] + left.row_offset, right_column, diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index f9e38b27..0ca2a136 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -7,6 +7,7 @@ use std::{ }; use super::{lookup, permutation, Error}; +use crate::arithmetic::FieldExt; use crate::poly::Rotation; /// A column type @@ -126,6 +127,34 @@ impl TryFrom> for Column { } } +/// A permutation. +#[derive(Clone, Debug)] +pub struct Permutation { + index: usize, + mapping: Vec>, +} + +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(), + } + } + + /// Returns index of permutation + pub fn index(&self) -> usize { + self.index + } + + /// Returns mapping of permutation + pub fn mapping(&self) -> &[Column] { + &self.mapping + } +} + /// This trait allows a [`Circuit`] to direct some backend to assign a witness /// for a constraint system. pub trait Assignment {