-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary solver for array equality constraints #520
Conversation
let mut result = GateResolution::Skip; | ||
if let Gate::Arithmetic(arith) = gate { | ||
let partial_gate = | ||
super::arithmetic::ArithmeticSolver::evaluate(arith, initial_witness); | ||
result = self.solve_booleans(initial_witness, &partial_gate); | ||
self.identify_booleans(&partial_gate); | ||
} else { | ||
self.identify_binaries(gate); | ||
} | ||
result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut result = GateResolution::Skip; | |
if let Gate::Arithmetic(arith) = gate { | |
let partial_gate = | |
super::arithmetic::ArithmeticSolver::evaluate(arith, initial_witness); | |
result = self.solve_booleans(initial_witness, &partial_gate); | |
self.identify_booleans(&partial_gate); | |
} else { | |
self.identify_binaries(gate); | |
} | |
result | |
if let Gate::Arithmetic(arith) = gate { | |
let partial_gate = | |
super::arithmetic::ArithmeticSolver::evaluate(arith, initial_witness); | |
let result = self.solve_booleans(initial_witness, &partial_gate); | |
self.identify_booleans(&partial_gate); | |
result | |
} else { | |
self.identify_binaries(gate); | |
GateResolution::Skip | |
} |
We can remove some indirection with the mutable result here.
@@ -30,6 +31,7 @@ pub enum GateResolution { | |||
UnknownError(String), //Generic error | |||
UnsupportedOpcode(OPCODE), //Unsupported Opcode | |||
UnsatisfiedConstrain, //Gate is not satisfied | |||
Solved, //Circuit is solved, after a number of passes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the variant entirely? It is only returned by solve
, but there is no reason solve
could not return Resolved instead.
self.invert_witness.insert(*x, *result); | ||
} | ||
Gate::Arithmetic(a) => { | ||
self.identify_booleans(a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this branch triggered?
seems identify_binaries is called when it is not an arithmetic gate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but still the function is correct like this, using unreachable! would make it fit for the current use and less versatile.
Can we close this now that #731 is merged or will this be useful in another context? We need to move this to ACVM anyway if so. |
Yes this is useful in another context, in fact the issue solved by #731 was because the solver is not able to solve array equality checks. This PR is solving this issue, while #731 worked around it by removing it in case of a return statement. |
Closing as this is no longer relevant |
Related issue(s)
Resolves #455
Description
Summary of changes
This PR adds a binary solver which is able to solve the array equality constraints by identifying boolean constraints.
Dependency additions / changes
The binary solver is used only when the regular solver is stalled, so this has no impact when there is no array returned, and when there is, it will act only on the remaining unsolved gates.
Test additions / changes
sha256 and main_return tests are updated
Checklist
cargo fmt
with default settings.