mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-03 19:53:40 +00:00
Add first pieces of the API.
This commit is contained in:
parent
dd1ad9f114
commit
9dfc6ac379
4 changed files with 103 additions and 8 deletions
13
src/plonk.rs
13
src/plonk.rs
|
|
@ -103,12 +103,23 @@ fn test_proving() {
|
|||
// Initialize the polynomial commitment parameters
|
||||
let params: Params<EqAffine> = Params::new::<DummyHash<Fq>>(K);
|
||||
|
||||
struct MyConfig {}
|
||||
struct MyCircuit<F: Field> {
|
||||
a: Option<F>,
|
||||
}
|
||||
|
||||
impl<F: Field> Circuit<F> for MyCircuit<F> {
|
||||
fn synthesize(&self, cs: &mut impl ConstraintSystem<F>) -> Result<(), Error> {
|
||||
type Config = MyConfig;
|
||||
|
||||
fn configure(meta: &mut MetaCircuit) -> MyConfig {
|
||||
MyConfig {}
|
||||
}
|
||||
|
||||
fn synthesize(
|
||||
&self,
|
||||
cs: &mut impl ConstraintSystem<F>,
|
||||
config: MyConfig,
|
||||
) -> Result<(), Error> {
|
||||
for _ in 0..10 {
|
||||
let (_, _, _, _) = cs.multiply(|| {
|
||||
let a = self.a.ok_or(Error::SynthesisError)?;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
use super::Error;
|
||||
use core::cmp::max;
|
||||
use core::ops::{Add, Mul};
|
||||
|
||||
use super::Error;
|
||||
use crate::arithmetic::Field;
|
||||
|
||||
/// This represents a PLONK wire, which could be a fixed (selector) wire or an
|
||||
/// advice wire.
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Wire {
|
||||
/// A wires
|
||||
A(usize),
|
||||
|
|
@ -59,8 +61,82 @@ pub trait ConstraintSystem<F: Field> {
|
|||
/// backend prover can ask the circuit to synthesize using some given
|
||||
/// [`ConstraintSystem`] implementation.
|
||||
pub trait Circuit<F: Field> {
|
||||
/// This is a configuration object that stores things like wires.
|
||||
type Config;
|
||||
|
||||
/// The circuit is given an opportunity to describe the exact gate
|
||||
/// arrangement, wire arrangement, etc.
|
||||
fn configure(meta: &mut MetaCircuit) -> Self::Config;
|
||||
|
||||
/// Given the provided `cs`, synthesize the circuit. The concrete type of
|
||||
/// the caller will be different depending on the context, and they may or
|
||||
/// may not expect to have a witness present.
|
||||
fn synthesize(&self, cs: &mut impl ConstraintSystem<F>) -> Result<(), Error>;
|
||||
fn synthesize(
|
||||
&self,
|
||||
cs: &mut impl ConstraintSystem<F>,
|
||||
config: Self::Config,
|
||||
) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
/// Low-degree polynomial representing an identity that must hold over the committed wires.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Polynomial<F> {
|
||||
/// This is a wire queried at a certain relative location
|
||||
Wire(Wire, isize),
|
||||
/// This is the sum of two polynomials
|
||||
Sum(Box<Polynomial<F>>, Box<Polynomial<F>>),
|
||||
/// This is the product of two polynomials
|
||||
Product(Box<Polynomial<F>>, Box<Polynomial<F>>),
|
||||
/// This is a scaled polynomial
|
||||
Scaled(Box<Polynomial<F>>, F),
|
||||
}
|
||||
|
||||
impl<F: Field> Polynomial<F> {
|
||||
fn degree(&self) -> usize {
|
||||
match self {
|
||||
Polynomial::Wire(_, _) => 1,
|
||||
Polynomial::Sum(ref a, ref b) => max(a.degree(), b.degree()),
|
||||
Polynomial::Product(ref a, ref b) => a.degree() + b.degree(),
|
||||
Polynomial::Scaled(ref poly, _) => poly.degree(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Add for Polynomial<F> {
|
||||
type Output = Polynomial<F>;
|
||||
fn add(self, rhs: Polynomial<F>) -> Polynomial<F> {
|
||||
Polynomial::Sum(Box::new(self), Box::new(rhs))
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Mul for Polynomial<F> {
|
||||
type Output = Polynomial<F>;
|
||||
fn mul(self, rhs: Polynomial<F>) -> Polynomial<F> {
|
||||
Polynomial::Product(Box::new(self), Box::new(rhs))
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Mul<F> for Polynomial<F> {
|
||||
type Output = Polynomial<F>;
|
||||
fn mul(self, rhs: F) -> Polynomial<F> {
|
||||
Polynomial::Scaled(Box::new(self), rhs)
|
||||
}
|
||||
}
|
||||
|
||||
/// This is a description of the circuit environment, such as the gate, wire and
|
||||
/// permutation arrangements.
|
||||
#[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,
|
||||
}
|
||||
|
||||
impl Default for MetaCircuit {
|
||||
fn default() -> MetaCircuit {
|
||||
MetaCircuit {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
circuit::{Circuit, ConstraintSystem, Wire},
|
||||
circuit::{Circuit, ConstraintSystem, MetaCircuit, Wire},
|
||||
hash_point, Error, Proof, SRS,
|
||||
};
|
||||
use crate::arithmetic::{
|
||||
|
|
@ -78,8 +78,12 @@ impl<C: CurveAffine> Proof<C> {
|
|||
sm: vec![],
|
||||
};
|
||||
|
||||
let mut meta = MetaCircuit::default();
|
||||
|
||||
let config = ConcreteCircuit::configure(&mut meta);
|
||||
|
||||
// Synthesize the circuit to obtain the witness and other information.
|
||||
circuit.synthesize(&mut witness)?;
|
||||
circuit.synthesize(&mut witness, config)?;
|
||||
|
||||
// Create a transcript for obtaining Fiat-Shamir challenges.
|
||||
let mut transcript = HBase::init(C::Base::one());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
circuit::{Circuit, ConstraintSystem, Wire},
|
||||
circuit::{Circuit, ConstraintSystem, MetaCircuit, Wire},
|
||||
domain::EvaluationDomain,
|
||||
Error, GATE_DEGREE, SRS,
|
||||
};
|
||||
|
|
@ -54,8 +54,12 @@ impl<C: CurveAffine> SRS<C> {
|
|||
sm: vec![],
|
||||
};
|
||||
|
||||
let mut meta = MetaCircuit::default();
|
||||
|
||||
let config = ConcreteCircuit::configure(&mut meta);
|
||||
|
||||
// Synthesize the circuit to obtain SRS
|
||||
circuit.synthesize(&mut assembly)?;
|
||||
circuit.synthesize(&mut assembly, config)?;
|
||||
|
||||
assembly.sa.resize(params.n as usize, C::Scalar::zero());
|
||||
assembly.sb.resize(params.n as usize, C::Scalar::zero());
|
||||
|
|
|
|||
Loading…
Reference in a new issue