pepper-project / pequin

A system for verifying outsourced computations, and applying SNARKs. Simplified release of the main Pepper codebase.
Other
122 stars 46 forks source link

Adding support to call into external libsnark gadgets #20

Closed fleupold closed 5 years ago

fleupold commented 5 years ago

This pull request will allow people to call into external gadgets (e.g. libsnark's sha256_two_to_one_hash_gadget) by providing an executable that can respond to three commands

  1. gadgetN size: returns the number of intermediate variables the gadget requires
  2. gadgetN constraints a|b|c: returns the constraints for the a|b|c matrix in the form row column value
  3. gadgetN witness [inputs]: given the inputs, generate a fulfilling assignment for the constraints in the gadget and return it as a list of values.

This will allow you to use highly optimized gadget for expensive operations (e.g. hashing) while still using the convenience pepper offers for iterations, conditionals and other high level processing code. An example .c file using the ext_gadget call can be seen here: https://pastebin.com/kMExVe3L

The pull request will contain out of three steps:

  1. Add support for an ext_gadget function call in the frontend (similar to exo_compute)
  2. In the backend, when reading the ext_gadget command insert the external R1CS into the R1CS we are currently building.
  3. In the prover, when trying to process the ext_gadget command call into the gadget to get the witness instead of letting the prover run

I am planning to break this PR up into multiple commits to make it easier to review. Please feel free to comment with suggestions already now. I'm more than happy to redesign or iterate on the approach if you think there is a better one.

fleupold commented 5 years ago

Added documentation and an example. Also made sure that the exo_compute example is still running and we can run the same gadget in a loop.