Skip to main content

Circuit

Struct Circuit 

Source
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

Source

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.

Source

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.

Source

pub fn witness_index(&self, wire: Wire) -> ValueIndex

For the given wire, returns its index in the witness vector.

Source

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.

Source

pub fn new_witness_filler(&self) -> WitnessFiller<'_>

Creates a new witness filler for this circuit.

Source

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

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.

Source

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.

Source

pub const fn constraint_system(&self) -> &ConstraintSystem

Returns the constraint system for this circuit.

Source

pub const fn value_vec_layout(&self) -> &ValueVecLayout

Returns the layout of the value vector this circuit fills.

Source

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.

Source

pub const fn n_eval_insn(&self) -> usize

Returns the number of evaluation instructions in this circuit.

Source

pub fn simple_json_dump(&self) -> String

Returns a string with a JSON dump that is useful to profile the circuit.

Source

pub fn populate_batch<A, F>( &self, alloc: &A, log_instances: usize, fill: F, ) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
where A: Allocator, F: Fn(usize, &mut BatchWitnessFiller<'_, '_>),

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 instance i, for i in 0..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.

Source

pub fn populate_batch_parallel<A, F>( &self, alloc: &A, log_instances: usize, fill: F, ) -> Result<ValueTable<A::Vec<Word>>, BatchPopulateError>
where A: Allocator, F: Fn(usize, &mut BatchWitnessFiller<'_, '_>) + Sync,

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.

Source

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>
where A: Allocator, F: Fn(usize, &mut BatchWitnessFiller<'_, '_>) + Sync,

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§

Source§

impl From<Circuit> for CircuitM4

Source§

fn from(circuit: Circuit) -> Self

Makes a circuit the whole system, as a main that calls no chips.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more