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
Initialize, rollover, and manage Merkle tree lifecycle
Batched Operations
Efficient batched append and nullify operations
Access Control
Program registration and group-based permissions
Forester Support
Optional forester designation for tree maintenance
Account Types
State Merkle Tree
Stores compressed account data as leaves in a Merkle tree.Account discriminator (varies by tree type)
Tree configuration and access control
access_metadata: Program owner, forester, associated queuerollover_metadata: Rollover threshold and fee configurationqueue_metadata: Associated nullifier queue settings
Current Merkle tree root
History of root updates for proof verification
Cached recent roots for efficient lookups
Address Merkle Tree
Tracks addresses and their inclusion proofs using an indexed Merkle tree structure.Account discriminator for address trees
Tree configuration (similar to state trees)
History of address insertions and updates
Next available index for address insertion
Nullifier Queue
Temporary queue for batched nullification of spent state.Queue account discriminator
Queue configuration and associated tree
Current batch information for efficient processing
Batched nullifier values awaiting insertion
Core Instructions
Tree Initialization
initialize_state_merkle_tree_and_nullifier_queue
initialize_state_merkle_tree_and_nullifier_queue
Creates a new state Merkle tree and its associated nullifier queue.Accounts:
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
Creates a new address Merkle tree and its associated queue.Accounts:
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
Creates a new batched state Merkle tree with output queue for efficient batch operations.Parameters:
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
Creates a new batched address Merkle tree.Parameters:
input: Address tree initialization data
programs/account-compression/src/instructions/initialize_batched_address_merkle_tree.rsTree Operations
nullify_leaves
nullify_leaves
Nullifies (marks as spent) leaves in a state Merkle tree.Accounts:
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
Inserts a new address into an address Merkle tree.Parameters:
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
Appends a batch of leaves from the output queue to a batched state tree.Parameters:
data: Batched append instruction data
programs/account-compression/src/instructions/batch_append.rsbatch_nullify
batch_nullify
Nullifies a batch of leaves using the input queue.Parameters:
data: Batched nullify instruction data with ZK proof
programs/account-compression/src/instructions/batch_nullify.rsbatch_update_address_tree
batch_update_address_tree
Updates address tree with a batch of new addresses.Source:
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
Rolls over a state tree to a new tree when capacity is reached.Accounts:
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
Rolls over an address tree to a new tree.Process: Similar to state tree rolloverSource:
programs/account-compression/src/instructions/rollover_address_merkle_tree_and_queue.rsrollover_batched_state_merkle_tree
rollover_batched_state_merkle_tree
Rolls over a batched state Merkle tree.Source:
programs/account-compression/src/instructions/rollover_batched_state_merkle_tree.rsrollover_batched_address_merkle_tree
rollover_batched_address_merkle_tree
Rolls over a batched address Merkle tree.Source:
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
Registers a program to a group, granting it access to group trees.Accounts:
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
Removes a program’s registration from a group.Source:
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
Source Code
View the full source code on GitHub:Next Steps
Light System Program
Learn about state validation
Build Custom Program
Use Account Compression in your program