-
Notifications
You must be signed in to change notification settings - Fork 238
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
Compiled should introduce an optimalisation and inject helper unconstrained functions to help with division. #4214
Comments
All division is unconstrained division! Whenever we do integer division we calculate the quotient and remainder in an unconstrained function, range constrain these two witnesses, and then enforce that noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs Lines 714 to 762 in 26e9618
A lot of the savings that from that refactor come down to:
The last one is a potential compiler improvement but it would require us to cache a lot of division results and the situations where it would come up most (splitting an integer into limbs of smaller integers) are easy enough to recognise that I think that adding a |
Problem
This section of docs describes the optimalization that if some computation is cheaper to verify than compute - we should compute it in unconstrained code and only verify the results in constrained.
In general case - this is too high level for an optimiser to pick up.
For integer division - it can be done quite easily and introduce measurable benefits.
Happy Case
When compiler see integer division - it should replace it with an unconstrained division and constrained multiplication reducing the backend circuit size
Alternatives Considered
No response
Additional Context
I've recently submitted a PR to noir-trie-proofs that does this optimalisation manually and it saves 3% of gates.
aragonzkresearch/noir-trie-proofs#11
Would you like to submit a PR for this Issue?
Maybe
Support Needs
I might be interested in submitting a PR with this change, but I'll need some guidance. Please let me know if you think it's a good idea and where would be the best stage to do a transformation like that.
The text was updated successfully, but these errors were encountered: