mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-05 20:10:32 +00:00
Move Permutation struct from crate::circuit -> plonk::circuit
This commit is contained in:
parent
20bd44f854
commit
340fb2b6df
4 changed files with 39 additions and 26 deletions
|
|
@ -4,9 +4,11 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
use halo2::{
|
use halo2::{
|
||||||
arithmetic::FieldExt,
|
arithmetic::FieldExt,
|
||||||
circuit::{layouter::SingleChip, Cell, Chip, Layouter, Permutation},
|
circuit::{layouter::SingleChip, Cell, Chip, Layouter},
|
||||||
dev::VerifyFailure,
|
dev::VerifyFailure,
|
||||||
plonk::{Advice, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed, Instance},
|
plonk::{
|
||||||
|
Advice, Assignment, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Permutation,
|
||||||
|
},
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::{fmt, marker::PhantomData};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arithmetic::FieldExt,
|
arithmetic::FieldExt,
|
||||||
plonk::{Advice, Any, Column, ConstraintSystem, Error, Fixed},
|
plonk::{Advice, Any, Column, Error, Fixed, Permutation},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod layouter;
|
pub mod layouter;
|
||||||
|
|
@ -73,24 +73,6 @@ pub struct Cell {
|
||||||
column: Column<Any>,
|
column: Column<Any>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A permutation configured by a chip.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Permutation {
|
|
||||||
index: usize,
|
|
||||||
mapping: Vec<Column<Any>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A region of the circuit in which a [`Chip`] can assign cells.
|
/// 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
|
/// Inside a region, the chip may freely use relative offsets; the [`Layouter`] will
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ use std::collections::{HashMap, HashSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use super::{Cell, Chip, Layouter, Permutation, Region, RegionIndex, RegionStart};
|
use super::{Cell, Chip, Layouter, Region, RegionIndex, RegionStart};
|
||||||
use crate::plonk::{Advice, Any, Assignment, Column, Error, Fixed};
|
use crate::plonk::{Advice, Any, Assignment, Column, Error, Fixed, Permutation};
|
||||||
|
|
||||||
/// Helper trait for implementing a custom [`Layouter`].
|
/// Helper trait for implementing a custom [`Layouter`].
|
||||||
///
|
///
|
||||||
|
|
@ -321,18 +321,18 @@ impl<'r, 'a, C: Chip, CS: Assignment<C::Field> + 'a> RegionLayouter<C>
|
||||||
right: Cell,
|
right: Cell,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let left_column = permutation
|
let left_column = permutation
|
||||||
.mapping
|
.mapping()
|
||||||
.iter()
|
.iter()
|
||||||
.position(|c| c == &left.column)
|
.position(|c| c == &left.column)
|
||||||
.ok_or(Error::SynthesisError)?;
|
.ok_or(Error::SynthesisError)?;
|
||||||
let right_column = permutation
|
let right_column = permutation
|
||||||
.mapping
|
.mapping()
|
||||||
.iter()
|
.iter()
|
||||||
.position(|c| c == &right.column)
|
.position(|c| c == &right.column)
|
||||||
.ok_or(Error::SynthesisError)?;
|
.ok_or(Error::SynthesisError)?;
|
||||||
|
|
||||||
self.layouter.cs.copy(
|
self.layouter.cs.copy(
|
||||||
permutation.index,
|
permutation.index(),
|
||||||
left_column,
|
left_column,
|
||||||
*self.layouter.regions[*left.region_index] + left.row_offset,
|
*self.layouter.regions[*left.region_index] + left.row_offset,
|
||||||
right_column,
|
right_column,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{lookup, permutation, Error};
|
use super::{lookup, permutation, Error};
|
||||||
|
use crate::arithmetic::FieldExt;
|
||||||
use crate::poly::Rotation;
|
use crate::poly::Rotation;
|
||||||
|
|
||||||
/// A column type
|
/// A column type
|
||||||
|
|
@ -126,6 +127,34 @@ impl TryFrom<Column<Any>> for Column<Instance> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A permutation.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Permutation {
|
||||||
|
index: usize,
|
||||||
|
mapping: Vec<Column<Any>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns index of permutation
|
||||||
|
pub fn index(&self) -> usize {
|
||||||
|
self.index
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns mapping of permutation
|
||||||
|
pub fn mapping(&self) -> &[Column<Any>] {
|
||||||
|
&self.mapping
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This trait allows a [`Circuit`] to direct some backend to assign a witness
|
/// This trait allows a [`Circuit`] to direct some backend to assign a witness
|
||||||
/// for a constraint system.
|
/// for a constraint system.
|
||||||
pub trait Assignment<F: Field> {
|
pub trait Assignment<F: Field> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue