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
impl ExpressionSolver
Sourcepub(crate) fn solve<F: AcirField>(
initial_witness: &mut WitnessMap<F>,
opcode: &Expression<F>,
) -> Result<(), OpcodeResolutionError<F>>
pub(crate) fn solve<F: AcirField>( initial_witness: &mut WitnessMap<F>, opcode: &Expression<F>, ) -> Result<(), OpcodeResolutionError<F>>
Derives the rest of the witness in the provided expression based on the known witness values
- First we simplify the expression based on the known values and try to reduce the multiplication and linear terms
- If we end up with only the constant term;
- if it is 0 then the opcode is solved, if not,
- the assert_zero opcode is not satisfied and we return an error
- If we end up with only linear terms on the same witness ‘w’,
we can regroup them and solve ‘a*w+c = 0’:
- If ‘a’ is zero in the above expression;
- if c is also 0 then the opcode is solved
- if not that means the assert_zero opcode is not satisfied and we return an error
- If ‘a’ is not zero, we can solve it by setting the value of w: ‘w = -c/a’
- If ‘a’ is zero in the above expression;
Sourcefn solve_mul_term<F: AcirField>(
mul_terms: &[(F, Witness, Witness)],
witness_assignments: &WitnessMap<F>,
) -> Result<MulTerm<F>, OpcodeStatus<F>>
fn solve_mul_term<F: AcirField>( mul_terms: &[(F, Witness, Witness)], witness_assignments: &WitnessMap<F>, ) -> Result<MulTerm<F>, OpcodeStatus<F>>
Try to reduce the multiplication terms of the given expression’s mul terms to a known value or to a linear term, using the provided witness mapping. If there are 2 or more multiplication terms it returns the OpcodeUnsolvable error. If no witnesses value is in the provided ‘witness_assignments’ map, it returns MulTerm::TooManyUnknowns
Sourcefn solve_mul_term_helper<F: AcirField>(
term: &(F, Witness, Witness),
witness_assignments: &WitnessMap<F>,
) -> MulTerm<F>
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
Sourcefn solve_fan_in_term_helper<F: AcirField>(
term: &(F, Witness),
witness_assignments: &WitnessMap<F>,
) -> Option<F>
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.
Sourcepub(super) fn solve_fan_in_term<F: AcirField>(
linear_combinations: &[(F, Witness)],
witness_assignments: &WitnessMap<F>,
) -> OpcodeStatus<F>
pub(super) fn solve_fan_in_term<F: AcirField>( linear_combinations: &[(F, Witness)], witness_assignments: &WitnessMap<F>, ) -> OpcodeStatus<F>
Returns the summation of all of the variables, plus the unknown variable
Returns OpcodeStatus::OpcodeUnsolvable, if there is more than one unknown variable
pub(crate) fn evaluate<F: AcirField>( expr: &Expression<F>, initial_witness: &WitnessMap<F>, ) -> Expression<F>
Sourcepub(crate) fn combine_linear_terms<F: AcirField>(
linear_combinations: &[(F, Witness)],
) -> Vec<(F, Witness)>
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.
Sourcepub(crate) fn combine_mul_terms<F: AcirField>(
mul_terms: &[(F, Witness, Witness)],
) -> Vec<(F, Witness, Witness)>
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§
impl Freeze for ExpressionSolver
impl RefUnwindSafe for ExpressionSolver
impl Send for ExpressionSolver
impl Sync for ExpressionSolver
impl Unpin for ExpressionSolver
impl UnwindSafe for ExpressionSolver
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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