Skip to content

feltroidprime/sp1-starknet-template

Repository files navigation

SP1 Starknet Template

Build Status License: MIT

A complete template for building zero-knowledge applications on Starknet using SP1 zkVM

🔗 Based on the SP1 Project Template with Starknet-specific integration

This template demonstrates how to create an end-to-end SP1 project that generates proofs of RISC-V program execution and verifies them on Starknet. It includes a Fibonacci computation example with complete proof generation and on-chain verification.

🏗️ Architecture

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   SP1 Program   │───▶│  Proof Scripts  │───▶│ Starknet Verif. │
│   (Rust/RISC-V) │    │   (Groth16)     │    │   (Cairo)       │
└─────────────────┘    └─────────────────┘    └─────────────────┘
  • SP1 Program: Rust program that computes Fibonacci numbers in the zkVM
  • Proof Scripts: Generate and format proofs for Starknet verification (detailed docs)
  • Starknet Contract: Cairo smart contract that verifies SP1 proofs on-chain (detailed docs)

🚀 Quick Start

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/feltroidprime/sp1-starknet-template.git
    cd sp1-starknet-template
  2. Install SP1

    curl -L https://sp1.succinct.xyz | bash
    sp1up
  3. Install Starknet toolchain

    curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.sh | sh

📖 Usage

Quick Test Workflow

# 1. Test program execution (fast)
cd script && cargo run --release -- --execute --n 10

# 2. Extract verification key
cargo run --release --bin vkey

# 3. Update contract with your verification key (see contracts/README.md)

# 4. Generate Starknet proof
cargo run --release --bin starknet -- --system groth16 --n 10

# 5. Test on-chain verification
cd ../contracts && snforge test

For detailed usage instructions:

📁 Project Structure

├── program/              # SP1 program (Rust/RISC-V)
│   └── src/main.rs      # Fibonacci computation logic
├── script/              # Proof generation scripts
│   ├── README.md        # 📚 Detailed script documentation
│   └── src/bin/         # Proof generation binaries
├── contracts/           # Starknet smart contracts (Cairo)
│   ├── README.md        # 📚 Detailed contract documentation
│   ├── src/lib.cairo    # Main verification contract
│   └── tests/           # Contract tests
├── lib/                 # Shared library
│   └── src/lib.rs       # Common types and utilities
└── .github/workflows/   # CI/CD configuration

🧪 Example: Fibonacci Computation

This template includes a complete example that:

  1. Computes Fibonacci numbers in the SP1 zkVM
  2. Generates a zero-knowledge proof of the computation
  3. Verifies the proof on Starknet using a Cairo smart contract

The program takes an input n and computes the n-1th and nth Fibonacci numbers, proving the computation was done correctly without revealing the intermediate steps.

🌐 Production Deployment

Using the Prover Network

For production use or complex computations, use the Succinct Prover Network:

cp .env.example .env
# Edit .env with your network private key
SP1_PROVER=network NETWORK_PRIVATE_KEY=your_key cargo run --release --bin starknet

Hardware Requirements

Operation RAM Time Documentation
Execution 1GB Seconds script/README.md
Core Proof 4GB Minutes script/README.md
Groth16 Proof 16GB 10-30 min SP1 hardware requirements

🔍 Testing

Run the complete test suite:

# Test SP1 program execution
cd script && cargo run --release -- --execute

# Test proof generation  
cargo run --release -- --prove

# Test Starknet contract
cd ../contracts && snforge test

See component-specific testing documentation:

🆘 Troubleshooting

Common Issues

📚 Resources

🆘 Support

📄 License

This project is licensed under the MIT License - see the LICENSE-MIT file for details.


Built with ❤️ using SP1, Garaga and Starknet


Based on the SP1 Project Template by Succinct Labs • Starknet integration by feltroidprime

About

Brutally efficient SP1 proofs verification on Starknet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published