Skip to main content

Solidity Verifier

We maintain a suite of contracts used for verifying SP1 proofs onchain. We highly recommend using Foundry.

Installation

To install the latest release version:

forge install succinctlabs/sp1-contracts

To install a specific version:

forge install succinctlabs/sp1-contracts@<version>

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:

The recommended on-chain SP1 proof verification workflow is to use the ISP1Verifier interface on the SP1VerifierGateway, so the SP1VerifierGateway automatically routes your proof to the correct verifier.

Your program’s verification key should be upgradeable within your contract, in case you want to upgrade to a newer version of SP1 or modify your program.

Succinct maintains the ability to freeze verifiers on the canonical verifier gateway in the event of a security issue to prevent abuse. Note that verifier contract deployment is permissionless to enable customizable security configurations.

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 <version>
  3. Use the vkey command to get the program vkey: cargo prove vkey -elf <path/to/elf>

Alternatively, you can set up a simple script to do this using the sp1-sdk crate:

fn main() {
// Setup the logger.
sp1_sdk::utils::setup_logger();

// Setup the prover client.
let client = ProverClient::from_env();

// 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. We have an example of such a test in the SP1 Project Template.

Solidity Versions

The officially deployed contracts are built using Solidity 0.8.20 and exist on the sp1-contracts 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 contains the contracts with:

pragma solidity ^0.8.15;

and you can install it with:

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.