pub struct ConstraintSystemExt<F: Field, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> { /* private fields */ }Expand description
ConstraintSystemExt wraps a ConstraintSystemRef with compile-time
flags that control whether constraint matrices (ARITH_ENABLED) and / or
assignment vectors (ASSIGNMENTS_ENABLED) are collected during synthesis.
Implementations§
Source§impl<F: Field, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F: Field, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
Sourcepub fn new() -> Self
pub fn new() -> Self
ConstraintSystemExt::new creates a new constraint system wrapper
with the specified flags.
Sourcepub fn execute_synthesizer(
&self,
circuit: impl ConstraintSynthesizer<F>,
) -> Result<(), SynthesisError>
pub fn execute_synthesizer( &self, circuit: impl ConstraintSynthesizer<F>, ) -> Result<(), SynthesisError>
ConstraintSystemExt::execute_synthesizer executes a circuit inside
the constraint system, where the circuit should implement the
ConstraintSynthesizer trait.
Sourcepub fn execute_fn<R>(
&self,
circuit: impl FnOnce(ConstraintSystemRef<F>) -> Result<R, SynthesisError>,
) -> Result<R, SynthesisError>
pub fn execute_fn<R>( &self, circuit: impl FnOnce(ConstraintSystemRef<F>) -> Result<R, SynthesisError>, ) -> Result<R, SynthesisError>
ConstraintSystemExt::execute_fn executes a circuit inside the
constraint system, where the circuit should be defined as a closure that
takes as input a ConstraintSystemRef and returns a result of type R.
The return value of the closure will be returned by this method.
Source§impl<F: Field> ConstraintSystemExt<F, true, false>
impl<F: Field> ConstraintSystemExt<F, true, false>
Sourcepub fn arith<A: From<ConstraintSystem<F>>>(self) -> Result<A, SynthesisError>
pub fn arith<A: From<ConstraintSystem<F>>>(self) -> Result<A, SynthesisError>
ArithExtractor::arith extracts the constraint matrices from the
circuit and returns them as an arithmetization / constraint system
structure of type A.
Source§impl<F: Field> ConstraintSystemExt<F, false, true>
impl<F: Field> ConstraintSystemExt<F, false, true>
Sourcepub fn assignments(self) -> Result<Assignments<F, Vec<F>>, SynthesisError>
pub fn assignments(self) -> Result<Assignments<F, Vec<F>>, SynthesisError>
AssignmentsExtractor::assignments extracts the assignments from the
circuit and returns them as Assignments.
Methods from Deref<Target = ConstraintSystemRef<F>>§
Sourcepub fn get_all_predicates_num_constraints(
&self,
) -> IndexMap<String, usize, SeedableRandomState>
pub fn get_all_predicates_num_constraints( &self, ) -> IndexMap<String, usize, SeedableRandomState>
Returns the number of constraints in each predicate
Sourcepub fn get_predicates_num_constraints(
&self,
predicate_label: &str,
) -> Option<usize>
pub fn get_predicates_num_constraints( &self, predicate_label: &str, ) -> Option<usize>
Returns the number of constraints in the predicate with the given label
Sourcepub fn get_all_predicate_arities(
&self,
) -> IndexMap<String, usize, SeedableRandomState>
pub fn get_all_predicate_arities( &self, ) -> IndexMap<String, usize, SeedableRandomState>
Returns the arity of each predicate
Sourcepub fn get_predicate_arity(&self, predicate_label: &str) -> Option<usize>
pub fn get_predicate_arity(&self, predicate_label: &str) -> Option<usize>
Returns the predicate type of the predicate with the given label
Sourcepub fn get_all_predicate_types(&self) -> BTreeMap<String, Predicate<F>>
pub fn get_all_predicate_types(&self) -> BTreeMap<String, Predicate<F>>
Returns the predicate types of each predicate
Sourcepub fn get_predicate_type(&self, predicate_label: &str) -> Option<Predicate<F>>
pub fn get_predicate_type(&self, predicate_label: &str) -> Option<Predicate<F>>
Returns the predicate type of the predicate with the given label
Sourcepub fn num_constraints(&self) -> usize
pub fn num_constraints(&self) -> usize
Returns the number of constraints which is the sum of the number of constraints in each predicate. #[inline]
Sourcepub fn num_instance_variables(&self) -> usize
pub fn num_instance_variables(&self) -> usize
Returns the number of instance variables.
Sourcepub fn instance_assignment(&self) -> Result<Vec<F>, SynthesisError>
pub fn instance_assignment(&self) -> Result<Vec<F>, SynthesisError>
Returns the number of instance variables.
Sourcepub fn witness_assignment(&self) -> Result<Vec<F>, SynthesisError>
pub fn witness_assignment(&self) -> Result<Vec<F>, SynthesisError>
Returns the number of instance variables.
Sourcepub fn num_variables(&self) -> usize
pub fn num_variables(&self) -> usize
Returns the number of instance variables.
Sourcepub fn num_predicates(&self) -> usize
pub fn num_predicates(&self) -> usize
Returns the number of predicates.
Sourcepub fn num_witness_variables(&self) -> usize
pub fn num_witness_variables(&self) -> usize
Returns the number of witness variables.
Sourcepub fn enforce_constraint(
&self,
predicate_label: &str,
lc_vec: impl IntoIterator- LinearCombination
>, IntoIter : ExactSizeIterator>,
) -> Result<(), SynthesisError>where
<impl IntoIterator<Item = Box<dyn FnOnce() -> LinearCombination<F>>> as IntoIterator>::IntoIter: ExactSizeIterator,
pub fn enforce_constraint(
&self,
predicate_label: &str,
lc_vec: impl IntoIterator- LinearCombination
>, IntoIter : ExactSizeIterator>,
) -> Result<(), SynthesisError>where
<impl IntoIterator<Item = Box<dyn FnOnce() -> LinearCombination<F>>> as IntoIterator>::IntoIter: ExactSizeIterator,
Enforce a constraint in the constraint system. It takes a predicate name and enforces a vector of linear combinations of the length of the arity of the predicate enforces the constraint.
Sourcepub fn enforce_constraint_arity_2(
&self,
predicate_label: &str,
a: impl FnOnce() -> LinearCombination<F>,
b: impl FnOnce() -> LinearCombination<F>,
) -> Result<(), SynthesisError>
pub fn enforce_constraint_arity_2( &self, predicate_label: &str, a: impl FnOnce() -> LinearCombination<F>, b: impl FnOnce() -> LinearCombination<F>, ) -> Result<(), SynthesisError>
Enforce a constraint with arity 2.
Sourcepub fn enforce_constraint_arity_3(
&self,
predicate_label: &str,
a: impl FnOnce() -> LinearCombination<F>,
b: impl FnOnce() -> LinearCombination<F>,
c: impl FnOnce() -> LinearCombination<F>,
) -> Result<(), SynthesisError>
pub fn enforce_constraint_arity_3( &self, predicate_label: &str, a: impl FnOnce() -> LinearCombination<F>, b: impl FnOnce() -> LinearCombination<F>, c: impl FnOnce() -> LinearCombination<F>, ) -> Result<(), SynthesisError>
Enforce a constraint with arity 3.
Sourcepub fn enforce_constraint_arity_4(
&self,
predicate_label: &str,
a: impl FnOnce() -> LinearCombination<F>,
b: impl FnOnce() -> LinearCombination<F>,
c: impl FnOnce() -> LinearCombination<F>,
d: impl FnOnce() -> LinearCombination<F>,
) -> Result<(), SynthesisError>
pub fn enforce_constraint_arity_4( &self, predicate_label: &str, a: impl FnOnce() -> LinearCombination<F>, b: impl FnOnce() -> LinearCombination<F>, c: impl FnOnce() -> LinearCombination<F>, d: impl FnOnce() -> LinearCombination<F>, ) -> Result<(), SynthesisError>
Enforce a constraint with arity 4.
Sourcepub fn enforce_constraint_arity_5(
&self,
predicate_label: &str,
a: impl FnOnce() -> LinearCombination<F>,
b: impl FnOnce() -> LinearCombination<F>,
c: impl FnOnce() -> LinearCombination<F>,
d: impl FnOnce() -> LinearCombination<F>,
e: impl FnOnce() -> LinearCombination<F>,
) -> Result<(), SynthesisError>
pub fn enforce_constraint_arity_5( &self, predicate_label: &str, a: impl FnOnce() -> LinearCombination<F>, b: impl FnOnce() -> LinearCombination<F>, c: impl FnOnce() -> LinearCombination<F>, d: impl FnOnce() -> LinearCombination<F>, e: impl FnOnce() -> LinearCombination<F>, ) -> Result<(), SynthesisError>
Enforce a constraint with arity 5.
Sourcepub fn enforce_r1cs_constraint(
&self,
a: impl FnOnce() -> LinearCombination<F>,
b: impl FnOnce() -> LinearCombination<F>,
c: impl FnOnce() -> LinearCombination<F>,
) -> Result<(), SynthesisError>
pub fn enforce_r1cs_constraint( &self, a: impl FnOnce() -> LinearCombination<F>, b: impl FnOnce() -> LinearCombination<F>, c: impl FnOnce() -> LinearCombination<F>, ) -> Result<(), SynthesisError>
Enforce an R1CS constraint in the constraint system.
On input a, b, and c, this method enforces that a * b = c.
If the R1CS predicate has not been already added, this method will add it.
This method is a special case
of enforce_constraint and is used to provide a low-effort way to port prior
code that assumed that R1CS is the only kind of predicate.
Sourcepub fn enforce_sr1cs_constraint(
&self,
a: impl FnOnce() -> LinearCombination<F>,
b: impl FnOnce() -> LinearCombination<F>,
) -> Result<(), SynthesisError>
pub fn enforce_sr1cs_constraint( &self, a: impl FnOnce() -> LinearCombination<F>, b: impl FnOnce() -> LinearCombination<F>, ) -> Result<(), SynthesisError>
Enforce a SquareR1CS constraint in the constraint system.
On input a and b, this method enforces that a^2 = b.
If the SquareR1CS predicate has not been added to the constraint system,
this method will add it.
This method is a special case of enforce_constraint.
Sourcepub fn new_lc(
&self,
lc: impl FnOnce() -> LinearCombination<F>,
) -> Result<Variable, SynthesisError>
pub fn new_lc( &self, lc: impl FnOnce() -> LinearCombination<F>, ) -> Result<Variable, SynthesisError>
Obtain a new variable representing the linear combination lc.
Sourcepub fn set_mode(&self, mode: SynthesisMode)
pub fn set_mode(&self, mode: SynthesisMode)
Set self.mode to mode.
Sets the mode if there exists an underlying ConstraintSystem.
Sourcepub fn is_in_setup_mode(&self) -> bool
pub fn is_in_setup_mode(&self) -> bool
Check whether self.mode == SynthesisMode::Setup.
Returns true if
- There is an underlying
ConstraintSystemand, - It is in setup mode.
Sourcepub fn optimization_goal(&self) -> OptimizationGoal
pub fn optimization_goal(&self) -> OptimizationGoal
Check whether this constraint system aims to optimize weight, number of constraints, or neither.
Sourcepub fn set_optimization_goal(&self, goal: OptimizationGoal)
pub fn set_optimization_goal(&self, goal: OptimizationGoal)
Specify whether this constraint system should aim to optimize weight, number of constraints, or neither.
Sourcepub fn should_outline_instances(&self) -> bool
pub fn should_outline_instances(&self) -> bool
Should we outline instances according to the optimization specified in
Section 3, Page 11 of Polymath
By default, this flag is false.
Sourcepub fn set_instance_outliner(&self, outliner: InstanceOutliner<F>)
pub fn set_instance_outliner(&self, outliner: InstanceOutliner<F>)
Specify the strategy for how the instance should be outlined. This should be compatible with the predicates in the constraint system.
Sourcepub fn should_construct_matrices(&self) -> bool
pub fn should_construct_matrices(&self) -> bool
Check whether or not self will construct matrices.
Sourcepub fn new_input_variable<Func>(
&self,
f: Func,
) -> Result<Variable, SynthesisError>
pub fn new_input_variable<Func>( &self, f: Func, ) -> Result<Variable, SynthesisError>
Obtain a variable representing a new public instance input.
Sourcepub fn new_witness_variable<Func>(
&self,
f: Func,
) -> Result<Variable, SynthesisError>
pub fn new_witness_variable<Func>( &self, f: Func, ) -> Result<Variable, SynthesisError>
Obtain a new variable representing a new private witness variable.
Sourcepub fn register_predicate(
&self,
label: &str,
predicate: PredicateConstraintSystem<F>,
) -> Result<(), SynthesisError>
pub fn register_predicate( &self, label: &str, predicate: PredicateConstraintSystem<F>, ) -> Result<(), SynthesisError>
Register a predicate in the constraint system with a given label.
Sourcepub fn remove_predicate(&self, label: &str)
pub fn remove_predicate(&self, label: &str)
Remove a predicate with the given label from the constraint system.
Sourcepub fn has_predicate(&self, predicate_label: &str) -> bool
pub fn has_predicate(&self, predicate_label: &str) -> bool
Checks if there is a predicate with the given label in the constraint
Sourcepub fn assigned_value(&self, v: Variable) -> Option<F>
pub fn assigned_value(&self, v: Variable) -> Option<F>
Obtain the assignment corresponding to the Variable v.
Sourcepub fn is_satisfied(&self) -> Result<bool, SynthesisError>
pub fn is_satisfied(&self) -> Result<bool, SynthesisError>
If self is satisfied, outputs Ok(true).
If self is unsatisfied, outputs Ok(false).
If self.is_in_setup_mode() or if self == None, outputs Err(()).
Sourcepub fn which_is_unsatisfied(&self) -> Result<Option<String>, SynthesisError>
pub fn which_is_unsatisfied(&self) -> Result<Option<String>, SynthesisError>
If self is satisfied, outputs Ok(None).
If self is unsatisfied, outputs Some(s,i), where s is the label of
the unsatisfied prediacate and i is the index of
the first unsatisfied constraint in that predicate.
If self.is_in_setup_mode() or self == None, outputs Err(()).
Sourcepub fn finalize(&self)
pub fn finalize(&self)
Finalize the constraint system (either by outlining or inlining, if an optimization goal is set).
Sourcepub fn inline_all_lcs(&self)
pub fn inline_all_lcs(&self)
Naively inlines symbolic linear combinations into the linear combinations that use them.
Useful for standard pairing-based SNARKs where addition gates are cheap. For example, in the SNARKs such as [Groth16] and [Groth-Maller17], addition gates do not contribute to the size of the multi-scalar multiplication, which is the dominating cost.
Sourcepub fn to_matrices(
&self,
) -> Result<BTreeMap<String, Vec<Vec<Vec<(F, usize)>>>>, SynthesisError>
pub fn to_matrices( &self, ) -> Result<BTreeMap<String, Vec<Vec<Vec<(F, usize)>>>>, SynthesisError>
Get the matrices corresponding to the predicates.and the corresponding set of matrices
Sourcepub fn get_lc(&self, var: Variable) -> Option<LinearCombination<F>>
pub fn get_lc(&self, var: Variable) -> Option<LinearCombination<F>>
Get the linear combination corresponding to the given lc_index.
TODO: This function should ideally return a reference to the linear
combination and not clone it.
Sourcepub fn make_row(
&self,
lc: LinearCombination<F>,
) -> Result<Vec<(F, usize)>, SynthesisError>
pub fn make_row( &self, lc: LinearCombination<F>, ) -> Result<Vec<(F, usize)>, SynthesisError>
Given a linear combination, create a row in the matrix
Sourcepub fn borrow(&self) -> Option<Ref<'_, ConstraintSystem<F>>>
pub fn borrow(&self) -> Option<Ref<'_, ConstraintSystem<F>>>
Obtain an immutable reference to the underlying ConstraintSystem.
§Panics
This method panics if self is already mutably borrowed.
Sourcepub fn borrow_mut(&self) -> Option<RefMut<'_, ConstraintSystem<F>>>
pub fn borrow_mut(&self) -> Option<RefMut<'_, ConstraintSystem<F>>>
Obtain a mutable reference to the underlying ConstraintSystem.
§Panics
This method panics if self is already mutably borrowed.
Sourcepub fn constraint_names(&self) -> Option<Vec<String>>
pub fn constraint_names(&self) -> Option<Vec<String>>
Get trace information about all constraints in the system
Trait Implementations§
Auto Trait Implementations§
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> !RefUnwindSafe for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> !Send for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> !Sync for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> !UnwindSafe for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> Freeze for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> Unpin for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
impl<F, const ARITH_ENABLED: bool, const ASSIGNMENTS_ENABLED: bool> UnsafeUnpin for ConstraintSystemExt<F, ARITH_ENABLED, ASSIGNMENTS_ENABLED>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more