mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Introduce Wire enum for use in permutations
This commit is contained in:
parent
a257308ba2
commit
0bdcbb6c67
2 changed files with 77 additions and 22 deletions
|
|
@ -18,6 +18,17 @@ pub struct AdviceWire(pub usize);
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
pub struct AuxWire(pub usize);
|
pub struct AuxWire(pub usize);
|
||||||
|
|
||||||
|
/// An enum over all wire types, to be used in permutations
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
|
pub enum Wire {
|
||||||
|
/// Fixed wire
|
||||||
|
Fixed(FixedWire),
|
||||||
|
/// Advice wire
|
||||||
|
Advice(AdviceWire),
|
||||||
|
/// Auxiliary wire
|
||||||
|
Aux(AuxWire),
|
||||||
|
}
|
||||||
|
|
||||||
/// 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> {
|
||||||
|
|
@ -176,7 +187,7 @@ pub struct ConstraintSystem<F> {
|
||||||
// enforced between advice wire values in A, B and C, and another
|
// enforced between advice wire values in A, B and C, and another
|
||||||
// permutation between wires (B, C, D) which allows the same with D instead
|
// permutation between wires (B, C, D) which allows the same with D instead
|
||||||
// of A.
|
// of A.
|
||||||
pub(crate) permutations: Vec<Vec<(AdviceWire, usize)>>,
|
pub(crate) permutations: Vec<Vec<(Wire, usize)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: Field> Default for ConstraintSystem<F> {
|
impl<F: Field> Default for ConstraintSystem<F> {
|
||||||
|
|
@ -200,7 +211,7 @@ impl<F: Field> Default for ConstraintSystem<F> {
|
||||||
|
|
||||||
impl<F: Field> ConstraintSystem<F> {
|
impl<F: Field> ConstraintSystem<F> {
|
||||||
/// Add a permutation argument for some advice wires
|
/// Add a permutation argument for some advice wires
|
||||||
pub fn permutation(&mut self, wires: &[AdviceWire]) -> usize {
|
pub fn permutation(&mut self, wires: &[Wire]) -> usize {
|
||||||
let index = self.permutations.len();
|
let index = self.permutations.len();
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
let at = Rotation(-1);
|
let at = Rotation(-1);
|
||||||
|
|
@ -209,7 +220,11 @@ impl<F: Field> ConstraintSystem<F> {
|
||||||
}
|
}
|
||||||
let wires = wires
|
let wires = wires
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&wire| (wire, self.query_advice_index(wire, 0)))
|
.map(|&wire| match wire {
|
||||||
|
Wire::Advice(wire) => (Wire::Advice(wire), self.query_advice_index(wire, 0)),
|
||||||
|
Wire::Aux(wire) => (Wire::Aux(wire), self.query_aux_index(wire, 0)),
|
||||||
|
Wire::Fixed(wire) => (Wire::Fixed(wire), self.query_fixed_index(wire, 0)),
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
self.permutations.push(wires);
|
self.permutations.push(wires);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{
|
use super::{
|
||||||
circuit::{AdviceWire, Assignment, Circuit, ConstraintSystem, FixedWire},
|
circuit::{AdviceWire, Assignment, Circuit, ConstraintSystem, FixedWire, Wire},
|
||||||
hash_point, Error, Proof, SRS,
|
hash_point, Error, Proof, SRS,
|
||||||
};
|
};
|
||||||
use crate::arithmetic::{
|
use crate::arithmetic::{
|
||||||
|
|
@ -182,15 +182,34 @@ impl<C: CurveAffine> Proof<C> {
|
||||||
|
|
||||||
// Iterate over each wire of the permutation
|
// Iterate over each wire of the permutation
|
||||||
for (&(wire, _), permuted_wire_values) in wires.iter().zip(permuted_values.iter()) {
|
for (&(wire, _), permuted_wire_values) in wires.iter().zip(permuted_values.iter()) {
|
||||||
parallelize(&mut modified_advice, |modified_advice, start| {
|
match wire {
|
||||||
for ((modified_advice, advice_value), permuted_advice_value) in modified_advice
|
Wire::Advice(wire) => {
|
||||||
.iter_mut()
|
parallelize(&mut modified_advice, |modified_advice, start| {
|
||||||
.zip(witness.advice[wire.0][start..].iter())
|
for ((modified_advice, advice_value), permuted_advice_value) in
|
||||||
.zip(permuted_wire_values[start..].iter())
|
modified_advice
|
||||||
{
|
.iter_mut()
|
||||||
*modified_advice *= &(x_0 * permuted_advice_value + &x_1 + advice_value);
|
.zip(witness.advice[wire.0][start..].iter())
|
||||||
|
.zip(permuted_wire_values[start..].iter())
|
||||||
|
{
|
||||||
|
*modified_advice *=
|
||||||
|
&(x_0 * permuted_advice_value + &x_1 + advice_value);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
Wire::Aux(wire) => {
|
||||||
|
parallelize(&mut modified_advice, |modified_aux, start| {
|
||||||
|
for ((modified_aux, aux_value), permuted_aux_value) in modified_aux
|
||||||
|
.iter_mut()
|
||||||
|
.zip(aux_lagrange_polys[wire.0][start..].iter())
|
||||||
|
.zip(permuted_wire_values[start..].iter())
|
||||||
|
{
|
||||||
|
*modified_aux *= &(x_0 * permuted_aux_value + &x_1 + aux_value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// TODO: implement for fixed wires
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
permutation_modified_advice.push(modified_advice);
|
permutation_modified_advice.push(modified_advice);
|
||||||
|
|
@ -214,17 +233,38 @@ impl<C: CurveAffine> Proof<C> {
|
||||||
let mut deltaomega = C::Scalar::one();
|
let mut deltaomega = C::Scalar::one();
|
||||||
for &(wire, _) in wires.iter() {
|
for &(wire, _) in wires.iter() {
|
||||||
let omega = domain.get_omega();
|
let omega = domain.get_omega();
|
||||||
parallelize(&mut modified_advice, |modified_advice, start| {
|
match wire {
|
||||||
let mut deltaomega = deltaomega * &omega.pow_vartime(&[start as u64, 0, 0, 0]);
|
Wire::Advice(wire) => {
|
||||||
for (modified_advice, advice_value) in modified_advice
|
parallelize(&mut modified_advice, |modified_advice, start| {
|
||||||
.iter_mut()
|
let mut deltaomega =
|
||||||
.zip(witness.advice[wire.0][start..].iter())
|
deltaomega * &omega.pow_vartime(&[start as u64, 0, 0, 0]);
|
||||||
{
|
for (modified_advice, advice_value) in modified_advice
|
||||||
// Multiply by p_j(\omega^i) + \delta^j \omega^i \beta
|
.iter_mut()
|
||||||
*modified_advice *= &(deltaomega * &x_0 + &x_1 + advice_value);
|
.zip(witness.advice[wire.0][start..].iter())
|
||||||
deltaomega *= ω
|
{
|
||||||
|
// Multiply by p_j(\omega^i) + \delta^j \omega^i \beta
|
||||||
|
*modified_advice *= &(deltaomega * &x_0 + &x_1 + advice_value);
|
||||||
|
deltaomega *= ω
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
Wire::Aux(wire) => {
|
||||||
|
parallelize(&mut modified_advice, |modified_advice, start| {
|
||||||
|
let mut deltaomega =
|
||||||
|
deltaomega * &omega.pow_vartime(&[start as u64, 0, 0, 0]);
|
||||||
|
for (modified_advice, advice_value) in modified_advice
|
||||||
|
.iter_mut()
|
||||||
|
.zip(aux_lagrange_polys[wire.0][start..].iter())
|
||||||
|
{
|
||||||
|
// Multiply by p_j(\omega^i) + \delta^j \omega^i \beta
|
||||||
|
*modified_advice *= &(deltaomega * &x_0 + &x_1 + advice_value);
|
||||||
|
deltaomega *= ω
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// TODO: implement for fixed wires
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
deltaomega *= &C::Scalar::DELTA;
|
deltaomega *= &C::Scalar::DELTA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue