Skip to content
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

Closed
wants to merge 28 commits into from

Conversation

guipublic
Copy link
Contributor

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

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

@guipublic guipublic requested a review from kevaundray November 24, 2022 15:44
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/pwg/binary.rs Outdated Show resolved Hide resolved
crates/acvm/src/pwg/binary.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
crates/acvm/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +61 to +70
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

@TomAFrench
Copy link
Member

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.

@guipublic
Copy link
Contributor Author

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.

@kevaundray
Copy link
Contributor

Closing as this is no longer relevant

@kevaundray kevaundray closed this Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto return doesn't work with arrays
5 participants