pub struct CircuitBuilder<F>where
F: Field,{ /* private fields */ }Expand description
Builder for constructing arithmetic circuits
Implementations§
Source§impl<F> CircuitBuilder<F>where
F: Field,
impl<F> CircuitBuilder<F>where
F: Field,
Sourcepub fn new(witness_size: usize, public_input_size: usize) -> CircuitBuilder<F>
pub fn new(witness_size: usize, public_input_size: usize) -> CircuitBuilder<F>
Create a new circuit builder
§Arguments
witness_size- Number of witness wires (private inputs)public_input_size- Number of public input wires
§Example
ⓘ
use lib_q_zkp::circuit::CircuitBuilder;
use lib_q_stark_field::extension::Complex;
use lib_q_stark_mersenne31::Mersenne31;
type Val = Complex<Mersenne31>;
let mut builder = CircuitBuilder::<Val>::new(2, 1);
let a = builder.wire(0); // witness wire 0
let b = builder.wire(1); // witness wire 1
let sum = builder.add(a, b);
builder.assert_zero(sum);
let circuit = builder.build();Sourcepub fn alloc_wire(&mut self) -> Wire
pub fn alloc_wire(&mut self) -> Wire
Allocate a new intermediate wire
Sourcepub fn assert_zero(&mut self, wire: Wire)
pub fn assert_zero(&mut self, wire: Wire)
Assert that a wire equals zero
Sourcepub fn assert_constant(&mut self, wire: Wire, constant: F)
pub fn assert_constant(&mut self, wire: Wire, constant: F)
Assert that a wire equals a constant
Sourcepub fn add(&mut self, left: Wire, right: Wire) -> Wire
pub fn add(&mut self, left: Wire, right: Wire) -> Wire
Add two wires and return the result wire
Sourcepub fn mul(&mut self, left: Wire, right: Wire) -> Wire
pub fn mul(&mut self, left: Wire, right: Wire) -> Wire
Multiply two wires and return the result wire
Sourcepub fn build(self) -> ArithmeticCircuit<F>
pub fn build(self) -> ArithmeticCircuit<F>
Build the circuit
Auto Trait Implementations§
impl<F> Freeze for CircuitBuilder<F>
impl<F> RefUnwindSafe for CircuitBuilder<F>where
F: RefUnwindSafe,
impl<F> Send for CircuitBuilder<F>
impl<F> Sync for CircuitBuilder<F>
impl<F> Unpin for CircuitBuilder<F>where
F: Unpin,
impl<F> UnsafeUnpin for CircuitBuilder<F>
impl<F> UnwindSafe for CircuitBuilder<F>where
F: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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