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.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ 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)
- Rust (latest stable)
- SP1 Toolchain
- Starknet Toolchain (Scarb + Starknet Foundry)
-
Clone the repository
git clone https://github.com/feltroidprime/sp1-starknet-template.git cd sp1-starknet-template -
Install SP1
curl -L https://sp1.succinct.xyz | bash sp1up -
Install Starknet toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.sh | sh
# 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 testFor detailed usage instructions:
- Proof Generation: See script/README.md
- Contract Integration: See contracts/README.md
├── 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
This template includes a complete example that:
- Computes Fibonacci numbers in the SP1 zkVM
- Generates a zero-knowledge proof of the computation
- 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.
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| 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 |
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 testSee component-specific testing documentation:
- "failed to generate proof": Check script debugging guide
- "Wrong program" error: See contract configuration
- Hardware requirements: Check performance considerations
- SP1 Issues: SP1 GitHub Issues
- Template Issues: Create an issue
- Garaga Support: Garaga Support
- Starknet Support: Starknet Support
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