pub struct ConstraintSystem<F: Field> {
    pub mode: SynthesisMode,
    pub num_instance_variables: usize,
    pub num_witness_variables: usize,
    pub num_constraints: usize,
    pub num_linear_combinations: usize,
    pub optimization_goal: OptimizationGoal,
    pub instance_assignment: Vec<F>,
    pub witness_assignment: Vec<F>,
    pub cache_map: Rc<RefCell<BTreeMap<TypeId, Box<dyn Any>>>>,
    /* private fields */
}
Expand description

An Rank-One ConstraintSystem. Enforces constraints of the form ⟨a_i, z⟩ ⋅ ⟨b_i, z⟩ = ⟨c_i, z⟩, where a_i, b_i, and c_i are linear combinations over variables, and z is the concrete assignment to these variables.

Fields§

§mode: SynthesisMode

The mode in which the constraint system is operating. self can either be in setup mode (i.e., self.mode == SynthesisMode::Setup) or in proving mode (i.e., self.mode == SynthesisMode::Prove). If we are in proving mode, then we have the additional option of whether or not to construct the A, B, and C matrices of the constraint system (see below).

§num_instance_variables: usize

The number of variables that are “public inputs” to the constraint system.

§num_witness_variables: usize

The number of variables that are “private inputs” to the constraint system.

§num_constraints: usize

The number of constraints in the constraint system.

§num_linear_combinations: usize

The number of linear combinations

§optimization_goal: OptimizationGoal

The parameter we aim to minimize in this constraint system (either the number of constraints or their total weight).

§instance_assignment: Vec<F>

Assignments to the public input variables. This is empty if self.mode == SynthesisMode::Setup.

§witness_assignment: Vec<F>

Assignments to the private input variables. This is empty if self.mode == SynthesisMode::Setup.

§cache_map: Rc<RefCell<BTreeMap<TypeId, Box<dyn Any>>>>

Map for gadgets to cache computation results.

Implementations§

Construct an empty ConstraintSystem.

Create a new ConstraintSystemRef<F>.

Set self.mode to mode.

Check whether self.mode == SynthesisMode::Setup.

Check whether this constraint system aims to optimize weight, number of constraints, or neither.

Specify whether this constraint system should aim to optimize weight, number of constraints, or neither.

Check whether or not self will construct matrices.

Return a variable representing the constant “zero” inside the constraint system.

Return a variable representing the constant “one” inside the constraint system.

Obtain a variable representing a new public instance input.

Obtain a variable representing a new private witness input.

Obtain a variable representing a linear combination.

Enforce a R1CS constraint with the name name.

Transform the map of linear combinations. Specifically, allow the creation of additional witness assignments.

This method is used as a subroutine of inline_all_lcs and outline_lcs.

The transformer function is given a references of this constraint system (&self), number of times used, and a mutable reference of the linear combination to be transformed. (&ConstraintSystem, usize, &mut LinearCombination)

The transformer function returns the number of new witness variables needed and a vector of new witness assignments (if not in the setup mode). (usize, Option<Vec>)

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.

Finalize the constraint system (either by outlining or inlining, if an optimization goal is set).

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.

If self is satisfied, outputs Ok(true). If self is unsatisfied, outputs Ok(false). If self.is_in_setup_mode(), outputs Err(()).

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(), outputs Err(()).

Obtain the assignment corresponding to the Variable v.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more