Skip to content

Binary solver for array equality constraints#520

Closed
guipublic wants to merge 28 commits intomasterfrom
gd/auto_return_array
Closed

Binary solver for array equality constraints#520
guipublic wants to merge 28 commits intomasterfrom
gd/auto_return_array

Conversation

@guipublic
Copy link
Copy Markdown
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
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
Copy Markdown
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.

UnknownError(String), //Generic error
UnsupportedOpcode(OPCODE), //Unsupported Opcode
UnsatisfiedConstrain, //Gate is not satisfied
Solved, //Circuit is solved, after a number of passes
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Closing as this is no longer relevant

@kevaundray kevaundray closed this Jul 13, 2023
@TomAFrench TomAFrench deleted the gd/auto_return_array branch January 8, 2026 17:07
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