-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
8,170 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Offchain Verification | ||
|
||
## Rust `no_std` Verification | ||
|
||
You can verify SP1 Groth16 and Plonk proofs in `no_std` environments with [`sp1-verifier`](https://docs.rs/sp1-verifier/latest/sp1_verifier/). | ||
|
||
`sp1-verifier` is also patched to verify Groth16 and Plonk proofs within the SP1 ZKVM, using | ||
[bn254](https://blog.succinct.xyz/succinctshipsprecompiles/) precompiles. For an example of this, see | ||
the [Groth16 Example](https://github.com/succinctlabs/sp1/tree/main/examples/groth16/). | ||
|
||
### Installation | ||
|
||
Import the following dependency in your `Cargo.toml`: | ||
|
||
```toml | ||
sp1-verifier = {version = "3.0.0", default-features = false} | ||
``` | ||
|
||
### Usage | ||
|
||
`sp1-verifier`'s interface is very similar to the solidity verifier's. It exposes two public functions: | ||
[`Groth16Verifier::verify_proof`](https://docs.rs/sp1-verifier/latest/src/sp1_verifier/groth16.rs.html) | ||
and [`PlonkVerifier::verify_proof`](https://docs.rs/sp1-verifier/latest/src/sp1_verifier/plonk.rs.html). | ||
|
||
`sp1-verifier` also exposes the Groth16 and Plonk verifying keys as constants, `GROTH16_VK_BYTES` and `PLONK_VK_BYTES`. These | ||
keys correspond to the current SP1 version's official Groth16 and Plonk verifying keys, which are used for verifying proofs generated | ||
using docker or the prover network. | ||
|
||
First, generate your groth16/plonk proof with the SP1 SDK. See [here](./onchain/getting-started.md#generating-sp1-proofs-for-onchain-verification) | ||
for more information -- `sp1-verifier` and the solidity verifier expect inputs in the same format. | ||
|
||
Next, verify the proof with `sp1-verifier`. The following snippet is from the [Groth16 example program](https://github.com/succinctlabs/sp1/tree/dev/examples/groth16/), which verifies a Groth16 proof within SP1 using `sp1-verifier`. | ||
|
||
```rust,noplayground | ||
{{#include ../../examples/groth16/program/src/main.rs}} | ||
``` | ||
|
||
Here, the proof, public inputs, and vkey hash are read from stdin. See the following snippet to see how these values are generated. | ||
|
||
```rust,noplayground | ||
{{#include ../../examples/groth16/script/src/main.rs:12:34}} | ||
``` | ||
|
||
> Note that the SP1 SDK itself is *not* `no_std` compatible. | ||
## Wasm Verification | ||
|
||
The [`example-sp1-wasm-verifier`](https://github.com/succinctlabs/example-sp1-wasm-verifier) demonstrates how to | ||
verify SP1 proofs in wasm. For a more detailed explanation of the process, please see the [README](https://github.com/succinctlabs/example-sp1-wasm-verifier/blob/main/README.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Contract Addresses | ||
|
||
To verify SP1 proofs on-chain, we recommend using our deployed canonical verifier gateways. The | ||
[SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol) | ||
will automatically route your SP1 proof to the correct verifier based on the SP1 version used. | ||
|
||
## Canonical Verifier Gateways | ||
|
||
There are different verifier gateway for each proof system: Groth16 and PLONK. This means that you | ||
must use the correct verifier gateway depending on if you are verifying a Groth16 or PLONK proof. | ||
|
||
### Groth16 | ||
|
||
| Chain ID | Chain | Gateway | | ||
| -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 1 | Mainnet | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://etherscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 11155111 | Sepolia | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://sepolia.etherscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 17000 | Holesky | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://holesky.etherscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 42161 | Arbitrum One | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://arbiscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 421614 | Arbitrum Sepolia | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://sepolia.arbiscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 8453 | Base | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://basescan.org/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 84532 | Base Sepolia | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://sepolia.basescan.org/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 10 | Optimism | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://optimistic.etherscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 11155420 | Optimism Sepolia | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://sepolia-optimism.etherscan.io/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 534351 | Scroll Sepolia | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://sepolia.scrollscan.com/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
| 534352 | Scroll | [0x397A5f7f3dBd538f23DE225B51f532c34448dA9B](https://scrollscan.com/address/0x397A5f7f3dBd538f23DE225B51f532c34448dA9B) | | ||
|
||
### PLONK | ||
|
||
| Chain ID | Chain | Gateway | | ||
| -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 1 | Mainnet | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 11155111 | Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 17000 | Holesky | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://holesky.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 42161 | Arbitrum One | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 421614 | Arbitrum Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 8453 | Base | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 84532 | Base Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 10 | Optimism | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://optimistic.etherscan.io/address/0x3b6041173b80e77f038f3f2c0f9744f04837185e) | | ||
| 11155420 | Optimism Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia-optimism.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 534351 | Scroll Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
| 534352 | Scroll | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) | | ||
|
||
The most up-to-date reference on each chain can be found in the | ||
[deployments](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/deployments) | ||
directory in the | ||
SP1 contracts repository, where each chain has a dedicated JSON file with each verifier's address. | ||
|
||
## Versioning Policy | ||
|
||
Whenever a verifier for a new SP1 version is deployed, the gateway contract will be updated to | ||
support it with | ||
[addRoute()](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol#L65). | ||
If a verifier for an SP1 version has an issue, the route will be frozen with | ||
[freezeRoute()](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol#L71). | ||
|
||
On mainnets, only official versioned releases are deployed and added to the gateway. Testnets have | ||
`rc` versions of the verifier deployed supported in addition to the official versions. | ||
|
||
## Deploying to other Chains | ||
|
||
In the case that you need to use a chain that is not listed above, you can deploy your own | ||
verifier contract by following the instructions in the | ||
[SP1 Contracts Repo](https://github.com/succinctlabs/sp1-contracts/blob/main/README.md#deployments). | ||
|
||
Since both the `SP1VerifierGateway` and each `SP1Verifier` implement the [ISP1Verifier | ||
interface](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1Verifier.sol), you can choose to either: | ||
|
||
* Deploy the `SP1VerifierGateway` and add `SP1Verifier` contracts to it. Then point to the | ||
`SP1VerifierGateway` address in your contracts. | ||
* Deploy just the `SP1Verifier` contract that you want to use. Then point to the `SP1Verifier` | ||
address in | ||
your contracts. | ||
|
||
If you want support for a canonical verifier on your chain, contact us [here](https://t.me/+AzG4ws-kD24yMGYx). We often deploy canonical verifiers on new chains if there's enough demand. | ||
|
||
## ISP1Verifier Interface | ||
|
||
All verifiers implement the [ISP1Verifier](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1Verifier.sol) interface. | ||
|
||
```c++ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
/// @title SP1 Verifier Interface | ||
/// @author Succinct Labs | ||
/// @notice This contract is the interface for the SP1 Verifier. | ||
interface ISP1Verifier { | ||
/// @notice Verifies a proof with given public values and vkey. | ||
/// @dev It is expected that the first 4 bytes of proofBytes must match the first 4 bytes of | ||
/// target verifier's VERIFIER_HASH. | ||
/// @param programVKey The verification key for the RISC-V program. | ||
/// @param publicValues The public values encoded as bytes. | ||
/// @param proofBytes The proof of the program execution the SP1 zkVM encoded as bytes. | ||
function verifyProof( | ||
bytes32 programVKey, | ||
bytes calldata publicValues, | ||
bytes calldata proofBytes | ||
) external view; | ||
} | ||
``` |
Oops, something went wrong.