The Account Compression program is the foundation of Light Protocol’s ZK compression system. It owns all Merkle tree accounts and provides instructions for tree operations.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Lightprotocol/light-protocol/llms.txt
Use this file to discover all available pages before exploring further.
Program ID
Overview
The Account Compression program manages two types of Merkle trees:- State Merkle Trees: Store compressed account state data
- Address Merkle Trees: Track address ownership and inclusion proofs
Key Features
Tree Management
Batched Operations
Access Control
Forester Support
Account Types
State Merkle Tree
Stores compressed account data as leaves in a Merkle tree.access_metadata: Program owner, forester, associated queuerollover_metadata: Rollover threshold and fee configurationqueue_metadata: Associated nullifier queue settings
Address Merkle Tree
Tracks addresses and their inclusion proofs using an indexed Merkle tree structure.Nullifier Queue
Temporary queue for batched nullification of spent state.Core Instructions
Tree Initialization
initialize_state_merkle_tree_and_nullifier_queue
initialize_state_merkle_tree_and_nullifier_queue
authority(signer): Tree authoritymerkle_tree(writable): Uninitialized state tree accountnullifier_queue(writable): Uninitialized queue accountregistered_program_pda: Program registration proof
index: Unique tree indexprogram_owner: Optional program that owns the treeforester: Optional designated forester for tree maintenancemerkle_tree_config: Tree height, changelog size, roots size, canopy depthqueue_config: Capacity, sequence threshold, network fee
programs/account-compression/src/instructions/initialize_state_merkle_tree_and_nullifier_queue.rsinitialize_address_merkle_tree_and_queue
initialize_address_merkle_tree_and_queue
authority(signer): Tree authoritymerkle_tree(writable): Uninitialized address tree accountqueue(writable): Uninitialized address queue accountregistered_program_pda: Program registration proof
index: Unique tree indexprogram_owner: Optional program ownerforester: Optional designated foresteraddress_merkle_tree_config: Tree configurationaddress_queue_config: Queue configuration
programs/account-compression/src/instructions/initialize_address_merkle_tree_and_queue.rsinitialize_batched_state_merkle_tree
initialize_batched_state_merkle_tree
input: Tree initialization data (height, capacity, root history size)
programs/account-compression/src/instructions/initialize_batched_state_merkle_tree.rsinitialize_batched_address_merkle_tree
initialize_batched_address_merkle_tree
input: Address tree initialization data
programs/account-compression/src/instructions/initialize_batched_address_merkle_tree.rsTree Operations
nullify_leaves
nullify_leaves
authority(signer): Must be registered program or tree authorityregistered_program_pda: Program registration proofmerkle_tree(writable): State tree to updatenullifier_queue(writable): Queue to append nullifierslog_wrapper: Event logging
change_log_indices: Indices in changelog for proof verificationleaves_queue_indices: Indices of leaves to nullifyindices: Leaf indices in the treeproofs: Merkle proofs for each leaf
programs/account-compression/src/instructions/nullify_leaves.rsupdate_address_merkle_tree
update_address_merkle_tree
changelog_index: Index in changelogindexed_changelog_index: Index in indexed changelogvalue: Address value to insertlow_address_index: Index of address below insertion pointlow_address_value: Value of low addresslow_address_next_index: Next index from low addresslow_address_next_value: Next value from low addresslow_address_proof: Merkle proof for low address
programs/account-compression/src/instructions/update_address_merkle_tree.rsbatch_append
batch_append
data: Batched append instruction data
programs/account-compression/src/instructions/batch_append.rsbatch_nullify
batch_nullify
data: Batched nullify instruction data with ZK proof
programs/account-compression/src/instructions/batch_nullify.rsbatch_update_address_tree
batch_update_address_tree
programs/account-compression/src/instructions/batch_update_address_tree.rsTree Rollover
rollover_state_merkle_tree_and_nullifier_queue
rollover_state_merkle_tree_and_nullifier_queue
authority(signer): Fee payerregistered_program_pda: Program registrationnew_merkle_tree(writable): Pre-created new treenew_nullifier_queue(writable): Pre-created new queueold_merkle_tree(writable): Current tree to mark as rolled overold_nullifier_queue(writable): Current queue to mark as rolled over
- Validates new tree has same configuration as old tree
- Marks old tree as rolled over (prevents new operations)
- Links old tree to new tree for continuity
programs/account-compression/src/instructions/rollover_state_merkle_tree_and_nullifier_queue.rsrollover_address_merkle_tree_and_queue
rollover_address_merkle_tree_and_queue
programs/account-compression/src/instructions/rollover_address_merkle_tree_and_queue.rsrollover_batched_state_merkle_tree
rollover_batched_state_merkle_tree
programs/account-compression/src/instructions/rollover_batched_state_merkle_tree.rsrollover_batched_address_merkle_tree
rollover_batched_address_merkle_tree
programs/account-compression/src/instructions/rollover_batched_address_merkle_tree.rsAccess Control
initialize_group_authority
initialize_group_authority
update_group_authority
update_group_authority
register_program_to_group
register_program_to_group
authority(signer): Group authorityprogram_to_be_registered: Program to grant accessregistered_program_pda(writable): PDA to creategroup_authority_pda: Group PDA
programs/account-compression/src/instructions/register_program.rsderegister_program
deregister_program
programs/account-compression/src/instructions/deregister_program.rsUsage in Custom Programs
Registering Your Program
Before your program can use Account Compression, it must be registered:Nullifying Leaves
Example of nullifying compressed account state:Error Codes
Common errors from the Account Compression program:| Code | Name | Description |
|---|---|---|
| 6000 | InvalidAuthority | Authority does not match tree metadata |
| 6001 | MerkleTreeFull | Tree has reached capacity |
| 6002 | InvalidMerkleProof | Provided Merkle proof is invalid |
| 6003 | LeafAlreadyNullified | Attempting to nullify already-nullified leaf |
| 6004 | InvalidChangelogIndex | Changelog index out of bounds |
| 6005 | InvalidQueueType | Queue type doesn’t match operation |
| 6006 | RolloverNotReady | Tree not ready for rollover |
| 6007 | InvalidRegisteredProgram | Program not registered for this tree |
programs/account-compression/src/errors.rs