SP1 Prover Integration Guide
Overview
This guide explains how to implement the off-chain SP1 prover component for Gelap. The prover is responsible for generating zero-knowledge proofs that validate private state transitions.
Prerequisites
Rust (latest stable version)
SP1 SDK installed (
cargo install sp1-cli)Foundry for contract interaction
Understanding of Merkle trees and cryptographic commitments
SP1 Program Structure
The SP1 program (guest code) runs inside the zkVM and performs the heavy cryptographic computations.
Directory Structure
prover/
├── program/ # SP1 guest code (runs in zkVM)
│ ├── Cargo.toml
│ └── src/
│ └── main.rs # Main prover logic
├── script/ # Host code (orchestrates proving)
│ ├── Cargo.toml
│ └── src/
│ ├── main.rs # CLI interface
│ └── lib.rs # Prover utilities
└── Cargo.tomlGuest Program Implementation
Core Data Structures
Main Prover Logic
Host Program Implementation
Prover Service
CLI Interface
Building and Running
Build the SP1 Program
Run the Prover
Integration with Smart Contract
Submit Transaction
Performance Optimization
Caching Merkle Proofs
Maintain local database of tree state
Cache sibling paths for frequently used notes
Use incremental tree updates
Parallel Proof Generation
Generate proofs for multiple transactions in parallel
Use proof aggregation if supported by SP1
Hardware Acceleration
Use GPU acceleration for proof generation
Consider cloud-based proving services
Security Considerations
Input Validation
Validate all inputs before proof generation
Check note ownership
Verify balance sufficiency
Randomness
Use cryptographically secure randomness for blinding factors
Never reuse blinding factors
Key Management
Store secret keys securely
Use hardware wallets when possible
Implement key derivation (BIP-32/44)
Testing
Unit Tests
Integration Tests
Troubleshooting
Common Issues
Issue: Proof verification fails on-chain
Solution: Ensure ABI encoding matches exactly
Check that vKey is correct
Verify Merkle root computation matches contract
Issue: Slow proof generation
Solution: Use release builds (
--release)Enable hardware acceleration
Reduce circuit complexity
Issue: Merkle proof invalid
Solution: Verify tree state is synchronized
Check sibling hash computation
Ensure correct tree depth (32 levels)
Next Steps
Implement full Merkle tree synchronization
Add support for multiple token types
Implement encrypted memo decryption
Build wallet integration
Deploy prover as a service
Last updated