Skip to content

perf: add a function for handling hints more efficiently#659

Closed
aybehrouz wants to merge 4 commits into
Consensys:developfrom
aybehrouz:perf/stateless-hints
Closed

perf: add a function for handling hints more efficiently#659
aybehrouz wants to merge 4 commits into
Consensys:developfrom
aybehrouz:perf/stateless-hints

Conversation

@aybehrouz
Copy link
Copy Markdown
Contributor

@aybehrouz aybehrouz commented Apr 22, 2023

This PR provides a possible solution for issue #653.

@aybehrouz
Copy link
Copy Markdown
Contributor Author

aybehrouz commented Apr 22, 2023

Tests are failing here, but on my local machine they look fine. By using NewStateLessHint when ToBinary is called on a constant, it only creates one constraint, while I've not handled the constant path in the function at all.

@aybehrouz aybehrouz marked this pull request as ready for review April 27, 2023 11:25
@ivokub ivokub mentioned this pull request May 3, 2023
@aybehrouz
Copy link
Copy Markdown
Contributor Author

@ivokub @gbotrel @Tabaie

Hi,
What do you think about this PR, guys? It is the implementation of this idea: #653 (comment)

@gbotrel
Copy link
Copy Markdown
Collaborator

gbotrel commented May 23, 2023

hey sorry we had a lot going on forgot about that one, thanks for the nudge.

  • I prefer to see hints (all of them) as stateless functions. but we have several examples where circuit-developers used them as ... a way to introduce new wires and/or put a "hook" in the solver.
    --> so far the contract was "using a solver hint, you are introducing new wires and putting a placeholder for the solver to resolve these wires at solve time".

  • not sure we do need the "hint inputs are constants, let's optimized it out" a lot. If it's isolated in one or two places (like ToBinary) might be simpler to target the issue there for now. it is more conservative but maybe a couple of extra constraints on some edge cases is better than introducing subtle behavior / doubling APIs for hints (note that for the stateless one; the compiler has no way to actually check that the function is indeed stateless).

will sync with @ivokub & @Tabaie 👍

@aybehrouz
Copy link
Copy Markdown
Contributor Author

I see. So, If you don't like the idea of a generic solution, For now I'd recommend handling constant inputs in ToBinary explicitly. There are some practical examples that shows ToBinary may be called with a constant input, while the programmer cannot notice it. (the call is done inside another function) The current Implementation of ToBinary creates around 250 constraints for a constant input, while no constraints are needed.

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.

2 participants