mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-10 16:01:28 +01:00
feat: TestConstraintCounter
This commit is contained in:
committed by
Pratyush Mishra
parent
b1913a9ca7
commit
951a6226c9
@@ -34,6 +34,7 @@ use ralloc::{collections::BTreeMap, string::String, vec::Vec};
|
||||
use std::{collections::BTreeMap, string::String, vec::Vec};
|
||||
|
||||
pub mod test_constraint_system;
|
||||
pub mod test_constraint_counter;
|
||||
|
||||
pub mod bits;
|
||||
pub use self::bits::*;
|
||||
|
||||
74
r1cs-std/src/test_constraint_counter.rs
Normal file
74
r1cs-std/src/test_constraint_counter.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use crate::String;
|
||||
use algebra::Field;
|
||||
use r1cs_core::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
|
||||
|
||||
/// Constraint counter for testing purposes.
|
||||
pub struct TestConstraintCounter {
|
||||
pub num_inputs: usize,
|
||||
pub num_aux: usize,
|
||||
pub num_constraints: usize,
|
||||
}
|
||||
|
||||
impl TestConstraintCounter {
|
||||
pub fn new() -> TestConstraintCounter {
|
||||
TestConstraintCounter {
|
||||
num_aux: 0,
|
||||
num_inputs: 0,
|
||||
num_constraints: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<ConstraintF: Field> ConstraintSystem<ConstraintF> for TestConstraintCounter {
|
||||
type Root = Self;
|
||||
|
||||
fn alloc<F, A, AR>(&mut self, _: A, _: F) -> Result<Variable, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<ConstraintF, SynthesisError>,
|
||||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
let var = Variable::new_unchecked(Index::Aux(self.num_aux));
|
||||
self.num_aux += 1;
|
||||
Ok(var)
|
||||
}
|
||||
|
||||
fn alloc_input<F, A, AR>(&mut self, _: A, _: F) -> Result<Variable, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<ConstraintF, SynthesisError>,
|
||||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
let var = Variable::new_unchecked(Index::Input(self.num_inputs));
|
||||
self.num_inputs += 1;
|
||||
|
||||
Ok(var)
|
||||
}
|
||||
|
||||
fn enforce<A, AR, LA, LB, LC>(&mut self, _: A, _: LA, _: LB, _: LC)
|
||||
where
|
||||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
LA: FnOnce(LinearCombination<ConstraintF>) -> LinearCombination<ConstraintF>,
|
||||
LB: FnOnce(LinearCombination<ConstraintF>) -> LinearCombination<ConstraintF>,
|
||||
LC: FnOnce(LinearCombination<ConstraintF>) -> LinearCombination<ConstraintF>,
|
||||
{
|
||||
self.num_constraints += 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
|
||||
}
|
||||
|
||||
fn num_constraints(&self) -> usize {
|
||||
self.num_constraints
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user