arkworks-rs / groth16

A Rust implementation of the Groth16 zkSNARK
https://www.arkworks.rs
Apache License 2.0
252 stars 101 forks source link

feat: allow using custom R1CS to QAP reductions #34

Closed gakonst closed 3 years ago

gakonst commented 3 years ago

Description

As discussed, it is potentially useful to allow customizing the R1CS to QAP conversion, for cases such as Circom's where they skip some of the FFTs.

Implementation

This PR abstracts the R1CS to QAP to a trait and exposes methods for providing implementors of the trait. It maintains backwards compat.

Pratyush commented 3 years ago

Actually another suggestion: maybe we can parameterize the Groth16 struct itself by a new generic type parameter bounded by the R1CSToQap trait, and set the default to the old version? Do you think that would be cleaner?

gakonst commented 3 years ago

Addressed your comments!

Actually another suggestion: maybe we can parameterize the Groth16 struct itself by a new generic type parameter bounded by the R1CSToQap trait, and set the default to the old version? Do you think that would be cleaner?

I think we should be considering a larger refactor (which I've started here) so as to allow the prover to cache intermediate steps, which should also help with having a cleaner abstraction around the QAP type

Pratyush commented 3 years ago

Also, for the documentation, should we add the details of the reduction as described in libsnark: https://github.com/scipr-lab/libsnark/blob/2af440246fa2c3d0b1b0a425fb6abd8cc8b9c54d/libsnark/reductions/r1cs_to_qap/r1cs_to_qap.tcc

Pratyush commented 3 years ago

I updated the API names slightly @gakonst, but this is good to merge otherwise. Any comments?