Struct ExpressionSolver

Source
pub(crate) struct ExpressionSolver;
Expand description

An Expression solver will take a Circuit’s assert-zero opcodes with witness assignments and create the other witness variables

Implementations§

Source§

impl ExpressionSolver

Source

pub(crate) fn solve<F: AcirField>( initial_witness: &mut WitnessMap<F>, opcode: &Expression<F>, ) -> Result<(), OpcodeResolutionError<F>>

Derives the rest of the witness based on known witness values in a single pass.

For expressions with 0 or 1 multiplication terms (the common case), this avoids allocating an intermediate Expression and eliminates redundant witness map lookups. Falls back to the general evaluate-based approach for 2+ mul terms or when linear term combining is needed.

Source

fn verify_satisfied<F: AcirField>( sum: F, ) -> Result<(), OpcodeResolutionError<F>>

Verify that the fully-evaluated expression equals zero.

Source

fn solve_single_unknown<F: AcirField>( sum: F, coeff: F, witness: Witness, initial_witness: &mut WitnessMap<F>, ) -> Result<(), OpcodeResolutionError<F>>

Solve sum + coeff * witness = 0 for the witness.

Source

fn solve_via_evaluate<F: AcirField>( initial_witness: &mut WitnessMap<F>, opcode: &Expression<F>, ) -> Result<(), OpcodeResolutionError<F>>

General solver that allocates an intermediate evaluated Expression. Used as a fallback when the single-pass approach cannot handle the expression (2+ mul terms, or linear terms that need combining).

Source

fn mul_term_status<F: AcirField>( mul_terms: &[(F, Witness, Witness)], ) -> Result<MulTerm<F>, OpcodeStatus<F>>

Indicates the ‘solved’ status of the mul term, after partial evaluation.

Source

fn solve_mul_term_helper<F: AcirField>( term: &(F, Witness, Witness), witness_assignments: &WitnessMap<F>, ) -> MulTerm<F>

Try to solve a multiplication term of the form qab, where q is a constant and a,b are witnesses If both a and b have known values (in the provided map), it returns the value qab If only one of a or b has a known value, it returns the linear term c*w where c is a constant and w is the unknown witness If both a and b are unknown, it returns MulTerm::TooManyUnknowns

Source

fn solve_fan_in_term_helper<F: AcirField>( term: &(F, Witness), witness_assignments: &WitnessMap<F>, ) -> Option<F>

Reduce a linear term to its value if the witness assignment is known If the witness value is not known in the provided map, it returns None.

Source

pub(super) fn fan_in_status<F: AcirField>( linear_combinations: &[(F, Witness)], ) -> OpcodeStatus<F>

Indicate the ‘solved’ status of the linear terms after partial evaluation.

Source

pub(crate) fn evaluate<F: AcirField>( expr: &Expression<F>, initial_witness: &WitnessMap<F>, ) -> Expression<F>

Source

pub(crate) fn combine_linear_terms<F: AcirField>( linear_combinations: &[(F, Witness)], ) -> Vec<(F, Witness)>

Combines linear terms with the same witness by summing their coefficients. For example w1 + 2*w1 becomes 3*w1.

Source

pub(crate) fn combine_mul_terms<F: AcirField>( mul_terms: &[(F, Witness, Witness)], ) -> Vec<(F, Witness, Witness)>

Combines multiplication terms with the same witnesses by summing their coefficients. For example w1*w2 + 2*w2*w1 becomes 3*w1*w2. If a coefficient ends up being zero, the term is removed.

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