-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add callback-oriented versions of constraint_system
and generate_witness
#836
Conversation
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.
to let callers recover from errors, we could add a third callback, which just resets the state to what it was:
type ('input_var, 'return_var, 'result) manual_callbacks =
{ run_circuit : 'a. ('input_var -> unit -> 'a) -> 'a
; finish_computation : 'return_var -> 'result
; reset_state : unit -> unit
}
and you'd use it like this pseudo-code
let builder = constraint_system_manual();
try {
let result = await build.run_circuit(input);
builder.finish_computation(result);
} catch (err) {
builder.reset_state();
}
since its optional to use use reset_state
and handle errors, this would be an easy change.
still approving though because it seems that the present version is good enough (passes all tests across the stack, even those that intentionally create errors in circuits - probably because snarky's current state, however broken, never affects subsequent circuit runs, because states are just nested)
let builder = | ||
Run.Constraint_system_builder.build ~input_typ ~return_typ | ||
in | ||
(* FIXME: This behaves badly with exceptions. *) |
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.
see my review on a way to improve this
This PR refactors the internals of snarky to expose a callback-oriented version of the functions
constraint_system
andgenerate_witness
. As the core entrypoints used by pickles, this allows us to use these callbacks to handle async witness generation.This PR is structured as a series of refactoring commits, plus a final commit that implements the new functions. Each refactoring is deliberately structured so that there is no behavioural change, except for a few small performance optimisations as a result of removing duplicated/redundant computations.