This repository demonstrates how to implement and verify Merkle tree proofs using SP1 zero-knowledge proofs.
The project showcases:
- A guest program that verifies Merkle proofs inside the SP1 zkVM
- A host program that sets up inputs, generates proofs, and verifies them
sp1-merkle-proof/
├── guest-merkle-verifier/ # Guest program that runs in zkVM
│ ├── Cargo.toml
│ └── src/
│ └── main.rs # Merkle verification logic
├── host/ # Host program
│ ├── Cargo.toml
│ └── src/
│ └── main.rs # Proof generation and verification
└── Cargo.toml # Workspace configuration
- Install Rust (https://rustup.rs/)
- Install SP1:
curl -sSL https://sp1.succinct.xyz/install | bash
- Add SP1 to your PATH:
export PATH="$HOME/.sp1/bin:$PATH"
cargo prove build --release -p guest-merkle-verifier
This will compile the guest program and generate the ELF file required by the zkVM.
cargo run --release -p host
This will:
- Read the guest program ELF
- Set up the example Merkle proof inputs
- Generate a zero-knowledge proof
- Verify the proof
The guest program:
- Reads the Merkle root, leaf, and proof from the host
- Verifies the proof by recalculating the root hash
- Commits the result (true/false) back to the host
The host program:
- Sets up inputs (root, leaf, and proof)
- Passes them to the guest program
- Generates a zero-knowledge proof that the guest executed correctly
- Verifies the proof
- Extracts the result from the public values
To use your own Merkle tree:
- Modify the host program to use your own Merkle root, leaf, and proof
- The guest program should work with any valid Merkle proof using Keccak-256
- For larger Merkle trees, you may need to optimize the guest program
- SP1 provides precompiles for common cryptographic operations that can accelerate proof generation
- For production use, consider using the SP1 Prover Network instead of generating proofs locally