pub enum ConstraintSystemRef<F: Field> {
None,
CS(Rc<RefCell<ConstraintSystem<F>>>),
}
Expand description
A shared reference to a constraint system that can be stored in high level variables.
Variants§
None
Represents the case where we don’t need to allocate variables or enforce constraints. Encountered when operating over constant values.
CS(Rc<RefCell<ConstraintSystem<F>>>)
Represents the case where we do allocate variables or enforce constraints.
Implementations§
Source§impl<F: Field> ConstraintSystemRef<F>
impl<F: Field> ConstraintSystemRef<F>
Sourcepub fn new(inner: ConstraintSystem<F>) -> Self
pub fn new(inner: ConstraintSystem<F>) -> Self
Construct a ConstraintSystemRef
from a ConstraintSystem
.
Sourcepub fn into_inner(self) -> Option<ConstraintSystem<F>>
pub fn into_inner(self) -> Option<ConstraintSystem<F>>
Consumes self to return the inner ConstraintSystem<F>
. Returns
None
if Self::CS
is None
or if any other references to
Self::CS
exist.
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 set_mode(&self, mode: SynthesisMode)
pub fn set_mode(&self, mode: SynthesisMode)
Set self.mode
to mode
.
Sourcepub fn is_in_setup_mode(&self) -> bool
pub fn is_in_setup_mode(&self) -> bool
Check whether self.mode == SynthesisMode::Setup
.
Sourcepub fn num_constraints(&self) -> usize
pub fn num_constraints(&self) -> usize
Returns the number of constraints.
Sourcepub fn num_instance_variables(&self) -> usize
pub fn num_instance_variables(&self) -> usize
Returns the number of instance variables.
Sourcepub fn num_witness_variables(&self) -> usize
pub fn num_witness_variables(&self) -> usize
Returns the number of witness variables.
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_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>
pub fn new_input_variable<Func>(&self, f: Func) -> Result<Variable>
Obtain a variable representing a new public instance input.
Sourcepub fn new_witness_variable<Func>(&self, f: Func) -> Result<Variable>
pub fn new_witness_variable<Func>(&self, f: Func) -> Result<Variable>
Obtain a variable representing a new private witness input.
Sourcepub fn new_lc(&self, lc: LinearCombination<F>) -> Result<Variable>
pub fn new_lc(&self, lc: LinearCombination<F>) -> Result<Variable>
Obtain a variable representing a linear combination.
Sourcepub fn enforce_constraint(
&self,
a: LinearCombination<F>,
b: LinearCombination<F>,
c: LinearCombination<F>,
) -> Result<()>
pub fn enforce_constraint( &self, a: LinearCombination<F>, b: LinearCombination<F>, c: LinearCombination<F>, ) -> Result<()>
Enforce a R1CS constraint with the name name
.
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 finalize(&self)
pub fn finalize(&self)
Finalize the constraint system (either by outlining or inlining, if an optimization goal is set).
Sourcepub fn to_matrices(&self) -> Option<ConstraintMatrices<F>>
pub fn to_matrices(&self) -> Option<ConstraintMatrices<F>>
This step must be called after constraint generation has completed, and after all symbolic LCs have been inlined into the places that they are used.
Sourcepub fn is_satisfied(&self) -> Result<bool>
pub fn is_satisfied(&self) -> Result<bool>
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>>
pub fn which_is_unsatisfied(&self) -> Result<Option<String>>
If self
is satisfied, outputs Ok(None)
.
If self
is unsatisfied, outputs Some(i)
, where i
is the index of
the first unsatisfied constraint.
If self.is_in_setup_mode()
or self == None
, outputs Err(())
.
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 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§
Source§impl<F: Clone + Field> Clone for ConstraintSystemRef<F>
impl<F: Clone + Field> Clone for ConstraintSystemRef<F>
Source§fn clone(&self) -> ConstraintSystemRef<F>
fn clone(&self) -> ConstraintSystemRef<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F: Field> From<ConstraintSystemRef<F>> for Namespace<F>
impl<F: Field> From<ConstraintSystemRef<F>> for Namespace<F>
Source§fn from(other: ConstraintSystemRef<F>) -> Self
fn from(other: ConstraintSystemRef<F>) -> Self
Source§impl<F: Field> PartialEq for ConstraintSystemRef<F>
impl<F: Field> PartialEq for ConstraintSystemRef<F>
impl<F: Field> Eq for ConstraintSystemRef<F>
Auto Trait Implementations§
impl<F> Freeze for ConstraintSystemRef<F>
impl<F> !RefUnwindSafe for ConstraintSystemRef<F>
impl<F> !Send for ConstraintSystemRef<F>
impl<F> !Sync for ConstraintSystemRef<F>
impl<F> Unpin for ConstraintSystemRef<F>
impl<F> !UnwindSafe for ConstraintSystemRef<F>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)