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 groth16 verifier example #1231

Merged
merged 23 commits into from
Jan 17, 2024
Merged

Add groth16 verifier example #1231

merged 23 commits into from
Jan 17, 2024

Conversation

capossele
Copy link
Contributor

@capossele capossele commented Dec 14, 2023

Adds an example (based on a Sudoku game) showing how to verify inside the zkVM a Groth16 snark proof over the BN_254 curve, generated by Circom/SnarkJS.

Closes #1131

Copy link

vercel bot commented Dec 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 9:43am

Comment on lines 12 to 24
# Always optimize; building and running the guest takes much longer without optimization.
[profile.dev]
opt-level = 3

[profile.dev.build-override]
opt-level = 3

[profile.release]
debug = 1
lto = true

[profile.release.build-override]
opt-level = 3
Copy link
Member

Choose a reason for hiding this comment

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

The workspace already contains all of this. They will be ignored when specified here.

Copy link
Contributor

@nategraf nategraf left a comment

Choose a reason for hiding this comment

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

This looks good to me, as far as providing example code. I don't want to preempt any further comments/concerns from @flaub, if he has any.

examples/groth16-verifier/Cargo.toml Outdated Show resolved Hide resolved
examples/groth16-verifier/README.md Outdated Show resolved Hide resolved
examples/groth16-verifier/README.md Outdated Show resolved Hide resolved
examples/groth16-verifier/README.md Outdated Show resolved Hide resolved
examples/groth16-verifier/groth16/src/circom.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

I think this file needs to be dropped. If it's part of a workspace, then this file is most likely being ignored anyways.

Co-authored-by: Victor Graf <victor@risczero.com>
@capossele capossele merged commit 2342cc1 into main Jan 17, 2024
23 checks passed
@capossele capossele deleted the capossele/groth16-example branch January 17, 2024 10:05
flaub pushed a commit that referenced this pull request Jan 18, 2024
Adds an example (based on a Sudoku game) showing how to verify inside
the zkVM a Groth16 snark proof over the BN_254 curve, generated by
Circom/SnarkJS.


Closes #1131

---------

Co-authored-by: Victor Graf <victor@risczero.com>
flaub pushed a commit that referenced this pull request Jan 18, 2024
Adds an example (based on a Sudoku game) showing how to verify inside
the zkVM a Groth16 snark proof over the BN_254 curve, generated by
Circom/SnarkJS.


Closes #1131

---------

