Skip to content

zk-examples/sp1-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SP1 Groth16 examples

This repository runs three SP1 programs and produces native SP1 Groth16 proofs. It does not convert proofs to snarkjs.

Prerequisites

Run the repository from an Ubuntu or WSL ext4 filesystem with:

  • Rust and Cargo;
  • the SP1 CLI and cargo-prove, pinned to SP1 6.3.1;
  • Go;
  • Clang;
  • the Protobuf compiler (protoc).

The tested WSL configuration used 14 processors, 30 GB memory, and 16 GB swap.

Circuit cache

SP1 expects the Groth16 v6.1.0 circuit files under:

~/.sp1/circuits/groth16/v6.1.0

Populate the cache once with the resumable download:

(
  set -euo pipefail
  circuit_dir="$HOME/.sp1/circuits/groth16/v6.1.0"
  archive="$circuit_dir/artifacts.tar.gz"
  mkdir -p "$circuit_dir"
  curl --fail --location --continue-at - --retry 5 \
    --output "$archive" \
    "https://sp1-circuits.s3-us-east-2.amazonaws.com/v6.1.0-groth16.tar.gz"
  test "$(stat -c %s "$archive")" = "6211807514"
  tar -Pxzf "$archive" -C "$circuit_dir"
  rm -- "$archive"
)

The expected archive size is 6211807514 bytes.

Run

Run all checks, execute all guests, and prove all three cases:

./scripts/prove.sh

Execute the guests without proving:

cargo run --release --locked -p sp1-examples -- --execute-only

Prove cases individually:

cargo run --release --locked -p sp1-examples -- --case arithmetic
cargo run --release --locked -p sp1-examples -- --case fibonacci
cargo run --release --locked -p sp1-examples -- --case sha256

Proofs are written to:

artifacts/arithmetic/proof.bin
artifacts/fibonacci/proof.bin
artifacts/sha256/proof.bin

These verified proof files are included in the repository and are reused on subsequent runs.

Each output must be non-empty. A retained proof is loaded, its public values are checked, and it is natively verified by SP1 before the host reports PROOF_REUSED.

To hand the proofs to the converter, run this from the converter repository:

./scripts/import-examples.sh ../sp1-examples

About

A collection of educational examples demonstrating zero-knowledge proof implementations using SP1.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages