bellman_ce/plonk/cs/mod.rs
1use crate::pairing::ff::{Field};
2use crate::pairing::{Engine};
3
4use crate::{SynthesisError};
5use std::marker::PhantomData;
6
7pub mod gates;
8pub mod variable;
9
10use self::variable::*;
11use self::gates::*;
12
13pub trait Circuit<E: Engine> {
14 fn synthesize<CS: ConstraintSystem<E>>(&self, cs: &mut CS) -> Result<(), SynthesisError>;
15}
16
17pub trait ConstraintSystem<E: Engine> {
18 // const ZERO: Variable;
19 // const ONE: Variable;
20
21 // allocate a variable
22 fn alloc<F>(&mut self, value: F) -> Result<Variable, SynthesisError>
23 where
24 F: FnOnce() -> Result<E::Fr, SynthesisError>;
25
26 // allocate an input variable
27 fn alloc_input<F>(&mut self, value: F) -> Result<Variable, SynthesisError>
28 where
29 F: FnOnce() -> Result<E::Fr, SynthesisError>;
30
31 // // allocate a multiplication gate
32 // fn multiply<F>(&mut self, values: F) -> Result<(Variable, Variable, Variable), SynthesisError>
33 // where
34 // F: FnOnce() -> Result<(E::Fr, E::Fr, E::Fr), SynthesisError>;
35
36 // // allocate an addition gate
37 // fn add<F>(&mut self, values: F) -> Result<(Variable, Variable, Variable), SynthesisError>
38 // where
39 // F: FnOnce() -> Result<(E::Fr, E::Fr, E::Fr), SynthesisError>;
40
41 // enforce variable as boolean
42 fn enforce_boolean(&mut self, variable: Variable) -> Result<(), SynthesisError>;
43
44 // allocate an abstract gate
45 fn new_gate(&mut self, variables: (Variable, Variable, Variable),
46 coeffs:(E::Fr, E::Fr, E::Fr, E::Fr, E::Fr)) -> Result<(), SynthesisError>;
47
48 // allocate a constant
49 fn enforce_constant(&mut self, variable: Variable, constant: E::Fr) -> Result<(), SynthesisError>;
50
51 // allocate a multiplication gate
52 fn enforce_mul_2(&mut self, variables: (Variable, Variable)) -> Result<(), SynthesisError>;
53
54 // allocate a multiplication gate
55 fn enforce_mul_3(&mut self, variables: (Variable, Variable, Variable)) -> Result<(), SynthesisError>;
56
57 // allocate a linear combination gate
58 fn enforce_zero_2(&mut self, variables: (Variable, Variable), coeffs:(E::Fr, E::Fr)) -> Result<(), SynthesisError>;
59
60 // allocate a linear combination gate
61 fn enforce_zero_3(&mut self, variables: (Variable, Variable, Variable), coeffs:(E::Fr, E::Fr, E::Fr)) -> Result<(), SynthesisError>;
62
63
64 // // allocate a linear combination gate
65 // fn enforce_zero_2<F>(&mut self, variables: (Variable, Variable), coeffs:(E::Fr, E::Fr), values: F) -> Result<(), SynthesisError>;
66
67 // // allocate a linear combination gate
68 // fn enforce_zero_3<F>(&mut self, variables: (Variable, Variable, Variable), coeffs:(E::Fr, E::Fr, E::Fr), values: F) -> Result<(), SynthesisError>;
69
70 // // allocate a linear combination gate
71 // fn enforce_zero_2<F>(&mut self, variables: (Variable, Variable), coeffs:(E::Fr, E::Fr), values: F) -> Result<(), SynthesisError>
72 // where
73 // F: FnOnce() -> Result<(E::Fr, E::Fr), SynthesisError>;
74
75 // // allocate a linear combination gate
76 // fn enforce_zero_3<F>(&mut self, variables: (Variable, Variable, Variable), coeffs:(E::Fr, E::Fr, E::Fr), values: F) -> Result<(), SynthesisError>
77 // where
78 // F: FnOnce() -> Result<(E::Fr, E::Fr, E::Fr), SynthesisError>;
79
80 fn get_value(&self, _variable: Variable) -> Result<E::Fr, SynthesisError> {
81 Err(SynthesisError::AssignmentMissing)
82 }
83
84 fn get_dummy_variable(&self) -> Variable;
85
86 // fn get_dummy_variable(&self) -> Variable {
87 // <Self as ConstraintSystem<E>>::ZERO
88 // }
89}
90
91
92
93// /// This is a backend for the `SynthesisDriver` to relay information about
94// /// the concrete circuit. One backend might just collect basic information
95// /// about the circuit for verification, while another actually constructs
96// /// a witness.
97// pub trait Backend<E: Engine> {
98// type LinearConstraintIndex;
99
100// /// Get the value of a variable. Can return None if we don't know.
101// fn get_var(&self, _variable: Variable) -> Option<E::Fr> { None }
102
103// /// Set the value of a variable. Might error if this backend expects to know it.
104// fn set_var<F>(&mut self, _variable: Variable, _value: F) -> Result<(), SynthesisError>
105// where F: FnOnce() -> Result<E::Fr, SynthesisError> { Ok(()) }
106
107// /// Create a new multiplication gate.
108// fn new_multiplication_gate(&mut self) { }
109
110// /// Create a new linear constraint, returning the power of Y for caching purposes.
111// fn new_linear_constraint(&mut self) -> Self::LinearConstraintIndex;
112
113// /// Insert a term into a linear constraint. TODO: bad name of function
114// fn insert_coefficient(&mut self, _var: Variable, _coeff: Coeff<E::Fr>, _y: &Self::LinearConstraintIndex) { }
115
116// /// Compute a `LinearConstraintIndex` from `q`.
117// fn get_for_q(&self, q: usize) -> Self::LinearConstraintIndex;
118
119// /// Mark y^{_index} as the power of y cooresponding to the public input
120// /// coefficient for the next public input, in the k(Y) polynomial.
121// fn new_k_power(&mut self, _index: usize) { }
122// }
123
124// /// This is an abstraction which synthesizes circuits.
125// pub trait SynthesisDriver {
126// fn synthesize<E: Engine, C: Circuit<E>, B: Backend<E>>(backend: B, circuit: &C) -> Result<(), SynthesisError>;
127// }