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>(
arith_opcode: &Expression<F>,
witness_assignments: &WitnessMap<F>,
) -> Result<MulTerm<F>, OpcodeStatus<F>>
fn solve_mul_term<F: AcirField>( arith_opcode: &Expression<F>, witness_assignments: &WitnessMap<F>, ) -> Result<MulTerm<F>, OpcodeStatus<F>>
Try to reduce the multiplication terms of the given expression 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>(
arith_opcode: &Expression<F>,
witness_assignments: &WitnessMap<F>,
) -> OpcodeStatus<F>
pub(super) fn solve_fan_in_term<F: AcirField>( arith_opcode: &Expression<F>, 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>
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§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
] or
a color-specific method, such as [OwoColorize::green
], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
] or
a color-specific method, such as [OwoColorize::on_yellow
], Read more