Skip to main content

CircuitBuilder

Trait CircuitBuilder 

Source
pub trait CircuitBuilder {
    type Wire: Copy;
    type Field: Field;

    // Required methods
    fn assert_zero(&mut self, wire: Self::Wire);
    fn constant(&mut self, val: Self::Field) -> Self::Wire;
    fn add(&mut self, lhs: Self::Wire, rhs: Self::Wire) -> Self::Wire;
    fn mul(&mut self, lhs: Self::Wire, rhs: Self::Wire) -> Self::Wire;
    fn hint<H: Fn([Self::Field; IN]) -> [Self::Field; OUT], const IN: usize, const OUT: usize>(
        &mut self,
        inputs: [Self::Wire; IN],
        f: H,
    ) -> [Self::Wire; OUT];
    fn hint_varsize<H: FnOnce(&[Self::Field]) -> Vec<Self::Field>>(
        &mut self,
        inputs: &[Self::Wire],
        out_len: usize,
        f: H,
    ) -> Vec<Self::Wire>;

    // Provided methods
    fn assert_eq(&mut self, lhs: Self::Wire, rhs: Self::Wire) { ... }
    fn sub(&mut self, lhs: Self::Wire, rhs: Self::Wire) -> Self::Wire { ... }
}
Expand description

Common interface for circuit construction and witness generation.

This trait enables writing circuit logic once that works for both abstract circuit expression (ConstraintBuilder) and concrete witness generation (WitnessGenerator). The same function can build constraints symbolically or evaluate them with concrete values.

Required Associated Types§

Required Methods§

Source

fn assert_zero(&mut self, wire: Self::Wire)

Source

fn constant(&mut self, val: Self::Field) -> Self::Wire

Source

fn add(&mut self, lhs: Self::Wire, rhs: Self::Wire) -> Self::Wire

Source

fn mul(&mut self, lhs: Self::Wire, rhs: Self::Wire) -> Self::Wire

Source

fn hint<H: Fn([Self::Field; IN]) -> [Self::Field; OUT], const IN: usize, const OUT: usize>( &mut self, inputs: [Self::Wire; IN], f: H, ) -> [Self::Wire; OUT]

Source

fn hint_varsize<H: FnOnce(&[Self::Field]) -> Vec<Self::Field>>( &mut self, inputs: &[Self::Wire], out_len: usize, f: H, ) -> Vec<Self::Wire>

Runtime-arity variant of hint: takes a slice of input wires and an out_len, with a closure mapping the input values to out_len output values. Emits no constraints; the outputs are public-derivable (allocated in the derived segment) iff every input is, matching hint. The closure is invoked at most once — value-generating builders run it, the symbolic builder skips it.

Provided Methods§

Source

fn assert_eq(&mut self, lhs: Self::Wire, rhs: Self::Wire)

Source

fn sub(&mut self, lhs: Self::Wire, rhs: Self::Wire) -> Self::Wire

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F: Field, LayoutRef: Deref<Target = WitnessLayout<F>>> CircuitBuilder for InstanceGenerator<F, LayoutRef>

Source§

impl<F: Field, LayoutRef: Deref<Target = WitnessLayout<F>>> CircuitBuilder for WitnessGenerator<F, LayoutRef>

Source§

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