Skip to main content

Overview

The MerkleTreeAccount is a zero-copy account that stores the sparse Merkle tree state used to track all private commitments in the Privacy Cash protocol. Each tree can handle either native SOL or a specific SPL token.

Account Structure

authority
Pubkey
required
The public key of the authority that can update this tree’s configuration
next_index
u64
required
The index where the next leaf will be inserted in the Merkle tree
subtrees
[[u8; 32]; 26]
required
Array of intermediate node hashes representing the state of each level in the Merkle tree (height 26)
root
[u8; 32]
required
The current root hash of the Merkle tree
root_history
[[u8; 32]; 100]
required
Circular buffer storing the last 100 root hashes to allow proofs against recent tree states
root_index
u64
required
The current position in the root_history circular buffer
max_deposit_amount
u64
required
Maximum amount (in lamports for SOL, or token units for SPL tokens) that can be deposited in a single transaction
height
u8
required
The height of the Merkle tree (fixed at 26)
root_history_size
u8
required
The size of the root history buffer (fixed at 100)
bump
u8
required
The PDA bump seed used for account derivation
_padding
[u8; 5]
required
Padding bytes required for zero-copy account alignment

PDA Seeds

For SOL (Native)

[b"merkle_tree"]

For SPL Tokens

[b"merkle_tree", mint.key().as_ref()]

Notes

  • This account uses the #[account(zero_copy)] attribute for efficient memory access without deserialization
  • The tree height of 26 allows for 2^26 (67,108,864) unique commitments
  • The root history enables users to create proofs using recent tree states even while new deposits are being processed
  • Each SPL token has its own separate Merkle tree account

Build docs developers (and LLMs) love