pub struct Circuit { /* private fields */ }Expand description
An artifact that represents a built circuit.
The difference from ConstraintSystem is that a circuit retains enough information to
perform circuit evaluation to generate internal witness values.
Implementations§
Source§impl Circuit
impl Circuit
Sourcepub fn inout(&self) -> &[Wire]
pub fn inout(&self) -> &[Wire]
Returns the wires forming the circuit’s public interface, in inout segment order.
Inout value i of the value vector is the word wire inout()[i] holds, so this is the
reverse of Self::witness_index over that segment. A caller assembling the positional
public-input vector a verifier takes reads it straight off this slice.
The segment is ordered by wire creation, so a wire promoted with
CircuitBuilder::mark_inout follows the declared inout
wires only if its gate created it later; among promotions the order is the one their gates
ran in, not the order they were promoted in.
Sourcepub const fn scratch_peak_live(&self) -> usize
pub const fn scratch_peak_live(&self) -> usize
Returns the smallest scratch segment this circuit could run with.
This is the largest number of uncommitted temporaries alive at the same time. It is what the segment shrinks to once slots are shared. It is reported whether or not sharing is on, so the unused headroom stays visible.
Sourcepub fn witness_index(&self, wire: Wire) -> ValueIndex
pub fn witness_index(&self, wire: Wire) -> ValueIndex
For the given wire, returns its index in the witness vector.
Sourcepub fn witness_row(&self, wire: Wire) -> usize
pub fn witness_row(&self, wire: Wire) -> usize
For the given wire, returns the row it occupies in a transposed value array.
This is the wire’s flat position in the value vector, counting the scratch tail, which is
how Self::populate_wire_witness_batched numbers the rows it fills.
Sourcepub fn new_witness_filler(&self) -> WitnessFiller<'_>
pub fn new_witness_filler(&self) -> WitnessFiller<'_>
Creates a new witness filler for this circuit.
Sourcepub fn populate_wire_witness(
&self,
w: &mut WitnessFiller<'_>,
) -> Result<(), PopulateError>
pub fn populate_wire_witness( &self, w: &mut WitnessFiller<'_>, ) -> Result<(), PopulateError>
Populates non-input values (wires) in the witness.
Specifically, this will evaluate the circuit gate-by-gate and save the results in the witness vector.
This function expects that the input wires are already filled. The input wires are
CircuitBuilder::add_inout,CircuitBuilder::add_witnessthat were not created by the gates,
The wires created by CircuitBuilder::add_constant (and its convenience methods)
are automatically populated by this function as well. So is a wire promoted with
CircuitBuilder::mark_inout: it is public but gate-derived, so the caller leaves it
unset and reads the computed value back afterwards.
§Errors
Returns PopulateError when any assertion fails.
Each failure names the circuit path the assertion was declared under.
Evaluation runs to completion first, so every violation is reported at once.
Sourcepub fn populate_wire_witness_batched(
&self,
values: &mut StridedArray2DViewMut<'_, Word>,
) -> Result<(), BatchPopulateError>
pub fn populate_wire_witness_batched( &self, values: &mut StridedArray2DViewMut<'_, Word>, ) -> Result<(), BatchPopulateError>
Populates non-input values for a batch of instances at once.
This is the structure-of-arrays counterpart to Self::populate_wire_witness. values is
the transposed value array: rows are value-vector indices (in the same order a single
instance’s ValueVec uses) and columns are instances. Its height must be the full
value-vector length (including scratch) and its width is the instance count.
The caller must fill each instance’s input rows first — the witness wires and any declared
inout wires, but not a wire promoted with CircuitBuilder::mark_inout, which its gate
derives. This function fills the constant rows (broadcasting each constant across every
instance) and then evaluates the circuit gate-by-gate for all instances.
§Errors
If any instance is not satisfiable, returns an error naming the lowest-indexed failing instance and its assertion failures.
Sourcepub const fn constraint_system(&self) -> &ConstraintSystem
pub const fn constraint_system(&self) -> &ConstraintSystem
Returns the constraint system for this circuit.
Sourcepub const fn value_vec_layout(&self) -> &ValueVecLayout
pub const fn value_vec_layout(&self) -> &ValueVecLayout
Returns the layout of the value vector this circuit fills.
Sourcepub const fn n_gates(&self) -> usize
pub const fn n_gates(&self) -> usize
Returns the number of gates in this circuit.
Depending on what type of gates this circuit uses, the number of constraints might be significantly larger.
Sourcepub const fn n_eval_insn(&self) -> usize
pub const fn n_eval_insn(&self) -> usize
Returns the number of evaluation instructions in this circuit.
Sourcepub fn simple_json_dump(&self) -> String
pub fn simple_json_dump(&self) -> String
Returns a string with a JSON dump that is useful to profile the circuit.
Sourcepub fn populate_batch<A, F>(
&self,
alloc: &A,
log_instances: usize,
fill: F,
) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
pub fn populate_batch<A, F>( &self, alloc: &A, log_instances: usize, fill: F, ) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
Builds the batch witness in wire-major order, populating all 2^log_instances instances.
The instances are independent. For each, fill sets the input wires; the batched
interpreter then derives every remaining wire, filling all instances of one wire at a time.
§Arguments
alloc: backs the returned table’s words and the transient buffer built to fill it.log_instances: base-2 logarithm of the instance count.fill: sets the input wires of instancei, foriin0..2^log_instances. It must assign every witness input and every inout wire on each call.
§Errors
Returns an error naming the lowest-indexed instance whose inputs do not satisfy the circuit.
Sourcepub fn populate_batch_parallel<A, F>(
&self,
alloc: &A,
log_instances: usize,
fill: F,
) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
pub fn populate_batch_parallel<A, F>( &self, alloc: &A, log_instances: usize, fill: F, ) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
Builds the batch witness in parallel, one contiguous tile of instances per thread.
- A column stripe of the shared value array is not contiguous.
- A thread reading it touches one short run per wire row.
- Successive rows of the same stripe sit one instance count apart in memory.
- A tile avoids this: each thread gets its own small, fully contiguous buffer.
- A thread fills, evaluates, then gathers its own tile into the batch’s real layout.
§Errors
Returns an error naming a failing instance whose inputs do not satisfy the circuit. The reported instance is not guaranteed to be the lowest failing one across all tiles.
Sourcepub fn populate_batch_parallel_with_stripe_width<A, F>(
&self,
alloc: &A,
log_instances: usize,
stripe_width: usize,
fill: F,
) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
pub fn populate_batch_parallel_with_stripe_width<A, F>( &self, alloc: &A, log_instances: usize, stripe_width: usize, fill: F, ) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
Builds the batch witness in parallel using a caller-provided tile size.
Exposed for benchmarking tile sizes.
Production callers should use Self::populate_batch_parallel.
§Errors
Returns an error naming a failing instance whose inputs do not satisfy the circuit. The reported instance is not guaranteed to be the lowest failing one across all tiles.
§Panics
Panics if stripe_width == 0.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Circuit
impl !UnwindSafe for Circuit
impl Freeze for Circuit
impl Send for Circuit
impl Sync for Circuit
impl Unpin for Circuit
impl UnsafeUnpin for Circuit
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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