Co-authored-by: Victor Graf <victor@risczero.com>
weikengchen added a commit to l2iterative/risc0 that referenced this pull request Jan 18, 2024
* Add instruction on how to install dependencies and check out correct example version (risc0#1320)

Co-authored-by: Frank Laub <flaub@risc0.com>

* Add composition terminology to website and otherwise improve docs (risc0#1314)

This PR adds terminology entries to the website for terms/concepts
related to composition. Additionally is adds a bit more documentation to
types and methods related to composition, and additionally refactors the
`ExecutorEnv::add_assumption` method to accept `impl Into<Assumption>`
which allows the user to pass in a receipt without any transformation.

---------

Co-authored-by: Tim Zerrell <tim.zerrell@risczero.com>

* Groth16 prover (risc0#1295)

Groth16 prover

* Add workflow for generation of groth16 proof of STARK verification.
* Fix xtask bootstrap to break cyclic dependency

---------

Co-authored-by: Frank Laub <flaub@risc0.com>

* zkVM: update expected panic string to be compatible with new toolchains (risc0#1334)

Newer toolchains have a more detailed panic message in the guest
including the line number of the panic. Without this change the 1.75.0
toolchain will fail the `guest_error_forwarding` test like so:

```
running 1 test
test host::api::tests::guest_error_forwarding - should panic ... FAILED

failures:

---- host::api::tests::guest_error_forwarding stdout ----
thread 'host::api::tests::guest_error_forwarding' panicked at risc0/zkvm/src/host/api/tests.rs:146:22:
called `Result::unwrap()` on an `Err` value: Guest panicked: panicked at src/bin/multi_test.rs:99:13:
MultiTestSpec::Panic invoked
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: panic did not contain expected string
      panic message: `"called `Result::unwrap()` on an `Err` value: Guest panicked: panicked at src/bin/multi_test.rs:99:13:\nMultiTestSpec::Panic invoked"`,
 expected substring: `"Guest panicked: panicked at 'MultiTestSpec::Panic invoked'"`
```

Update the expected panic message so it works for older and newer
toolchains.

* Update docs to include resolve step (risc0#1335)

* Fix missing foundry toolchain (risc0#1338)

* Update serial_test requirement from 2.0 to 3.0 (risc0#1300)

Updates the requirements on
[serial_test](https://github.com/palfrey/serial_test) to permit the
latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/palfrey/serial_test/releases">serial_test's
releases</a>.</em></p>
<blockquote>
<h2>v3.0.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Multi key support <a
href="https://redirect.github.com/palfrey/serial_test/pull/102">palfrey/serial_test#102</a>
<ul>
<li>Attributes like <code>#[serial(one, two)]</code> are now supported
(for all attributes)</li>
<li>This is a breaking change, as <code>file_serial</code> paths now
need to be done separately <code>#[file_serial(key, path =&gt;
&quot;/tmp/foo&quot;)]</code></li>
</ul>
</li>
<li>Attributes at a mod-level <a
href="https://redirect.github.com/palfrey/serial_test/pull/104">palfrey/serial_test#104</a>
<ul>
<li>You can set any of the attributes on a <code>mod</code> and all
<code>#[test]</code> fn's in that mod will have the attribute
applied.</li>
</ul>
</li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/palfrey/serial_test/compare/v2.0.0...v3.0.0">https://github.com/palfrey/serial_test/compare/v2.0.0...v3.0.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/palfrey/serial_test/commit/bba3db847f10b0fbcbd71465cc233b0d510a3dd0"><code>bba3db8</code></a>
3.0.0</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/ae14645ea14fd1f3b8ddd09601062b3c9fbd5a42"><code>ae14645</code></a>
Merge pull request <a
href="https://redirect.github.com/palfrey/serial_test/issues/104">#104</a>
from palfrey/serial-for-mod</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/0dec256fe181fd9660077515f861614dd012ead2"><code>0dec256</code></a>
Merge branch 'main' into serial-for-mod</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/cee1dc17dbc7b90ab2c0d7fa81761871b1772fa1"><code>cee1dc1</code></a>
Add testing and parallel to package keywords</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/2a4b641ea9b6664ec3165826fcd4c93bcfd53b6a"><code>2a4b641</code></a>
Merge branch 'main' into serial-for-mod</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/288d933b77721f617b8e6e03e3c98515ae7876a1"><code>288d933</code></a>
Merge pull request <a
href="https://redirect.github.com/palfrey/serial_test/issues/105">#105</a>
from palfrey/upgrade-rustix</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/cf9d7fef6223d73d69f1c14197b4f79df994046f"><code>cf9d7fe</code></a>
Upgrade rustix</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/a8d985d9fde5aff6fe8822f71775f66c21a72a62"><code>a8d985d</code></a>
Replace a single-use match with if let</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/67d22ff9eef867032031e30fc65a58154f588364"><code>67d22ff</code></a>
Fix some clippy issues</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/ff2890d91b18e5d2b5e8ea546636a261a051ead2"><code>ff2890d</code></a>
Update docs for mod-level functionality</li>
<li>Additional commits viewable in <a
href="https://github.com/palfrey/serial_test/compare/v2.0.0...v3.0.0">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frank Laub <flaub@risc0.com>

* Add groth16 verifier example (risc0#1231)

Adds an example (based on a Sudoku game) showing how to verify inside
the zkVM a Groth16 snark proof over the BN_254 curve, generated by
Circom/SnarkJS.


Closes risc0#1131

---------

Co-authored-by: Victor Graf <victor@risczero.com>

* Distinguish between and avoid use of ExitCode::Fault and SessionLimit (risc0#1317)

Currently our code does not distinguish between guest-reported/proven
and host-reported/unproven exit codes. This PR addresses this issue by
giving `ExitCode::SystemSplit`, `Fault` and `SessionLimit` distinct exit
codes.

The rv32im circuit does not support exiting with with a verified status
of `SessionLimit` or `Fault`. As a result, these exit codes should be
unused and reserved for future revision of the circuit. This PR
refactors the executor to reflect this and align with the fact that the
prover will never write these statuses to the seal.

Supersedes: risc0#1313
Resolves: risc0#1306

---------

Co-authored-by: Frank Laub <flaub@risc0.com>

* Add ProverServer::compress and use it to make receipts succinct by default (risc0#1325)

This PR adds a `ProverServer::compress` function that uses the `lift`,
`join`, and `resolve` recursion programs to compress a
`CompositeReceipt` into a `SuccinctReceipt`. This PR then uses this
function to compress receipts when `prove_session` is called, and
therefore compress receipts by default.

This PR also:
* Adds an `ExitCode::is_ok` function to clean up some code I saw along
the way to implementing this PR

---------

Co-authored-by: Frank Laub <flaub@risc0.com>

* check hash

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Matheus Cardoso <45436839+Cardosaum@users.noreply.github.com>
Co-authored-by: Frank Laub <flaub@risc0.com>
Co-authored-by: Victor Graf <victor@risczero.com>
Co-authored-by: Tim Zerrell <tim.zerrell@risczero.com>
Co-authored-by: Angelo Capossele <angelocapossele@gmail.com>
Co-authored-by: Erik Kaneda <erik@risczero.com>
Co-authored-by: Rami Lukata <32602478+rlukata@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
weikengchen added a commit to l2iterative/risc0 that referenced this pull request Jan 18, 2024
* Add instruction on how to install dependencies and check out correct example version (risc0#1320)

Co-authored-by: Frank Laub <flaub@risc0.com>

* Add composition terminology to website and otherwise improve docs (risc0#1314)

This PR adds terminology entries to the website for terms/concepts
related to composition. Additionally is adds a bit more documentation to
types and methods related to composition, and additionally refactors the
`ExecutorEnv::add_assumption` method to accept `impl Into<Assumption>`
which allows the user to pass in a receipt without any transformation.

---------

Co-authored-by: Tim Zerrell <tim.zerrell@risczero.com>

* Groth16 prover (risc0#1295)

Groth16 prover

* Add workflow for generation of groth16 proof of STARK verification.
* Fix xtask bootstrap to break cyclic dependency

---------

Co-authored-by: Frank Laub <flaub@risc0.com>

* zkVM: update expected panic string to be compatible with new toolchains (risc0#1334)

Newer toolchains have a more detailed panic message in the guest
including the line number of the panic. Without this change the 1.75.0
toolchain will fail the `guest_error_forwarding` test like so:

```
running 1 test
test host::api::tests::guest_error_forwarding - should panic ... FAILED

failures:

---- host::api::tests::guest_error_forwarding stdout ----
thread 'host::api::tests::guest_error_forwarding' panicked at risc0/zkvm/src/host/api/tests.rs:146:22:
called `Result::unwrap()` on an `Err` value: Guest panicked: panicked at src/bin/multi_test.rs:99:13:
MultiTestSpec::Panic invoked
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: panic did not contain expected string
      panic message: `"called `Result::unwrap()` on an `Err` value: Guest panicked: panicked at src/bin/multi_test.rs:99:13:\nMultiTestSpec::Panic invoked"`,
 expected substring: `"Guest panicked: panicked at 'MultiTestSpec::Panic invoked'"`
```

Update the expected panic message so it works for older and newer
toolchains.

* Update docs to include resolve step (risc0#1335)

* Fix missing foundry toolchain (risc0#1338)

* Update serial_test requirement from 2.0 to 3.0 (risc0#1300)

Updates the requirements on
[serial_test](https://github.com/palfrey/serial_test) to permit the
latest version.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/palfrey/serial_test/releases">serial_test's
releases</a>.</em></p>
<blockquote>
<h2>v3.0.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Multi key support <a
href="https://redirect.github.com/palfrey/serial_test/pull/102">palfrey/serial_test#102</a>
<ul>
<li>Attributes like <code>#[serial(one, two)]</code> are now supported
(for all attributes)</li>
<li>This is a breaking change, as <code>file_serial</code> paths now
need to be done separately <code>#[file_serial(key, path =&gt;
&quot;/tmp/foo&quot;)]</code></li>
</ul>
</li>
<li>Attributes at a mod-level <a
href="https://redirect.github.com/palfrey/serial_test/pull/104">palfrey/serial_test#104</a>
<ul>
<li>You can set any of the attributes on a <code>mod</code> and all
<code>#[test]</code> fn's in that mod will have the attribute
applied.</li>
</ul>
</li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/palfrey/serial_test/compare/v2.0.0...v3.0.0">https://github.com/palfrey/serial_test/compare/v2.0.0...v3.0.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/palfrey/serial_test/commit/bba3db847f10b0fbcbd71465cc233b0d510a3dd0"><code>bba3db8</code></a>
3.0.0</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/ae14645ea14fd1f3b8ddd09601062b3c9fbd5a42"><code>ae14645</code></a>
Merge pull request <a
href="https://redirect.github.com/palfrey/serial_test/issues/104">#104</a>
from palfrey/serial-for-mod</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/0dec256fe181fd9660077515f861614dd012ead2"><code>0dec256</code></a>
Merge branch 'main' into serial-for-mod</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/cee1dc17dbc7b90ab2c0d7fa81761871b1772fa1"><code>cee1dc1</code></a>
Add testing and parallel to package keywords</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/2a4b641ea9b6664ec3165826fcd4c93bcfd53b6a"><code>2a4b641</code></a>
Merge branch 'main' into serial-for-mod</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/288d933b77721f617b8e6e03e3c98515ae7876a1"><code>288d933</code></a>
Merge pull request <a
href="https://redirect.github.com/palfrey/serial_test/issues/105">#105</a>
from palfrey/upgrade-rustix</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/cf9d7fef6223d73d69f1c14197b4f79df994046f"><code>cf9d7fe</code></a>
Upgrade rustix</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/a8d985d9fde5aff6fe8822f71775f66c21a72a62"><code>a8d985d</code></a>
Replace a single-use match with if let</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/67d22ff9eef867032031e30fc65a58154f588364"><code>67d22ff</code></a>
Fix some clippy issues</li>
<li><a
href="https://github.com/palfrey/serial_test/commit/ff2890d91b18e5d2b5e8ea546636a261a051ead2"><code>ff2890d</code></a>
Update docs for mod-level functionality</li>
<li>Additional commits viewable in <a
href="https://github.com/palfrey/serial_test/compare/v2.0.0...v3.0.0">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Frank Laub <flaub@risc0.com>

* Add groth16 verifier example (risc0#1231)

Adds an example (based on a Sudoku game) showing how to verify inside
the zkVM a Groth16 snark proof over the BN_254 curve, generated by
Circom/SnarkJS.


Closes risc0#1131

---------

Co-authored-by: Victor Graf <victor@risczero.com>

* remove the warning

* Distinguish between and avoid use of ExitCode::Fault and SessionLimit (risc0#1317)

Currently our code does not distinguish between guest-reported/proven
and host-reported/unproven exit codes. This PR addresses this issue by
giving `ExitCode::SystemSplit`, `Fault` and `SessionLimit` distinct exit
codes.

The rv32im circuit does not support exiting with with a verified status
of `SessionLimit` or `Fault`. As a result, these exit codes should be
unused and reserved for future revision of the circuit. This PR
refactors the executor to reflect this and align with the fact that the
prover will never write these statuses to the seal.

Supersedes: risc0#1313
Resolves: risc0#1306

---------

Co-authored-by: Frank Laub <flaub@risc0.com>

* Add ProverServer::compress and use it to make receipts succinct by default (risc0#1325)

This PR adds a `ProverServer::compress` function that uses the `lift`,
`join`, and `resolve` recursion programs to compress a
`CompositeReceipt` into a `SuccinctReceipt`. This PR then uses this
function to compress receipts when `prove_session` is called, and
therefore compress receipts by default.

This PR also:
* Adds an `ExitCode::is_ok` function to clean up some code I saw along
the way to implementing this PR

---------

Co-authored-by: Frank Laub <flaub@risc0.com>

* only change the name

* Update smoke-test to latest API (risc0#1346)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Matheus Cardoso <45436839+Cardosaum@users.noreply.github.com>
Co-authored-by: Frank Laub <flaub@risc0.com>
Co-authored-by: Victor Graf <victor@risczero.com>
Co-authored-by: Tim Zerrell <tim.zerrell@risczero.com>
Co-authored-by: Angelo Capossele <angelocapossele@gmail.com>
Co-authored-by: Erik Kaneda <erik@risczero.com>
Co-authored-by: Rami Lukata <32602478+rlukata@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@flaub flaub added this to the 0.20.0 milestone Jan 23, 2024
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.

groth16 verify zkVM example
3 participants