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

feat: use circom R1CS-to-QAP reduction #1

Merged
merged 2 commits into from
Jan 31, 2025
Merged

feat: use circom R1CS-to-QAP reduction #1

merged 2 commits into from
Jan 31, 2025

Conversation

Wollac
Copy link

@Wollac Wollac commented Jan 17, 2025

Make gnark proves snarkjs compatible:

snarkjs precomputes the Lagrange form of the powers of tau bases in a domain twice as large and the witness map is computed as the odd coefficients of (AB-C) in that domain. This serves as Z when computing the proof.

Closes ZKVM-902

go func() {
_, err := krs2.MultiExp(pk.G1.Z, h[:sizeH], ecc.MultiExpConfig{NbTasks: n / 2})
_, err := krs2.MultiExp(pk.G1.Z, h, ecc.MultiExpConfig{NbTasks: n / 2})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we now use the full h here. Are we safe to assume that any indices beyond the n-2 degree are 0?

Copy link

@capossele capossele Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw the new computeH, all good here. Maybe we can add a comment or something though, referring to how snarkjs does it in the same way

Copy link

linear bot commented Jan 29, 2025

Copy link

@capossele capossele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!
I'd just add some note maybe in the computeH function or somewhere that this new implementation is meant to be compatible with snarkjs (rather than the standard groth16 of gnark). That is just to make sure that people looking at the code understand why we have all this changes (e.g., a different root of unity shifting mechanism)

@Wollac Wollac merged commit 318f272 into risc0 Jan 31, 2025
@Wollac Wollac deleted the prove-circom branch January 31, 2025 13:41
Wollac added a commit that referenced this pull request Jan 31, 2025
* use R1CS-to-QAP circom reduction

* address review comment
Wollac added a commit that referenced this pull request Jan 31, 2025
* use R1CS-to-QAP circom reduction

* address review comment
pdg744 added a commit to risc0/risc0 that referenced this pull request Jan 31, 2025
Create Groth16 proofs using `gnark`instead of `rapidsnark`.

This process consists of the following parts:
- **`circom-compat`:** the Gnark bindings to Circom's R1CS, WTNS, and
ZKEY for Groth16 proof generation in Go.
- An update to the **`risczero/risc0-groth16-prover` Dockerfile**:
- During the Docker build process, it runs the `circom-compat` converter
to convert the `r1cs` and `zkey` files to their gnark counterparts.
- It replaces `rapidsnark` with the `circom-compat` prover that reads
these converted files plus the witness file.
- In the entrypoint script, it creates a named Unix pipe to write the
witness data to, allowing the prover to start and read the constraint
system while the witness generation is still running.
- A **patched `gnark`** version to match circom's R1CS-to-QAP reduction.
(See risc0/gnark#1)

The resulting docker image has been deployed as
[risczero/risc0-groth16-prover:v2025-01-24.1](https://hub.docker.com/layers/risczero/risc0-groth16-prover/v2025-01-24.1/images/sha256-434755bb2ccc0fb886f67855b67f37ba61c4983cb405dd3159588ce15016bbc3)
and `risc0/groth16/src/docker.rs` has been updated to use that image.
The `circom-compat` Go tests have been added to the CI.

Closes ZKVM-906

---------

Co-authored-by: Paul <[email protected]>
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