CircuitBuilder

Struct CircuitBuilder 

Source
pub struct CircuitBuilder<F: Field> {
Show 13 fields input_layer_nodes: Vec<Rc<InputLayerNode>>, input_shred_nodes: Vec<Rc<InputShred>>, fiat_shamir_challenge_nodes: Vec<Rc<FiatShamirChallengeNode>>, output_nodes: Vec<Rc<OutputNode>>, sector_nodes: Vec<Rc<Sector<F>>>, gate_nodes: Vec<Rc<GateNode>>, identity_gate_nodes: Vec<Rc<IdentityGateNode>>, split_nodes: Vec<Rc<SplitNode>>, matmult_nodes: Vec<Rc<MatMultNode>>, lookup_constraint_nodes: Vec<Rc<LookupConstraint>>, lookup_table_nodes: Vec<Rc<LookupTable>>, node_to_ptr: HashMap<NodeId, NodeRef<F>>, circuit_map: CircuitMap,
}
Expand description

A struct that owns and manages super::nodes::CircuitNodes during circuit creation.

Fields§

§input_layer_nodes: Vec<Rc<InputLayerNode>>§input_shred_nodes: Vec<Rc<InputShred>>§fiat_shamir_challenge_nodes: Vec<Rc<FiatShamirChallengeNode>>§output_nodes: Vec<Rc<OutputNode>>§sector_nodes: Vec<Rc<Sector<F>>>§gate_nodes: Vec<Rc<GateNode>>§identity_gate_nodes: Vec<Rc<IdentityGateNode>>§split_nodes: Vec<Rc<SplitNode>>§matmult_nodes: Vec<Rc<MatMultNode>>§lookup_constraint_nodes: Vec<Rc<LookupConstraint>>§lookup_table_nodes: Vec<Rc<LookupTable>>§node_to_ptr: HashMap<NodeId, NodeRef<F>>§circuit_map: CircuitMap

Implementations§

Source§

impl<F: Field> CircuitBuilder<F>

Source

pub fn new() -> Self

Constructs an empty CircuitBuilder.

Source

fn into_owned_helper<T: CircuitNode + Debug>(xs: Vec<Rc<T>>) -> Vec<T>

Source

pub fn build_with_max_layer_size( self, maybe_maximum_log_layer_size: Option<usize>, ) -> Result<Circuit<F>>

Generates a circuit description of all the nodes added so far.

Returns a Circuit struct containing the circuit description and all necessary metadata for attaching inputs.

Source

pub fn build_with_layer_combination(self) -> Result<Circuit<F>>

A build function that combines layers greedily such that the circuit is optimized for having the smallest number of layers possible.

Source

pub fn build_without_layer_combination(self) -> Result<Circuit<F>>

A build function that does not combine any layers.

Source

pub fn build(self) -> Result<Circuit<F>>

A default build function which does not combine layers. Equivalent to build_without_layer_combination.

Source§

impl<F: Field> CircuitBuilder<F>

Source

pub fn add_input_layer( &mut self, layer_label: &str, layer_visibility: LayerVisibility, ) -> InputLayerNodeRef<F>

Adds an InputLayerNode labeled layer_label to the builder’s node collection, intented to become a layer_kind input later during circuit instantiation.

Returns a weak pointer to the newly created layer node.

Note that Input Layers and Input Shred have disjoint label scopes. A label has to be unique only in its respective scope, regardless of the inclusive relation between shreds and input layers.

§Panics

If layer_label has already been used for an existing Input Layer.

Source

pub fn add_input_shred( &mut self, label: &str, num_vars: usize, source: &InputLayerNodeRef<F>, ) -> NodeRef<F>

Returns a reference to the newly created node.

Note that no method in Self requires to differentiate between a reference to an input shred as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.

§Panics

If label has already been used for an existing Input Shred.

Source

pub fn set_output(&mut self, source: &NodeRef<F>)

Adds an zero OutputNode (using OutputNode::new_zero()) to the builder’s node collection.

TODO(Makis): Add a check for ensuring each node can be set as output at most once.

Source

pub fn add_fiat_shamir_challenge_node( &mut self, num_challenges: usize, ) -> FSNodeRef<F>

Adds a FiatShamirChallengeNode to the builder’s node colllection. Returns a typed reference to the newly created node.

Source

pub fn add_sector(&mut self, expr: AbstractExpression<F>) -> NodeRef<F>

Adds a Sector to the builder’s node collection. Returns a typed reference to the newly created node.

Source

pub fn add_identity_gate_node( &mut self, pre_routed_data: &NodeRef<F>, non_zero_gates: Vec<(u32, u32)>, num_vars: usize, num_dataparallel_vars: Option<usize>, ) -> NodeRef<F>

Adds an IdentityGateNode to the builder’s node collection. Returns a reference to the newly created node.

Note that no method in Self requires to differentiate between a reference to an identity gate node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.

Source

pub fn add_gate_node( &mut self, lhs: &NodeRef<F>, rhs: &NodeRef<F>, nonzero_gates: Vec<(u32, u32, u32)>, gate_operation: BinaryOperation, num_dataparallel_bits: Option<usize>, ) -> NodeRef<F>

Adds an GateNode to the builder’s node collection. Returns a reference to the newly created node.

Note that no method in Self requires to differentiate between a reference to a gate node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.

Source

pub fn add_matmult_node( &mut self, matrix_a_node: &NodeRef<F>, rows_cols_num_vars_a: (usize, usize), matrix_b_node: &NodeRef<F>, rows_cols_num_vars_b: (usize, usize), ) -> NodeRef<F>

Adds an MatMultNode to the builder’s node collection. Returns a reference to the newly created node.

Note that no method in Self requires to differentiate between a reference to a matmult node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.

Source

pub fn add_lookup_table( &mut self, table: &NodeRef<F>, fiat_shamir_challenge_node: &FSNodeRef<F>, ) -> LookupTableNodeRef

Adds an LookupTable to the builder’s node collection. Returns a typed reference to the newly created node.

Source

pub fn add_lookup_constraint( &mut self, lookup_table: &LookupTableNodeRef, constrained: &NodeRef<F>, multiplicities: &NodeRef<F>, ) -> LookupConstraintNodeRef

Adds an LookupConstraint to the builder’s node collection. Returns a typed reference to the newly created node.

Source

pub fn add_split_node( &mut self, input_node: &NodeRef<F>, num_vars: usize, ) -> Vec<NodeRef<F>>

Adds an SplitNode to the builder’s node collection. Returns a vector of reference to the 2^num_vars newly created nodes.

Note that no method in Self requires to differentiate between a reference to a split node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.

Source

fn get_ptr_from_node_id(&self, id: NodeId) -> Rc<dyn CircuitNode>

Trait Implementations§

Source§

impl<F: Field> Default for CircuitBuilder<F>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<F> Freeze for CircuitBuilder<F>

§

impl<F> !RefUnwindSafe for CircuitBuilder<F>

§

impl<F> !Send for CircuitBuilder<F>

§

impl<F> !Sync for CircuitBuilder<F>

§

impl<F> Unpin for CircuitBuilder<F>
where F: Unpin,

§

impl<F> !UnwindSafe for CircuitBuilder<F>

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
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. 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> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

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
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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
§

impl<T> SyncDeps for T