Skip to content

Commit ef0fc3b

Browse files
authored
docs: official contracts (#1026)
2 parents 3f32657 + aaab5d4 commit ef0fc3b

File tree

8 files changed

+171
-77
lines changed

8 files changed

+171
-77
lines changed

book/SUMMARY.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@
3434

3535
- [Advanced](./generating-proofs/advanced.md)
3636

37+
# Onchain Verification
38+
39+
- [Getting Started](./onchain-verification/getting-started.md)
40+
41+
- [Solidity SDK](./onchain-verification/solidity-sdk.md)
42+
43+
- [Contract Addresses](./onchain-verification/contract-addresses.md)
44+
3745
# Prover Network
3846

3947
- [Setup](./prover-network/setup.md)
4048

4149
- [Usage](./prover-network/usage.md)
4250

43-
# Verifying Proofs
44-
45-
- [Solidity & EVM](./verifying-proofs/solidity-and-evm.md)
46-
4751
# Developers
4852

4953
- [Building Plonk Bn254 Artifacts](./developers/building-plonk-artifacts.md)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contract Addresses
2+
3+
When using SP1, we recommend using our deployed verifiers. Each contract is a [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol) which can automatically routes your SP1 proof to the correct verifier based on the prover version.
4+
5+
6+
| Chain ID | Chain | Gateway |
7+
|----------|------------------|---------------------------------------------------------------------------------------------------------------------------------|
8+
| 11155111 | Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
9+
| 17000 | Holesky | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://holesky.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
10+
| 42161 | Arbitrum One | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
11+
| 421614 | Arbitrum Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
12+
| 534351 | Scroll Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
13+
| 534352 | Scroll | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
14+
| 8453 | Base | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
15+
| 84532 | Base Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
16+
17+
**Currently officially supported versions of SP1 are v1.0.7 and v1.0.8.** If you'd like official support for a verifier on a different chain, please ask in the [SP1 Telegram](https://t.me/succinct_sp1).
18+
19+
## ISP1Verifier Interface
20+
21+
All verifiers implement the [ISP1Verifier](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1Verifier.sol) interface.
22+
23+
```c++
24+
// SPDX-License-Identifier: MIT
25+
pragma solidity ^0.8.20;
26+
27+
/// @title SP1 Verifier Interface
28+
/// @author Succinct Labs
29+
/// @notice This contract is the interface for the SP1 Verifier.
30+
interface ISP1Verifier {
31+
/// @notice Verifies a proof with given public values and vkey.
32+
/// @dev It is expected that the first 4 bytes of proofBytes must match the first 4 bytes of
33+
/// target verifier's VERIFIER_HASH.
34+
/// @param programVKey The verification key for the RISC-V program.
35+
/// @param publicValues The public values encoded as bytes.
36+
/// @param proofBytes The proof of the program execution the SP1 zkVM encoded as bytes.
37+
function verifyProof(
38+
bytes32 programVKey,
39+
bytes calldata publicValues,
40+
bytes calldata proofBytes
41+
) external view;
42+
}
43+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Onchain Verification
2+
3+
The best way to get started with verifying SP1 proofs on-chain is to refer to the [SP1 Project Template](https://github.com/succinctlabs/sp1-project-template/tree/main).
4+
5+
- The template [program](https://github.com/succinctlabs/sp1-project-template/blob/main/program/src/main.rs) shows how to write outputs that can be decoded in Solidity.
6+
- The template [script](https://github.com/succinctlabs/sp1-project-template/blob/main/script/src/bin/prove.rs) shows how to generate the proof using the SDK and save it to a file.
7+
- The template [contract](https://github.com/succinctlabs/sp1-project-template/blob/main/contracts/src/Fibonacci.sol) shows how to verify the proof onchain using Solidity.
8+
9+
Refer to the section on [Contract Addresses](./contract-addresses.md) for the addresses of the deployed verifiers.
10+
11+
## Generating SP1 Proof for Onchain Verification
12+
13+
By default, the proofs generated by SP1 are not verifiable onchain, as they are non-constant size and STARK verification on Ethereum is very expensive. To generate a proof that can be verified onchain, we use performant STARK recursion to combine SP1 shard proofs into a single STARK proof and then wrap that in a SNARK proof. Our `ProverClient` has a prover option for this called `plonk`. Behind the scenes, this function will first generate a normal SP1 proof, then recursively combine all of them into a single proof using the STARK recursion protocol. Finally, the proof is wrapped in a SNARK proof using PLONK.
14+
15+
> WARNING: The PLONK prover is only guaranteed to work on official releases of SP1. To use PLONK proving & verification locally, ensure that you have Docker installed.
16+
17+
### Example
18+
19+
```rust,noplayground
20+
{{#include ../../examples/fibonacci/script/bin/plonk_bn254.rs}}
21+
```
22+
23+
You can run the above script with `RUST_LOG=info cargo run --bin plonk_bn254 --release` in `examples/fibonacci/script`.
24+
25+
#### Using PLONK without Docker (Advanced)
26+
27+
If you would like to run the PLONK prover directly without Docker, you must have Go 1.22 installed and enable the `native-plonk` feature in `sp1-sdk`. This path is not recommended and may require additional native dependencies.
28+
29+
```toml
30+
sp1-sdk = { features = ["native-plonk"] }
31+
```
32+
33+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Solidity SDK
2+
3+
We maintain a suite of [contracts](https://github.com/succinctlabs/sp1-contracts/tree/main) used for verifying SP1 proofs onchain. We highly recommend using [Foundry](https://book.getfoundry.sh/).
4+
5+
## Installation
6+
7+
To install the latest release version:
8+
9+
```bash
10+
forge install succinctlabs/sp1-contracts
11+
```
12+
13+
To install a specific version:
14+
15+
```bash
16+
forge install succinctlabs/sp1-contracts@<version>
17+
```
18+
19+
Finally, add `@sp1-contracts/=lib/sp1-contracts/contracts/src/` in `remappings.txt.`
20+
21+
### Usage
22+
23+
Once installed, you can use the contracts in the library by importing them:
24+
25+
```c++
26+
// SPDX-License-Identifier: MIT
27+
pragma solidity ^0.8.20;
28+
29+
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol";
30+
31+
/// @title Fibonacci.
32+
/// @author Succinct Labs
33+
/// @notice This contract implements a simple example of verifying the proof of a computing a
34+
/// fibonacci number.
35+
contract Fibonacci {
36+
/// @notice The address of the SP1 verifier contract.
37+
/// @dev This can either be a specific SP1Verifier for a specific version, or the
38+
/// SP1VerifierGateway which can be used to verify proofs for any version of SP1.
39+
/// For the list of supported verifiers on each chain, see:
40+
/// https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments
41+
address public verifier;
42+
43+
/// @notice The verification key for the fibonacci program.
44+
bytes32 public fibonacciProgramVkey;
45+
46+
constructor(address _verifier, bytes32 _fibonacciProgramVkey) {
47+
verifier = _verifier;
48+
fibonacciProgramVkey = _fibonacciProgramVkey;
49+
}
50+
51+
/// @notice The entrypoint for verifying the proof of a fibonacci number.
52+
/// @param proof The encoded proof.
53+
/// @param publicValues The encoded public values.
54+
function verifyFibonacciProof(bytes calldata proof, bytes calldata publicValues)
55+
public
56+
view
57+
returns (uint32, uint32, uint32)
58+
{
59+
ISP1Verifier(verifier).verifyProof(fibonacciProgramVkey, publicValues, proof);
60+
(uint32 n, uint32 a, uint32 b) = abi.decode(publicValues, (uint32, uint32, uint32));
61+
return (n, a, b);
62+
}
63+
}
64+
```
65+
66+
For more details on the contracts, refer to the [sp1-contracts](https://github.com/succinctlabs/sp1-contracts) repo.
67+
68+
### Testing
69+
70+
To test the contract, we recommend setting up [Foundry Tests](https://book.getfoundry.sh/forge/tests). We have an example of such a test in the [SP1 Project Template](https://github.com/succinctlabs/sp1-project-template/blob/dev/contracts/test/Fibonacci.t.sol).

book/verifying-proofs/solidity-and-evm.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

core/src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl SP1PublicValues {
9191
}
9292
}
9393

94-
pub fn bytes(&self) -> String {
94+
pub fn raw(&self) -> String {
9595
format!("0x{}", hex::encode(self.buffer.data.clone()))
9696
}
9797

examples/fibonacci/script/bin/plonk_bn254.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ fn main() {
1616
// Generate the proof for the given program and input.
1717
let client = ProverClient::new();
1818
let (pk, vk) = client.setup(ELF);
19-
let mut proof = client.prove(&pk, stdin).plonk().run().unwrap();
19+
let proof = client.prove(&pk, stdin).plonk().run().unwrap();
2020

2121
println!("generated proof");
2222

23-
// Read and verify the output.
24-
let _ = proof.public_values.read::<u32>();
25-
let a = proof.public_values.read::<u32>();
26-
let b = proof.public_values.read::<u32>();
27-
println!("a: {}", a);
28-
println!("b: {}", b);
23+
// Get the public values as bytes.
24+
let public_values = proof.public_values.raw();
25+
println!("public values: {:?}", public_values);
26+
27+
// Get the proof as bytes.
28+
let solidity_proof = proof.raw();
29+
println!("proof: {:?}", solidity_proof);
2930

3031
// Verify proof and public values
3132
client.verify(&proof, &vk).expect("verification failed");

sdk/src/proof.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ impl SP1ProofWithPublicValues {
3939
bincode::deserialize_from(File::open(path).expect("failed to open file"))
4040
.map_err(Into::into)
4141
}
42+
43+
/// Returns the raw proof as a string.
44+
pub fn raw(&self) -> String {
45+
match &self.proof {
46+
SP1Proof::Plonk(plonk) => plonk.raw_proof.clone(),
47+
_ => unimplemented!(),
48+
}
49+
}
4250
}
4351

4452
pub type SP1CoreProofVerificationError = MachineVerificationError<CoreSC>;

0 commit comments

Comments
 (0)