This is a template for creating an end-to-end SP1 project that can generate a proof of any RISC-V program.
Use the Makefile
to run the following commands from the root directory of the project:
# runs tests on the merkle tree lib
make test-merkle-tree-lib
# builds the main program (creates and sets `SP1_ELF_merkle-tree-program`)
make build-program
# runs the main program with dummy data
make run-program
### these output fixtures for evm-compatible proofs into
### the ~/contracts/fixtures directory upon succesfully completing
#
# generates a core proof (more time-consuming) for groth16 + you need Docker running
make execute-program-gen-core-proof-groth16
# generates a core proof (more time-consuming) for plonk + you need Docker running
make execute-program-gen-core-proof-plonk
There are four main ways to run this project: build a program, execute a program, generate a core proof, and generate an EVM-compatible proof.
To build the program, run the following command:
cd program
cargo prove build
To run the program without generating a proof:
cd script
cargo run --release -- --execute
This will execute the program and display the output.
To generate a core proof for your program:
cd script
cargo run --release -- --prove
Warning
You will need at least 128GB RAM to generate a Groth16 or PLONK proof.
To generate a proof that is small enough to be verified on-chain and verifiable by the EVM:
cd script
cargo run --release --bin evm -- --system groth16
this will generate a Groth16 proof. If you want to generate a PLONK proof, run the following command:
cargo run --release --bin evm -- --system plonk
These commands will also generate fixtures that can be used to test the verification of SP1 zkVM proofs inside Solidity.
To retrieve your programVKey
for your on-chain contract, run the following command:
cargo prove vkey --program fibonacci-program
We highly recommend using the Succinct prover network for any non-trivial programs or benchmarking purposes. For more information, see the setup guide. this setup guide.
To get started, copy the example environment file:
cp .env.example .env
Then, set the SP1_PROVER
environment variable to network
and set the SP1_PRIVATE_KEY
environment variable to your whitelisted private key.
For example, to generate an EVM-compatible proof using the prover network, run the following command:
SP1_PROVER=network SP1_PRIVATE_KEY=... cargo run --release --bin evm
- If you are running this on MacOS M1 aarch64, don't use
zsh
as your shell. Usebash
instead;zsh
throws unintelligible errors.
- Right now
~/lib
contains the old fibonacci program./~lib3
is the current refactoring effort to make this work for Merkle Trees. - There are some
.expect()
and.unwrap()
calls in the code that should be handled more gracefully (marked with// todo ...
s). - The
evm.rs
file should be generating fixtures for the EVM-compatible proof (output in~/contracts/fixtures
), but I think my computer is running out of memory to do so; everything code-wise seems correct. - To deploy on their Prover Network you need to sign up for beta access! So, it could be worth signing up for that in case it takes a while. They claim this network is the best way to generate proofs for large, complex programs.