From c16141be9a150934e2a35604459cb6373553b702 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sat, 22 Aug 2020 15:15:39 -0600 Subject: [PATCH] Introduce `Variable` type --- src/plonk/circuit.rs | 28 ++++++++++++++++------------ src/plonk/prover.rs | 12 ++++++------ src/plonk/srs.rs | 12 ++++++------ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 48da226..f016b6b 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -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 { @@ -30,13 +34,13 @@ pub trait ConstraintSystem { 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 { 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 Mul for Polynomial { #[derive(Debug, Clone)] pub struct MetaCircuit { // num_fixed_wires: usize, -// num_advice_wires: usize, -// permutations: Vec>, -// gates: Vec, -// queries: HashSet<(Wire, usize)>, -// num_queries: usize, + // num_advice_wires: usize, + // permutations: Vec>, + // gates: Vec, + // queries: HashSet<(Wire, usize)>, + // num_queries: usize, } impl Default for MetaCircuit { diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index b0b66bf..f6016cf 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -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 Proof { 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); diff --git a/src/plonk/srs.rs b/src/plonk/srs.rs index 7d0487d..c61f8cb 100644 --- a/src/plonk/srs.rs +++ b/src/plonk/srs.rs @@ -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 SRS { 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);