Overview
Thelight-verifier crate provides ZK proof verification for Light Protocol. It verifies Groth16 proofs for inclusion, non-inclusion (address creation), and combined operations using the groth16-solana library.
Crate: light-verifierLocation:
program-libs/verifier/Error Codes: 13001-13007
Proof System: Groth16 over BN254
Key Features
Inclusion Proofs
Verify 1-20 compressed accounts exist in Merkle trees
Non-Inclusion Proofs
Verify 1-32 addresses don’t exist (for creation)
Combined Proofs
Single proof for both inclusion and address creation
Batch Updates
Verify batched tree updates (10, 250, 500 leaves)
Proof Types
Inclusion Proofs
Verify compressed accounts exist in state trees:- V1: 1, 2, 3, 4, 8 accounts
- V2: 1-20 accounts
Non-Inclusion Proofs
Verify addresses don’t exist in address trees (for creation):- V1: 1, 2, 3, 4, 8 addresses
- V2: 1-32 addresses
Combined Proofs
Single proof for both operations:- V1: Various combinations up to 4 accounts + 4 addresses
- V2: Various combinations up to 4 accounts + 4 addresses
Batch Update Proofs
Verify batched tree updates:verify_batch_append_with_proofs
verify_batch_append_with_proofs
Verify batch append to state tree output queue.Batch sizes: 10, 500Public input hash: H(old_root, new_root, hash_chain, start_index)
verify_batch_update
verify_batch_update
Verify batch nullifier updates (state tree input queue).Batch sizes: 10, 500Public input hash: H(old_root, new_root, hash_chain)
verify_batch_address_update
verify_batch_address_update
Verify batch address updates (address tree).Batch sizes: 10, 250Public input hash: H(old_root, new_root, hash_chain, next_index)
CompressedProof
Groth16 proof structure (128 bytes total):a: Compressed G1 point on BN254 (32 bytes)b: Compressed G2 point on BN254 (64 bytes)c: Compressed G1 point on BN254 (32 bytes)
Verifying Keys
Key Selection
Different verifying keys for different proof types:Naming Convention
Verifying key modules follow this pattern:-
V1 Inclusion:
v1_inclusion_<height>_<count>- Example:
v1_inclusion_26_4(height 26, 4 accounts)
- Example:
-
V1 Non-Inclusion:
v1_non_inclusion_<height>_<count>- Example:
v1_non_inclusion_26_2(height 26, 2 addresses)
- Example:
-
V1 Combined:
v1_combined_<state_height>_<addr_height>_<state_count>_<addr_count>- Example:
v1_combined_26_26_2_1(2 accounts, 1 address)
- Example:
-
V2 Inclusion:
v2_inclusion_<height>_<count>- Example:
v2_inclusion_32_10(height 32, 10 accounts)
- Example:
-
V2 Non-Inclusion:
v2_non_inclusion_<height>_<count>- Example:
v2_non_inclusion_40_5(height 40, 5 addresses)
- Example:
-
V2 Combined:
v2_combined_<state_height>_<addr_height>_<state_count>_<addr_count>- Example:
v2_combined_32_40_3_2(3 accounts, 2 addresses)
- Example:
-
Batch Operations:
batch_append_<height>_<batch_size>: Batch append proofsbatch_update_<height>_<batch_size>: Batch nullify proofsbatch_address_append_<height>_<batch_size>: Batch address proofs
Tree Heights
V1 Trees: Height 26 (67M leaves) V2 Trees:- State trees: Heights 26, 30, 32, 40
- Address trees: Heights 26, 30, 32, 40
Error Codes
| Code | Error | Description |
|---|---|---|
| 13001 | PublicInputsTryIntoFailed | Failed to convert public inputs to array |
| 13002 | DecompressG1Failed | Failed to decompress G1 point |
| 13003 | DecompressG2Failed | Failed to decompress G2 point |
| 13004 | InvalidPublicInputsLength | Public inputs count doesn’t match proof type |
| 13005 | CreateGroth16VerifierFailed | Failed to create verifier |
| 13006 | ProofVerificationFailed | Proof verification failed |
| 13007 | InvalidBatchSize | Unsupported batch size (must be 10, 250, or 500) |
Usage Examples
Basic Inclusion Proof
Create New Addresses
Combined Operation
Batch Tree Update
Verification Flow
On-Chain Verification Steps
Public Inputs
Inclusion proof:public_input_hash = H(old_root, new_root, hash_chain, [optional_index])
Performance
Compute Units
Approximate CU costs:| Proof Type | Accounts/Addresses | CU Cost |
|---|---|---|
| Inclusion | 1 | ~90,000 |
| Inclusion | 4 | ~92,000 |
| Inclusion | 8 | ~95,000 |
| Non-Inclusion | 1 | ~90,000 |
| Non-Inclusion | 4 | ~92,000 |
| Combined | 2 + 2 | ~95,000 |
| Batch (10) | - | ~95,000 |
| Batch (500) | - | ~95,000 |
Optimization Tips
Batch Operations
Batch Operations
Combine multiple account operations into a single proof when possible. Combined proofs are more efficient than separate inclusion + non-inclusion proofs.
Reuse Proofs
Reuse Proofs
Proofs are tied to specific roots. If the tree hasn’t changed, the same proof can be reused (though this is rare in practice).
Request Compact Keys
Request Compact Keys
Use the minimum required key size. Don’t request a proof for 8 accounts if you only need 2.
Circuit Details
Inclusion Circuit
Proves: Account hash is a leaf in the Merkle tree with given root Private inputs:- Merkle proof (path from leaf to root)
- Path indices (left/right at each level)
- Root
- Leaf (account hash)
Non-Inclusion Circuit
Proves: Address doesn’t exist in indexed Merkle tree Private inputs:- Low leaf (closest existing address < new address)
- Merkle proof for low leaf
- Next leaf (closest existing address > new address)
- Proof that new address is between low and next
- Root
- New address
Batch Append Circuit
Proves: Correct insertion of batch of leaves Private inputs:- All leaves in batch
- Merkle proofs for insertions
- Old root
- New root
- Hash chain (commitment to leaves)
- Start index
Testing
Best Practices
Always Verify Proofs
Always Verify Proofs
Never skip proof verification, even in development. Invalid proofs indicate serious issues.
Use Fresh Roots
Use Fresh Roots
Proofs are tied to specific Merkle roots. Always use recent roots from current slot.
Handle Verification Errors
Handle Verification Errors
Proof verification failures should halt execution. Don’t continue with state changes.
Request Minimal Proofs
Request Minimal Proofs
Only request proofs for the exact number of accounts/addresses needed. Larger proofs waste resources.
Feature Flags
Enables Solana SDK integration and error conversions
Enables Pinocchio SDK integration
Resources
Source Code
View on GitHub
API Docs
Rust documentation
Groth16 Paper
Original Groth16 paper
Prover Service
ZK proof generation service