Skip to main content

CircuitElem

Enum CircuitElem 

Source
pub enum CircuitElem<F: Field, B: CircuitBuilder<Field = F>> {
    Constant(F),
    Wire {
        builder: Weak<RefCell<B>>,
        wire: B::Wire,
    },
}
Expand description

A field element that is either a known constant or a wire in a CircuitBuilder B.

The Wire variant holds a Weak reference to the shared builder; it must outlive any operation performed on the element. Arithmetic over all-Constant operands folds at the F level without touching a builder; any Wire operand routes the operation through B.

Variants§

§

Constant(F)

§

Wire

Fields

§builder: Weak<RefCell<B>>
§wire: B::Wire

Implementations§

Source§

impl<F, B> CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source

pub fn wire(builder: &Rc<RefCell<B>>, wire: B::Wire) -> Self

Construct a Self::Wire anchored to a shared builder via a Weak reference.

Source

pub fn to_wire(&self, builder: &mut B) -> B::Wire

Lowers this element to a wire on builder, materializing a Constant via CircuitBuilder::constant. A Wire’s backing builder is assumed to be builder; callers mixing elements from different channels must check that themselves (as Self::combine does).

Source

pub fn combine<const IN: usize, const OUT: usize>( elems: [&Self; IN], f_op: impl Fn([F; IN]) -> [F; OUT], builder_op: impl Fn(&mut B, [B::Wire; IN]) -> [B::Wire; OUT], ) -> [Self; OUT]

Combine elems under an operation. If every input is a Constant, fold at the F level via f_op (no builder is touched). Otherwise convert constants to wires on the shared builder and run builder_op over the wires.

Source

pub fn combine_varlen( elems: &[&Self], n_out: usize, f_op: impl FnOnce(&[F]) -> Vec<F>, builder_op: impl FnOnce(&mut B, &[B::Wire]) -> Vec<B::Wire>, ) -> Vec<Self>

Variable-arity sibling of Self::combine.

f_op and builder_op must return a Vec of length n_out; checked via debug_assert_eq!.

Trait Implementations§

Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Add for CircuitElem<F, B>

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<F, B> Add for &CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<F, B> Add<&CircuitElem<F, B>> for CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> AddAssign for CircuitElem<F, B>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> AddAssign<&CircuitElem<F, B>> for CircuitElem<F, B>

Source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Clone for CircuitElem<F, B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Debug for CircuitElem<F, B>
where B::Wire: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> FieldOps for CircuitElem<F, B>

Source§

type Scalar = F

Source§

fn zero() -> Self

Returns the zero element (additive identity).
Source§

fn one() -> Self

Returns the one element (multiplicative identity).
Source§

fn square_transpose<FSub: Field>(elems: &mut [Self])
where Self::Scalar: ExtensionField<FSub>,

Transpose the subfield elements in a slice of field elements. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> From<F> for CircuitElem<F, B>

Source§

fn from(val: F) -> Self

Converts to this type from the input type.
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> InvertOrZero for CircuitElem<F, B>

Source§

fn invert_or_zero(self) -> Self

Not implemented: nothing the wrapper runs inverts a value that may be zero.

The verifier’s own inversions are all of random challenges, which it argues are non-zero, so they go through InvertOrZero::invert below. Constraining the zero case as well would cost extra constraints on every one of them, to admit an input no caller has.

This panics while the circuit is being built rather than at proving time, so a caller that does need it fails loudly and can implement it then.

Source§

unsafe fn invert(self) -> Self

Constrains the hinted inverse with the single product the contract allows.

§Safety

The caller guarantees the value is non-zero. At zero the emitted constraint x * inv == 1 is unsatisfiable, so the circuit becomes unprovable rather than yielding a wrong proof.

Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Mul for CircuitElem<F, B>

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl<F, B> Mul for &CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<F, B> Mul<&CircuitElem<F, B>> for CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> MulAssign for CircuitElem<F, B>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> MulAssign<&CircuitElem<F, B>> for CircuitElem<F, B>

Source§

fn mul_assign(&mut self, rhs: &Self)

Performs the *= operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Neg for CircuitElem<F, B>

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Product for CircuitElem<F, B>

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<'a, F: Field, B: CircuitBuilder<Field = F>> Product<&'a CircuitElem<F, B>> for CircuitElem<F, B>

Source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Square for CircuitElem<F, B>

Source§

fn square(self) -> Self

Returns the value multiplied by itself
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Sub for CircuitElem<F, B>

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<F, B> Sub for &CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<F, B> Sub<&CircuitElem<F, B>> for CircuitElem<F, B>
where F: Field, B: CircuitBuilder<Field = F>,

Source§

type Output = CircuitElem<F, B>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> SubAssign for CircuitElem<F, B>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> SubAssign<&CircuitElem<F, B>> for CircuitElem<F, B>

Source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
Source§

impl<F: Field, B: CircuitBuilder<Field = F>> Sum for CircuitElem<F, B>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<'a, F: Field, B: CircuitBuilder<Field = F>> Sum<&'a CircuitElem<F, B>> for CircuitElem<F, B>

Source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

§

impl<F, B> !RefUnwindSafe for CircuitElem<F, B>

§

impl<F, B> !Send for CircuitElem<F, B>

§

impl<F, B> !Sync for CircuitElem<F, B>

§

impl<F, B> !UnwindSafe for CircuitElem<F, B>

§

impl<F, B> Freeze for CircuitElem<F, B>
where F: Freeze, <B as CircuitBuilder>::Wire: Freeze,

§

impl<F, B> Unpin for CircuitElem<F, B>
where F: Unpin, <B as CircuitBuilder>::Wire: Unpin,

§

impl<F, B> UnsafeUnpin for CircuitElem<F, B>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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