Trait bellpepper_core::ConstraintSystem
source · pub trait ConstraintSystem<Scalar: PrimeField>: Sized + Send {
type Root: ConstraintSystem<Scalar>;
Show 19 methods
// Required methods
fn alloc<F, A, AR>(
&mut self,
annotation: A,
f: F,
) -> Result<Variable, SynthesisError>
where F: FnOnce() -> Result<Scalar, SynthesisError>,
A: FnOnce() -> AR,
AR: Into<String>;
fn alloc_input<F, A, AR>(
&mut self,
annotation: A,
f: F,
) -> Result<Variable, SynthesisError>
where F: FnOnce() -> Result<Scalar, SynthesisError>,
A: FnOnce() -> AR,
AR: Into<String>;
fn enforce<A, AR, LA, LB, LC>(&mut self, annotation: A, a: LA, b: LB, c: LC)
where A: FnOnce() -> AR,
AR: Into<String>,
LA: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
LB: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
LC: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>;
fn push_namespace<NR, N>(&mut self, name_fn: N)
where NR: Into<String>,
N: FnOnce() -> NR;
fn pop_namespace(&mut self);
fn get_root(&mut self) -> &mut Self::Root;
// Provided methods
fn new() -> Self { ... }
fn one() -> Variable { ... }
fn namespace<NR, N>(
&mut self,
name_fn: N,
) -> Namespace<'_, Scalar, Self::Root>
where NR: Into<String>,
N: FnOnce() -> NR { ... }
fn is_extensible() -> bool { ... }
fn extend(&mut self, _other: &Self) { ... }
fn is_witness_generator(&self) -> bool { ... }
fn extend_inputs(&mut self, _new_inputs: &[Scalar]) { ... }
fn extend_aux(&mut self, _new_aux: &[Scalar]) { ... }
fn allocate_empty(
&mut self,
_aux_n: usize,
_inputs_n: usize,
) -> (&mut [Scalar], &mut [Scalar]) { ... }
fn allocate_empty_inputs(&mut self, _n: usize) -> &mut [Scalar] { ... }
fn allocate_empty_aux(&mut self, _n: usize) -> &mut [Scalar] { ... }
fn inputs_slice(&self) -> &[Scalar] { ... }
fn aux_slice(&self) -> &[Scalar] { ... }
}
Expand description
Represents a constraint system which can have new variables allocated and constrains between them formed.
Required Associated Types§
sourcetype Root: ConstraintSystem<Scalar>
type Root: ConstraintSystem<Scalar>
Represents the type of the “root” of this constraint system so that nested namespaces can minimize indirection.
Required Methods§
sourcefn alloc<F, A, AR>(
&mut self,
annotation: A,
f: F,
) -> Result<Variable, SynthesisError>
fn alloc<F, A, AR>( &mut self, annotation: A, f: F, ) -> Result<Variable, SynthesisError>
Allocate a private variable in the constraint system. The provided function is used to
determine the assignment of the variable. The given annotation
function is invoked
in testing contexts in order to derive a unique name for this variable in the current
namespace.
sourcefn alloc_input<F, A, AR>(
&mut self,
annotation: A,
f: F,
) -> Result<Variable, SynthesisError>
fn alloc_input<F, A, AR>( &mut self, annotation: A, f: F, ) -> Result<Variable, SynthesisError>
Allocate a public variable in the constraint system. The provided function is used to determine the assignment of the variable.
sourcefn enforce<A, AR, LA, LB, LC>(&mut self, annotation: A, a: LA, b: LB, c: LC)where
A: FnOnce() -> AR,
AR: Into<String>,
LA: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
LB: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
LC: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
fn enforce<A, AR, LA, LB, LC>(&mut self, annotation: A, a: LA, b: LB, c: LC)where
A: FnOnce() -> AR,
AR: Into<String>,
LA: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
LB: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
LC: FnOnce(LinearCombination<Scalar>) -> LinearCombination<Scalar>,
Enforce that A
* B
= C
. The annotation
function is invoked in testing contexts
in order to derive a unique name for the constraint in the current namespace.
sourcefn push_namespace<NR, N>(&mut self, name_fn: N)
fn push_namespace<NR, N>(&mut self, name_fn: N)
Create a new (sub)namespace and enter into it. Not intended
for downstream use; use namespace
instead.
sourcefn pop_namespace(&mut self)
fn pop_namespace(&mut self)
Exit out of the existing namespace. Not intended for
downstream use; use namespace
instead.
Provided Methods§
fn new() -> Self
sourcefn namespace<NR, N>(&mut self, name_fn: N) -> Namespace<'_, Scalar, Self::Root>
fn namespace<NR, N>(&mut self, name_fn: N) -> Namespace<'_, Scalar, Self::Root>
Begin a namespace for this constraint system.
sourcefn is_extensible() -> bool
fn is_extensible() -> bool
Most implementations of ConstraintSystem are not ‘extensible’: they won’t implement a specialized
version of extend
and should therefore also keep the default implementation of is_extensible
so callers which optionally make use of extend
can know to avoid relying on it when unimplemented.
sourcefn extend(&mut self, _other: &Self)
fn extend(&mut self, _other: &Self)
Extend concatenates thew other
constraint systems to the receiver, modifying the receiver, whose
inputs, allocated variables, and constraints will precede those of the other
constraint system.
The primary use case for this is parallel synthesis of circuits which can be decomposed into
entirely independent sub-circuits. Each can be synthesized in its own thread, then the
original ConstraintSystem
can be extended with each, in the same order they would have
been synthesized sequentially.
sourcefn is_witness_generator(&self) -> bool
fn is_witness_generator(&self) -> bool
Determines if the current ConstraintSystem
instance is a witness generator.
ConstraintSystems that are witness generators need not assemble the actual constraints. Rather, they exist only
to efficiently create a witness.
§Returns
false
- By default, aConstraintSystem
is not a witness generator.
sourcefn extend_inputs(&mut self, _new_inputs: &[Scalar])
fn extend_inputs(&mut self, _new_inputs: &[Scalar])
Extend the inputs of the ConstraintSystem
.
§Panics
Panics if called on a ConstraintSystem
that is not a witness generator.
sourcefn extend_aux(&mut self, _new_aux: &[Scalar])
fn extend_aux(&mut self, _new_aux: &[Scalar])
Extend the auxiliary inputs of the ConstraintSystem
.
§Panics
Panics if called on a ConstraintSystem
that is not a witness generator.
sourcefn allocate_empty(
&mut self,
_aux_n: usize,
_inputs_n: usize,
) -> (&mut [Scalar], &mut [Scalar])
fn allocate_empty( &mut self, _aux_n: usize, _inputs_n: usize, ) -> (&mut [Scalar], &mut [Scalar])
Allocate empty space for the auxiliary inputs and the main inputs of the ConstraintSystem
.
§Panics
Panics if called on a ConstraintSystem
that is not a witness generator.
sourcefn allocate_empty_inputs(&mut self, _n: usize) -> &mut [Scalar]
fn allocate_empty_inputs(&mut self, _n: usize) -> &mut [Scalar]
Allocate empty space for the main inputs of the ConstraintSystem
.
§Panics
Panics if called on a ConstraintSystem
that is not a witness generator.
sourcefn allocate_empty_aux(&mut self, _n: usize) -> &mut [Scalar]
fn allocate_empty_aux(&mut self, _n: usize) -> &mut [Scalar]
Allocate empty space for the auxiliary inputs of the ConstraintSystem
.
§Panics
Panics if called on a ConstraintSystem
that is not a witness generator.
sourcefn inputs_slice(&self) -> &[Scalar]
fn inputs_slice(&self) -> &[Scalar]
Returns the constraint system’s inputs as a slice of Scalar
s.
§Panics
Panics if called on a ConstraintSystem
that is not a witness generator.
Object Safety§
Implementations on Foreign Types§
source§impl<'cs, Scalar: PrimeField, CS: ConstraintSystem<Scalar>> ConstraintSystem<Scalar> for &'cs mut CS
impl<'cs, Scalar: PrimeField, CS: ConstraintSystem<Scalar>> ConstraintSystem<Scalar> for &'cs mut CS
Convenience implementation of ConstraintSystem