diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index 82449ca963..8d2529e8d8 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -12,114 +12,43 @@ on: - "book/**" merge_group: -jobs: - # test: - # runs-on: ubuntu-latest - # name: test - # timeout-minutes: 60 - - # steps: - # - uses: actions/checkout@v4 - - # - name: Install mdbook - # run: | - # mkdir mdbook - # curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook - # echo $(pwd)/mdbook >> $GITHUB_PATH - - # - name: Install mdbook-template - # run: | - # mkdir mdbook-template - # curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template - # echo $(pwd)/mdbook-template >> $GITHUB_PATH - - # - name: Run tests - # run: mdbook test - - lint: - runs-on: ubuntu-latest - name: lint - timeout-minutes: 60 - - steps: - - uses: actions/checkout@v4 - - - name: Install mdbook-linkcheck - run: | - mkdir mdbook-linkcheck - curl -sSL -o mdbook-linkcheck.zip https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip - unzip mdbook-linkcheck.zip -d ./mdbook-linkcheck - chmod +x $(pwd)/mdbook-linkcheck/mdbook-linkcheck - echo $(pwd)/mdbook-linkcheck >> $GITHUB_PATH - - - name: Run linkcheck - run: mdbook-linkcheck --standalone +defaults: + run: + working-directory: book +jobs: build: + name: Build Docusaurus runs-on: ubuntu-latest - timeout-minutes: 60 steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@nightly - - name: Install mdbook - run: | - mkdir mdbook - curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook - echo $(pwd)/mdbook >> $GITHUB_PATH - - - name: Install mdbook-template - run: | - mkdir mdbook-template - curl -sSL https://github.com/sgoudham/mdbook-template/releases/latest/download/mdbook-template-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook-template - echo $(pwd)/mdbook-template >> $GITHUB_PATH - - - uses: Swatinem/rust-cache@v2 with: - cache-on-failure: true - - - name: Build book - run: mdbook build + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: npm + cache-dependency-path: book/package-lock.json - # - name: Build docs - # run: cargo docs - # env: - # # Keep in sync with ./ci.yml:jobs.docs - # RUSTDOCFLAGS: - # --cfg docsrs --show-type-layout --generate-link-to-definition --enable-index-page - # -Zunstable-options + - name: Install dependencies + run: npm ci - # - name: Move docs to book folder - # run: | - # mv target/doc target/book/docs + - name: Create New Code Refrences + run: chmod +x gen-code-refs.sh && ./gen-code-refs.sh - - name: Archive artifact - shell: sh - run: | - chmod -c -R +rX "target/book" | - while read line; do - echo "::warning title=Invalid file permissions automatically fixed::$line" - done - tar \ - --dereference --hard-dereference \ - --directory "target/book" \ - -cvf "$RUNNER_TEMP/artifact.tar" \ - --exclude=.git \ - --exclude=.github \ - . + - name: Build website + run: npm run build - - name: Upload artifact - uses: actions/upload-artifact@v4 + - name: Upload Build Artifact + uses: actions/upload-pages-artifact@v3 with: - name: github-pages - path: ${{ runner.temp }}/artifact.tar - retention-days: 1 - if-no-files-found: error + path: book/build deploy: # Only deploy if a push to main if: github.ref_name == 'main' && github.event_name == 'push' runs-on: ubuntu-latest - needs: [lint, build] + needs: [build] # Grant GITHUB_TOKEN the permissions required to make a Pages deployment permissions: @@ -135,4 +64,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v4 \ No newline at end of file + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/test-book.yml b/.github/workflows/test-book.yml new file mode 100644 index 0000000000..c80530a72f --- /dev/null +++ b/.github/workflows/test-book.yml @@ -0,0 +1,30 @@ +name: Test deployment + +on: + pull_request: + branches: [main, dev] + +defaults: + run: + working-directory: book + +jobs: + test-deploy: + name: Test doc build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: npm + cache-dependency-path: book/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Test build website + run: npm run build diff --git a/book/docs/generating-proofs/prover-network/usage.md b/book/docs/generating-proofs/prover-network/usage.md index 3c87b9b38a..6a0db6fa1f 100644 --- a/book/docs/generating-proofs/prover-network/usage.md +++ b/book/docs/generating-proofs/prover-network/usage.md @@ -19,8 +19,8 @@ SP1_PROVER=network SP1_PRIVATE_KEY=... RUST_LOG=info cargo run --release - `SP1_PROVER` should be set to `network` when using the prover network. -- `SP1_PRIVATE_KEY` should be set to your [private key](../prover-network.md#key-setup). You will need - to be using a [whitelisted](../prover-network.md#get-access) key to use the network. +- `SP1_PRIVATE_KEY` should be set to your [private key](../prover-network#key-setup). You will need + to be using a [whitelisted](../prover-network#get-access) key to use the network. When you call any of the prove functions in ProverClient now, it will first simulate your program, then wait for it to be proven through the network and finally return the proof. diff --git a/book/docs/onchain-verification/contract-addresses.md b/book/docs/onchain-verification/contract-addresses.md deleted file mode 100644 index 3acb971edf..0000000000 --- a/book/docs/onchain-verification/contract-addresses.md +++ /dev/null @@ -1,80 +0,0 @@ -# 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 - -| 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; -} -``` diff --git a/book/docs/onchain-verification/getting-started.mdx b/book/docs/onchain-verification/getting-started.mdx deleted file mode 100644 index 3cbe73933a..0000000000 --- a/book/docs/onchain-verification/getting-started.mdx +++ /dev/null @@ -1,34 +0,0 @@ -import Example from "../../static/examples_fibonacci_script_bin_groth16_bn254.rs.mdx"; - - -# Onchain Verification: Setup - -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). - -- 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. -- 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. -- 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. - -Refer to the section on [Contract Addresses](./contract-addresses.md#contract-addresses) for the addresses of the deployed verifiers. - -## Generating SP1 Proofs for Onchain Verification - -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. - -> WARNING: The Groth16 and PLONK provers are only guaranteed to work on official releases of SP1. To -> use Groth16 or PLONK proving & verification locally, ensure that you have Docker installed and have -> at least 128GB of RAM. - -### Example - - - -You can run the above script with `RUST_LOG=info cargo run --bin groth16_bn254 --release` in `examples/fibonacci/script`. - -#### Using Groth16 and PLONK without Docker (Advanced) - -If you would like to run the Groth16 or PLONK prover directly without Docker, you must have Go 1.22 installed and enable the `native-gnark` feature in `sp1-sdk`. This path is not recommended and may require additional native dependencies. - -```toml -sp1-sdk = { version = "2.0.0", features = ["native-gnark"] } -``` diff --git a/book/docs/onchain-verification/solidity-sdk.md b/book/docs/onchain-verification/solidity-sdk.md deleted file mode 100644 index 822ab620b9..0000000000 --- a/book/docs/onchain-verification/solidity-sdk.md +++ /dev/null @@ -1,122 +0,0 @@ -# Solidity Verifier - -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/). - -## Installation - -To install the latest release version: - -```bash -forge install succinctlabs/sp1-contracts -``` - -To install a specific version: - -```bash -forge install succinctlabs/sp1-contracts@ -``` - -Finally, add `@sp1-contracts/=lib/sp1-contracts/contracts/src/` in `remappings.txt.` - -### Usage - -Once installed, you can use the contracts in the library by importing them: - -```c++ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol"; - -/// @title Fibonacci. -/// @author Succinct Labs -/// @notice This contract implements a simple example of verifying the proof of a computing a -/// fibonacci number. -contract Fibonacci { - /// @notice The address of the SP1 verifier contract. - /// @dev This can either be a specific SP1Verifier for a specific version, or the - /// SP1VerifierGateway which can be used to verify proofs for any version of SP1. - /// For the list of supported verifiers on each chain, see: - /// https://docs.succinct.xyz/onchain-verification/contract-addresses - address public verifier; - - /// @notice The verification key for the fibonacci program. - bytes32 public fibonacciProgramVKey; - - constructor(address _verifier, bytes32 _fibonacciProgramVKey) { - verifier = _verifier; - fibonacciProgramVKey = _fibonacciProgramVKey; - } - - /// @notice The entrypoint for verifying the proof of a fibonacci number. - /// @param _proofBytes The encoded proof. - /// @param _publicValues The encoded public values. - function verifyFibonacciProof(bytes calldata _publicValues, bytes calldata _proofBytes) - public - view - returns (uint32, uint32, uint32) - { - ISP1Verifier(verifier).verifyProof(fibonacciProgramVKey, _publicValues, _proofBytes); - (uint32 n, uint32 a, uint32 b) = abi.decode(_publicValues, (uint32, uint32, uint32)); - return (n, a, b); - } -} - -``` - -### Finding your program vkey - -The program vkey (`fibonacciProgramVKey` in the example above) is passed into the `ISP1Verifier` along with the public values and proof bytes. You -can find your program vkey by going through the following steps: - -1. Find what version of SP1 crates you are using. -2. Use the version from step to run this command: `sp1up --version ` -3. Use the vkey command to get the program vkey: `cargo prove vkey -elf ` - -Alternatively, you can set up a simple script to do this using the `sp1-sdk` crate: - -```rust -fn main() { - // Setup the logger. - sp1_sdk::utils::setup_logger(); - - // Setup the prover client. - let client = ProverClient::new(); - - // Setup the program. - let (_, vk) = client.setup(FIBONACCI_ELF); - - // Print the verification key. - println!("Program Verification Key: {}", vk.bytes32()); -} -``` - -### Testing - -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). - -### Solidity Versions - -The officially deployed contracts are built using Solidity 0.8.20 and exist on the -[sp1-contracts main](https://github.com/succinctlabs/sp1-contracts/tree/main) branch. - -If you need to use different versions that are compatible with your contracts, there are also other -branches you can install that contain different versions. For -example for branch [main-0.8.15](https://github.com/succinctlabs/sp1-contracts/tree/main-0.8.15) -contains the contracts with: - -```c++ -pragma solidity ^0.8.15; -``` - -and you can install it with: - -```sh -forge install succinctlabs/sp1-contracts@main-0.8.15 -``` - -If there is different versions that you need but there aren't branches for them yet, please ask in -the [SP1 Telegram](https://t.me/+AzG4ws-kD24yMGYx). diff --git a/book/docs/verification/off-chain-verification.md b/book/docs/verification/off-chain-verification.md index abd9981469..c862720962 100644 --- a/book/docs/verification/off-chain-verification.md +++ b/book/docs/verification/off-chain-verification.md @@ -38,7 +38,7 @@ Next, verify the proof with `sp1-verifier`. The following snippet is from the [G Here, the proof, public inputs, and vkey hash are read from stdin. See the following snippet to see how these values are generated. - + > Note that the SP1 SDK itself is *not* `no_std` compatible. diff --git a/book/docs/verification/onchain/getting-started.mdx b/book/docs/verification/onchain/getting-started.mdx index 45e5e95d9f..e102de657c 100644 --- a/book/docs/verification/onchain/getting-started.mdx +++ b/book/docs/verification/onchain/getting-started.mdx @@ -8,7 +8,7 @@ The best way to get started with verifying SP1 proofs on-chain is to refer to th - 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. - 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. -Refer to the section on [Contract Addresses](./contract-addresses.md#contract-addresses) for the addresses of the deployed verifiers. +Refer to the section on [Contract Addresses](./contract-addresses#contract-addresses) for the addresses of the deployed verifiers. ## Generating SP1 Proofs for Onchain Verification diff --git a/book/docusaurus.config.ts b/book/docusaurus.config.ts index 138a7891df..75522b54ed 100644 --- a/book/docusaurus.config.ts +++ b/book/docusaurus.config.ts @@ -19,9 +19,11 @@ const config: Config = { // If you aren't using GitHub pages, you don't need these. organizationName: 'succinctlabs', // Usually your GitHub org/user name. projectName: 'sp1', // Usually your repo name. + deploymentBranch: 'main', + trailingSlash: false, - onBrokenLinks: 'throw', - onBrokenMarkdownLinks: 'warn', + onBrokenLinks: 'warn', + onBrokenMarkdownLinks: 'throw', // Even if you don't use internationalization, you can use this field to set // useful metadata like html lang. For example, if your site is Chinese, you @@ -80,7 +82,7 @@ const config: Config = { items: [ { label: 'Home', - to: '/docs/summary', + to: '/', }, ], }, diff --git a/book/create-markdown-templates.sh b/book/gen-code-refs.sh similarity index 100% rename from book/create-markdown-templates.sh rename to book/gen-code-refs.sh diff --git a/book/versioned_docs/version-3.4.0/generating-proofs/prover-network/usage.md b/book/versioned_docs/version-3.4.0/generating-proofs/prover-network/usage.md index 3c87b9b38a..6a0db6fa1f 100644 --- a/book/versioned_docs/version-3.4.0/generating-proofs/prover-network/usage.md +++ b/book/versioned_docs/version-3.4.0/generating-proofs/prover-network/usage.md @@ -19,8 +19,8 @@ SP1_PROVER=network SP1_PRIVATE_KEY=... RUST_LOG=info cargo run --release - `SP1_PROVER` should be set to `network` when using the prover network. -- `SP1_PRIVATE_KEY` should be set to your [private key](../prover-network.md#key-setup). You will need - to be using a [whitelisted](../prover-network.md#get-access) key to use the network. +- `SP1_PRIVATE_KEY` should be set to your [private key](../prover-network#key-setup). You will need + to be using a [whitelisted](../prover-network#get-access) key to use the network. When you call any of the prove functions in ProverClient now, it will first simulate your program, then wait for it to be proven through the network and finally return the proof. diff --git a/book/versioned_docs/version-3.4.0/onchain-verification/contract-addresses.md b/book/versioned_docs/version-3.4.0/onchain-verification/contract-addresses.md deleted file mode 100644 index 3acb971edf..0000000000 --- a/book/versioned_docs/version-3.4.0/onchain-verification/contract-addresses.md +++ /dev/null @@ -1,80 +0,0 @@ -# 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 - -| 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; -} -``` diff --git a/book/versioned_docs/version-3.4.0/onchain-verification/getting-started.mdx b/book/versioned_docs/version-3.4.0/onchain-verification/getting-started.mdx deleted file mode 100644 index 6409876a00..0000000000 --- a/book/versioned_docs/version-3.4.0/onchain-verification/getting-started.mdx +++ /dev/null @@ -1,34 +0,0 @@ -import Example from "../../../static/examples_fibonacci_script_bin_groth16_bn254.rs.mdx"; - - -# Onchain Verification: Setup - -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). - -- 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. -- 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. -- 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. - -Refer to the section on [Contract Addresses](./contract-addresses.md#contract-addresses) for the addresses of the deployed verifiers. - -## Generating SP1 Proofs for Onchain Verification - -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. - -> WARNING: The Groth16 and PLONK provers are only guaranteed to work on official releases of SP1. To -> use Groth16 or PLONK proving & verification locally, ensure that you have Docker installed and have -> at least 128GB of RAM. - -### Example - - - -You can run the above script with `RUST_LOG=info cargo run --bin groth16_bn254 --release` in `examples/fibonacci/script`. - -#### Using Groth16 and PLONK without Docker (Advanced) - -If you would like to run the Groth16 or PLONK prover directly without Docker, you must have Go 1.22 installed and enable the `native-gnark` feature in `sp1-sdk`. This path is not recommended and may require additional native dependencies. - -```toml -sp1-sdk = { version = "2.0.0", features = ["native-gnark"] } -``` diff --git a/book/versioned_docs/version-3.4.0/onchain-verification/solidity-sdk.md b/book/versioned_docs/version-3.4.0/onchain-verification/solidity-sdk.md deleted file mode 100644 index 822ab620b9..0000000000 --- a/book/versioned_docs/version-3.4.0/onchain-verification/solidity-sdk.md +++ /dev/null @@ -1,122 +0,0 @@ -# Solidity Verifier - -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/). - -## Installation - -To install the latest release version: - -```bash -forge install succinctlabs/sp1-contracts -``` - -To install a specific version: - -```bash -forge install succinctlabs/sp1-contracts@ -``` - -Finally, add `@sp1-contracts/=lib/sp1-contracts/contracts/src/` in `remappings.txt.` - -### Usage - -Once installed, you can use the contracts in the library by importing them: - -```c++ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol"; - -/// @title Fibonacci. -/// @author Succinct Labs -/// @notice This contract implements a simple example of verifying the proof of a computing a -/// fibonacci number. -contract Fibonacci { - /// @notice The address of the SP1 verifier contract. - /// @dev This can either be a specific SP1Verifier for a specific version, or the - /// SP1VerifierGateway which can be used to verify proofs for any version of SP1. - /// For the list of supported verifiers on each chain, see: - /// https://docs.succinct.xyz/onchain-verification/contract-addresses - address public verifier; - - /// @notice The verification key for the fibonacci program. - bytes32 public fibonacciProgramVKey; - - constructor(address _verifier, bytes32 _fibonacciProgramVKey) { - verifier = _verifier; - fibonacciProgramVKey = _fibonacciProgramVKey; - } - - /// @notice The entrypoint for verifying the proof of a fibonacci number. - /// @param _proofBytes The encoded proof. - /// @param _publicValues The encoded public values. - function verifyFibonacciProof(bytes calldata _publicValues, bytes calldata _proofBytes) - public - view - returns (uint32, uint32, uint32) - { - ISP1Verifier(verifier).verifyProof(fibonacciProgramVKey, _publicValues, _proofBytes); - (uint32 n, uint32 a, uint32 b) = abi.decode(_publicValues, (uint32, uint32, uint32)); - return (n, a, b); - } -} - -``` - -### Finding your program vkey - -The program vkey (`fibonacciProgramVKey` in the example above) is passed into the `ISP1Verifier` along with the public values and proof bytes. You -can find your program vkey by going through the following steps: - -1. Find what version of SP1 crates you are using. -2. Use the version from step to run this command: `sp1up --version ` -3. Use the vkey command to get the program vkey: `cargo prove vkey -elf ` - -Alternatively, you can set up a simple script to do this using the `sp1-sdk` crate: - -```rust -fn main() { - // Setup the logger. - sp1_sdk::utils::setup_logger(); - - // Setup the prover client. - let client = ProverClient::new(); - - // Setup the program. - let (_, vk) = client.setup(FIBONACCI_ELF); - - // Print the verification key. - println!("Program Verification Key: {}", vk.bytes32()); -} -``` - -### Testing - -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). - -### Solidity Versions - -The officially deployed contracts are built using Solidity 0.8.20 and exist on the -[sp1-contracts main](https://github.com/succinctlabs/sp1-contracts/tree/main) branch. - -If you need to use different versions that are compatible with your contracts, there are also other -branches you can install that contain different versions. For -example for branch [main-0.8.15](https://github.com/succinctlabs/sp1-contracts/tree/main-0.8.15) -contains the contracts with: - -```c++ -pragma solidity ^0.8.15; -``` - -and you can install it with: - -```sh -forge install succinctlabs/sp1-contracts@main-0.8.15 -``` - -If there is different versions that you need but there aren't branches for them yet, please ask in -the [SP1 Telegram](https://t.me/+AzG4ws-kD24yMGYx). diff --git a/book/versioned_docs/version-3.4.0/verification/off-chain-verification.md b/book/versioned_docs/version-3.4.0/verification/off-chain-verification.md index dff3ee960a..6d218c49bb 100644 --- a/book/versioned_docs/version-3.4.0/verification/off-chain-verification.md +++ b/book/versioned_docs/version-3.4.0/verification/off-chain-verification.md @@ -38,7 +38,7 @@ Next, verify the proof with `sp1-verifier`. The following snippet is from the [G Here, the proof, public inputs, and vkey hash are read from stdin. See the following snippet to see how these values are generated. - + > Note that the SP1 SDK itself is *not* `no_std` compatible. diff --git a/book/versioned_docs/version-3.4.0/verification/onchain/getting-started.mdx b/book/versioned_docs/version-3.4.0/verification/onchain/getting-started.mdx index 279d91a8bc..ad4087c9d1 100644 --- a/book/versioned_docs/version-3.4.0/verification/onchain/getting-started.mdx +++ b/book/versioned_docs/version-3.4.0/verification/onchain/getting-started.mdx @@ -8,7 +8,7 @@ The best way to get started with verifying SP1 proofs on-chain is to refer to th - 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. - 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. -Refer to the section on [Contract Addresses](./contract-addresses.md#contract-addresses) for the addresses of the deployed verifiers. +Refer to the section on [Contract Addresses](./contract-addresses#contract-addresses) for the addresses of the deployed verifiers. ## Generating SP1 Proofs for Onchain Verification