mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Introduce Variable type
This commit is contained in:
parent
9dfc6ac379
commit
c16141be9a
3 changed files with 28 additions and 24 deletions
|
|
@ -9,15 +9,19 @@ use crate::arithmetic::Field;
|
|||
#[derive(Clone, Debug)]
|
||||
pub enum Wire {
|
||||
/// A wires
|
||||
A(usize),
|
||||
A,
|
||||
/// B wires
|
||||
B(usize),
|
||||
B,
|
||||
/// C wires
|
||||
C(usize),
|
||||
C,
|
||||
/// D wires
|
||||
D(usize),
|
||||
D,
|
||||
}
|
||||
|
||||
/// Represents a pointer to a value in the constraint system.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Variable(pub(crate) Wire, pub(crate) usize);
|
||||
|
||||
/// This trait allows a [`Circuit`] to direct some backend to assign a witness
|
||||
/// for a constraint system.
|
||||
pub trait ConstraintSystem<F: Field> {
|
||||
|
|
@ -30,13 +34,13 @@ pub trait ConstraintSystem<F: Field> {
|
|||
sd: F,
|
||||
sm: F,
|
||||
f: impl Fn() -> Result<(F, F, F, F), Error>,
|
||||
) -> Result<(Wire, Wire, Wire, Wire), Error>;
|
||||
) -> Result<(Variable, Variable, Variable, Variable), Error>;
|
||||
|
||||
/// a * b - c = 0
|
||||
fn multiply(
|
||||
&mut self,
|
||||
f: impl Fn() -> Result<(F, F, F), Error>,
|
||||
) -> Result<(Wire, Wire, Wire, Wire), Error> {
|
||||
) -> Result<(Variable, Variable, Variable, Variable), Error> {
|
||||
self.create_gate(F::zero(), F::zero(), F::one(), F::zero(), F::one(), || {
|
||||
let (a, b, c) = f()?;
|
||||
Ok((a, b, c, F::zero()))
|
||||
|
|
@ -47,7 +51,7 @@ pub trait ConstraintSystem<F: Field> {
|
|||
fn add(
|
||||
&mut self,
|
||||
f: impl Fn() -> Result<(F, F, F), Error>,
|
||||
) -> Result<(Wire, Wire, Wire, Wire), Error> {
|
||||
) -> Result<(Variable, Variable, Variable, Variable), Error> {
|
||||
self.create_gate(F::one(), F::one(), F::one(), F::zero(), F::zero(), || {
|
||||
let (a, b, c) = f()?;
|
||||
Ok((a, b, c, F::zero()))
|
||||
|
|
@ -128,11 +132,11 @@ impl<F> Mul<F> for Polynomial<F> {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct MetaCircuit {
|
||||
// num_fixed_wires: usize,
|
||||
// num_advice_wires: usize,
|
||||
// permutations: Vec<Vec<Wire>>,
|
||||
// gates: Vec<Polynomial>,
|
||||
// queries: HashSet<(Wire, usize)>,
|
||||
// num_queries: usize,
|
||||
// num_advice_wires: usize,
|
||||
// permutations: Vec<Vec<Wire>>,
|
||||
// gates: Vec<Polynomial>,
|
||||
// queries: HashSet<(Wire, usize)>,
|
||||
// num_queries: usize,
|
||||
}
|
||||
|
||||
impl Default for MetaCircuit {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
circuit::{Circuit, ConstraintSystem, MetaCircuit, Wire},
|
||||
circuit::{Circuit, ConstraintSystem, MetaCircuit, Wire, Variable},
|
||||
hash_point, Error, Proof, SRS,
|
||||
};
|
||||
use crate::arithmetic::{
|
||||
|
|
@ -42,13 +42,13 @@ impl<C: CurveAffine> Proof<C> {
|
|||
sd: F,
|
||||
sm: F,
|
||||
f: impl Fn() -> Result<(F, F, F, F), Error>,
|
||||
) -> Result<(Wire, Wire, Wire, Wire), Error> {
|
||||
) -> Result<(Variable, Variable, Variable, Variable), Error> {
|
||||
let (a, b, c, d) = f()?;
|
||||
let tmp = Ok((
|
||||
Wire::A(self.a.len()),
|
||||
Wire::B(self.a.len()),
|
||||
Wire::C(self.a.len()),
|
||||
Wire::D(self.a.len()),
|
||||
Variable(Wire::A, self.a.len()),
|
||||
Variable(Wire::B, self.a.len()),
|
||||
Variable(Wire::C, self.a.len()),
|
||||
Variable(Wire::D, self.a.len()),
|
||||
));
|
||||
self.a.push(a);
|
||||
self.b.push(b);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
circuit::{Circuit, ConstraintSystem, MetaCircuit, Wire},
|
||||
circuit::{Circuit, ConstraintSystem, MetaCircuit, Wire, Variable},
|
||||
domain::EvaluationDomain,
|
||||
Error, GATE_DEGREE, SRS,
|
||||
};
|
||||
|
|
@ -30,12 +30,12 @@ impl<C: CurveAffine> SRS<C> {
|
|||
sd: F,
|
||||
sm: F,
|
||||
_: impl Fn() -> Result<(F, F, F, F), Error>,
|
||||
) -> Result<(Wire, Wire, Wire, Wire), Error> {
|
||||
) -> Result<(Variable, Variable, Variable, Variable), Error> {
|
||||
let tmp = Ok((
|
||||
Wire::A(self.sa.len()),
|
||||
Wire::B(self.sa.len()),
|
||||
Wire::C(self.sa.len()),
|
||||
Wire::D(self.sa.len()),
|
||||
Variable(Wire::A, self.sa.len()),
|
||||
Variable(Wire::B, self.sa.len()),
|
||||
Variable(Wire::C, self.sa.len()),
|
||||
Variable(Wire::D, self.sa.len()),
|
||||
));
|
||||
self.sa.push(sa);
|
||||
self.sb.push(sb);
|
||||
|
|
|
|||
Loading…
Reference in a new issue