This document provides a high-level introduction to the Light Protocol codebase, explaining its architecture, core components, and how they interact to implement zero-knowledge compression on Solana. Light Protocol enables developers to create rent-free accounts and tokens by storing account state in compressed form using Merkle trees and zero-knowledge proofs.
For detailed information about specific subsystems, see:
Sources: README.md1-15 Cargo.toml1-96
Light Protocol is a ZK compression layer that reduces storage costs on Solana by up to 5,000x while maintaining security, composability, and performance. Instead of storing full account data on-chain, Light Protocol stores a commitment (hash) of the account in a Merkle tree. The actual account data lives off-chain in an indexer, and zero-knowledge proofs verify state transitions without exposing the full state.
The protocol consists of four deployed Solana programs with their program IDs:
compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq) - Manages Merkle trees and state commitmentsSySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7) - Handles compressed account lifecyclecTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m) - Implements compressed SPL tokensLighton6oQpVkeewmo2mcPTQQp7kYHr4fWpAgJyEmDX) - Manages program registration and forester coordinationSources: README.md10-15 README.md47-63
A compressed account is represented by the CompressedAccount type defined in the light-compressed-account crate. Instead of storing the full account data on-chain, only its hash is inserted into a Merkle tree. The CompressedAccount contains:
owner: The program that owns this accountlamports: SOL balanceaddress: Optional deterministic addressdata: Optional serialized account dataThe compressed account's hash becomes a leaf in a state Merkle tree managed by the account-compression program.
Sources: Cargo.toml216 [program-libs/compressed-account directory]
Light Protocol uses two types of Merkle trees:
StateMerkleTreeAccount): Store hashes of compressed accounts. Implemented using ConcurrentMerkleTree (V1) or BatchedMerkleTree (V2).AddressMerkleTreeAccount): Store indexed addresses for deterministic account derivation. Implemented using IndexedMerkleTree (V1) or batched variants (V2).Trees are managed through accounts in the account-compression program and have associated metadata in MerkleTreeMetadata.
Sources: [program-libs/concurrent-merkle-tree directory], [program-libs/indexed-merkle-tree directory], [program-libs/batched-merkle-tree directory]
State transitions (creating, updating, nullifying compressed accounts) require ZK proofs to verify:
Proofs are generated off-chain by the Light Prover service using Groth16 circuits implemented in gnark. The light-verifier library verifies proofs on-chain in Solana programs.
Sources: [program-libs/verifier directory], prover/client/Cargo.toml1-8
High-level architecture showing major system components and their relationships
Sources: Cargo.toml1-296 README.md1-206
The Light Protocol repository is organized as a Rust and JavaScript monorepo with the following top-level structure:
The workspace is defined in Cargo.toml1-296 with these member categories:
On-Chain Programs (programs/ and anchor-programs/):
account-compression - Merkle tree managementsystem - Compressed account state transitionscompressed-token/program - Compressed token implementationregistry - Program and forester registrationProgram Libraries (program-libs/):
compressed-account - Core CompressedAccount typehasher - Hasher trait and implementations (Poseidon, Keccak, SHA256)verifier - On-chain ZK proof verificationconcurrent-merkle-tree, indexed-merkle-tree, batched-merkle-tree - Tree implementationszero-copy - Zero-copy deserialization utilitiesmerkle-tree-metadata - Tree configuration and lifecycleSDK Libraries (sdk-libs/):
client - LightClient RPC interfacesdk - High-level SDK for building programs with light-sdksdk-pinocchio - Pinocchio-compatible SDKtoken-sdk - Token operations with light-tokenprogram-test - LightProgramTest testing frameworkphoton-api - Client for Photon indexerOff-Chain Services:
forester - Automated tree management serviceprover/client - light-prover-client for proof generationSources: Cargo.toml1-82
The JavaScript ecosystem lives in the js/ directory as a pnpm monorepo:
@lightprotocol/stateless.js - Core TypeScript SDK@lightprotocol/compressed-token - Token SDK@lightprotocol/zk-compression-cli - Command-line toolsSources: README.md195-202
Transaction flow showing interaction between client, off-chain services, and on-chain programs
Sources: [sdk-libs/client directory], [programs/system directory], [programs/account-compression directory]
The account-compression program defines instructions in programs/account-compression/src/lib.rs:
initialize_address_merkle_tree - Creates a new address treeinitialize_state_merkle_tree - Creates a new state treeappend_leaves - Adds leaves to a state treenullify_leaves - Marks leaves as spentupdate_address_merkle_tree - Updates address tree with new addressesThe light-system-program (Anchor) defines instructions in anchor-programs/system/src/lib.rs:
invoke - Processes compressed account state transitions with ZK proofsinvoke_cpi - Handles cross-program invocations with compressed accountsSources: [programs/account-compression directory], [anchor-programs/system directory]
CompressedAccount ([program-libs/compressed-account directory]):
InstructionDataInvoke ([sdk-libs/sdk-types directory]):
Contains the data passed to light-system-program::invoke:
proof: Compressed ZK proofinput_compressed_accounts_with_merkle_context: Accounts being read/nullifiedoutput_compressed_accounts: New accounts being createdrelay_fee: Optional fee for transaction relayingMerkleTreeMetadata ([program-libs/merkle-tree-metadata directory]): Tracks tree configuration and rollover state:
next_merkle_tree: Pubkey of next tree in rollover chainrollover_metadata: Configuration for automatic rolloverSources: [program-libs/compressed-account directory], [sdk-libs/sdk-types directory], [program-libs/merkle-tree-metadata directory]
LightClient (sdk-libs/client/src/rpc/rpc_connection.rs):
new() - Creates client with RPC and indexer endpointscreate_and_send_transaction() - Builds and sends compressed account transactionsget_compressed_accounts_by_owner() - Queries accounts via indexerLightProgramTest (sdk-libs/program-test/src/lib.rs):
new() - Starts local test validator with mock indexerprocess_transaction() - Processes test transactionsget_compressed_accounts() - Queries mock indexer stateSources: sdk-libs/client/Cargo.toml1-81 sdk-libs/program-test/Cargo.toml1-72
The light-program-test crate provides LightProgramTest for local development:
Local testing infrastructure components
The test framework:
litesvm as an in-memory Solana validatorTestRpc as a mock Photon indexerlight-prover-client to generate proofs locallySources: [sdk-libs/program-test directory], README.md176-191
The repository provides shell scripts for development:
./scripts/install.sh - Installs dependencies to .local/ directory./scripts/devenv.sh - Activates development environment./scripts/build.sh - Builds all Rust and JavaScript code./scripts/test.sh - Runs full test suiteProgram tests use cargo test-sbf:
Sources: README.md95-191
The Photon indexer (maintained by Helius) tracks compressed account state by:
account-compression and light-system-programClient code interacts with Photon through the photon-api crate, which provides a generated client from the OpenAPI spec.
Sources: sdk-libs/photon-api/Cargo.toml1-35 README.md17
The Light Prover generates zero-knowledge proofs using gnark circuits. The light-prover-client crate provides:
prove_inclusion() - Generates inclusion proofs for compressed accountsprove_batch() - Generates batch proofs for multiple operationsProofs use the Groth16 proving system with BN254 curve.
Sources: prover/client/Cargo.toml1-45
The Forester automates V2 batched tree operations:
light-registryQueueAccount for pending operationsSources: [forester directory], Cargo.toml78-79
Light Protocol has undergone multiple security audits:
Audit reports are available in the audits/ directory. Programs are deployed with verifiable builds that can be checked using solana-verify.
Sources: README.md65-74 SECURITY.md1-13
The codebase supports multiple feature configurations:
V1 vs V2 Trees:
ConcurrentMerkleTree and IndexedMerkleTree for individual operationsBatchedMerkleTree for batched operations (default with v2 feature)Hash Functions:
poseidon - Poseidon hash (default, ZK-friendly)keccak - Keccak256sha256 - SHA256Framework Support:
anchor - Anchor framework compatibilityidl-build - IDL generation for client toolingMost crates default to v2 and poseidon features for production use.
Sources: sdk-libs/sdk/Cargo.toml13-40 sdk-libs/client/Cargo.toml9-14
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.