1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::marker::PhantomData;
use crate::bls::Engine;
use crate::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
#[derive(Debug)]
pub struct BenchCS<E: Engine> {
inputs: usize,
aux: usize,
a: usize,
b: usize,
c: usize,
_e: PhantomData<E>,
}
impl<E: Engine> BenchCS<E> {
pub fn new() -> Self {
BenchCS::default()
}
pub fn num_constraints(&self) -> usize {
self.a
}
pub fn num_inputs(&self) -> usize {
self.inputs
}
}
impl<E: Engine> Default for BenchCS<E> {
fn default() -> Self {
BenchCS {
inputs: 1,
aux: 0,
a: 0,
b: 0,
c: 0,
_e: PhantomData,
}
}
}
unsafe impl<E: Engine> Send for BenchCS<E> {}
impl<E: Engine> ConstraintSystem<E> for BenchCS<E> {
type Root = Self;
fn new() -> Self {
BenchCS::default()
}
fn alloc<F, A, AR>(&mut self, _: A, _f: F) -> Result<Variable, SynthesisError>
where
F: FnOnce() -> Result<E::Fr, SynthesisError>,
A: FnOnce() -> AR,
AR: Into<String>,
{
self.aux += 1;
Ok(Variable::new_unchecked(Index::Aux(self.aux - 1)))
}
fn alloc_input<F, A, AR>(&mut self, _: A, _f: F) -> Result<Variable, SynthesisError>
where
F: FnOnce() -> Result<E::Fr, SynthesisError>,
A: FnOnce() -> AR,
AR: Into<String>,
{
self.inputs += 1;
Ok(Variable::new_unchecked(Index::Input(self.inputs - 1)))
}
fn enforce<A, AR, LA, LB, LC>(&mut self, _: A, _a: LA, _b: LB, _c: LC)
where
A: FnOnce() -> AR,
AR: Into<String>,
LA: FnOnce(LinearCombination<E>) -> LinearCombination<E>,
LB: FnOnce(LinearCombination<E>) -> LinearCombination<E>,
LC: FnOnce(LinearCombination<E>) -> LinearCombination<E>,
{
self.a += 1;
self.b += 1;
self.c += 1;
}
fn push_namespace<NR, N>(&mut self, _: N)
where
NR: Into<String>,
N: FnOnce() -> NR,
{
}
fn pop_namespace(&mut self) {}
fn get_root(&mut self) -> &mut Self::Root {
self
}
}