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

Add callback-oriented versions of constraint_system and generate_witness #836

Merged
merged 54 commits into from
Mar 7, 2024

Conversation

mrmr1993
Copy link
Member

This PR refactors the internals of snarky to expose a callback-oriented version of the functions constraint_system and generate_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.

Copy link
Member

@mitschabaude mitschabaude left a 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. *)
Copy link
Member

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

@mrmr1993 mrmr1993 mentioned this pull request Mar 5, 2024
@mitschabaude mitschabaude merged commit c4457d5 into master Mar 7, 2024
3 of 4 checks passed
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.

3 participants