Skip to content

Compressed NFTs on Solana - How Many Writers Update One Merkle Tree

Compressed NFTs on Solana keep a Merkle root and a short history of recent writes on chain; the NFT data lives off chain and each asset is a 32-byte leaf. A transfer replaces a leaf, and to replace a leaf a transaction must carry a proof against the tree’s root. When many users act on the same tree in the same slot, each new write changes the root, and with an ordinary Merkle tree every other proof in flight becomes invalid. SPL Account Compression, the on-chain program that stores these trees, solves this with a concurrent Merkle tree: it keeps a short history of recent changes and uses it to repair an out-of-date proof before checking it.

This article explains that mechanism from the whitepaper written by Solana Labs and Metaplex engineers, and from the code of the solana-program/account-compression repository at commit b229799 (28 February 2025). It then turns to the audit side: what the tree guarantees, and what a program built on it, such as Metaplex Bubblegum for NFTs, still has to check. A Python model of the library, checked against a plain Merkle tree, reproduces each example; its 22 checks are in the verification directory. For Solana accounts and programs in general, see Solana Core Concept.

This article has been made with the help of Claude Code and several custom skills

What you need to know first

The article assumes the basics of Solana programs and of hash functions. It relies on the following without deriving them:

  • Merkle inclusion proof. Leaves are hashed in pairs up to one root. A proof for a leaf is the list of sibling hashes on its path, from the leaf level up; the verifier hashes the leaf with each sibling in turn and compares the result with the root. The leaf index tells, at each level, whether the current node is on the left or on the right.
  • Solana accounts and owners. Program state lives in accounts. Each account has an owner program, and only that program can write its data. A program that reads an account passed by the caller must check which account it is.
  • Remaining accounts. An instruction lists the accounts it touches. Account Compression passes the proof nodes as extra account entries: each 32-byte node is written where an account address would go. A legacy transaction is limited to 1,232 bytes, which bounds how many nodes fit.
  • Cross-program invocations and program-derived addresses. A program can call another program, which Solana calls a CPI, and can sign for an address derived from its own ID, called a PDA. This is how a program, rather than a person, can hold the write authority of a tree.
  • Keccak-256. The tree hashes left || right with Keccak-256 (solana_program::keccak::hashv). An empty leaf is 32 zero bytes, and an empty subtree has a fixed root that anyone can compute.

Who takes part in a write

Besides the wallet, four programs and services take part in a compressed-NFT transfer. The wallet gets the leaf’s proof from an indexer, an off-chain service that follows the tree.

The transaction goes to a composing program, such as Metaplex’s Bubblegum, which checks the signature of the owner or of the delegate and rebuilds the old and new leaf hashes from the asset data. That program holds the tree’s write authority and calls Account Compression, which repairs the proof, checks it and writes the new path. Account Compression then calls a no-op program with the change log as instruction data, where the indexer reads it. The diagram follows one transfer; each arrow is a call or a request.

sequenceDiagram
    participant W as "Wallet"
    participant I as "Indexer"
    participant P as "Composing program, e.g. Bubblegum"
    participant AC as "Account Compression"
    participant N as "No-op program"
    W->>I: "Fetch the leaf's proof and the root"
    W->>P: "Transfer, signed by the owner or the delegate"
    P->>P: "Check the signature, rebuild old and new leaf"
    P->>AC: "replace_leaf, signed as the tree authority"
    AC->>AC: "Repair the proof, check it, write the path"
    AC->>N: "Change log as instruction data"
    N-->>I: "Indexer reads the change log from the ledger"

One root, many writers

The whitepaper’s example (its figure 3) uses a tree of depth 3 with nodes numbered in level order: X1 is the root, X8 to X15 are the leaves. Two requests arrive with proofs against the same root X1. The first replaces X10, at leaf index 2, with the proof {X11, X4, X3}. The second replaces X8, at leaf index 0, with the proof {X9, X5, X3}.

Once the first write lands, X10, X5, X2 and X1 change. The second proof still holds the old X5, so it hashes to the old root and a plain check refuses it. With many concurrent requests against one root, “only 1 request would succeed while all others would fail” (whitepaper, section 2).

flowchart TB
    X1["X1 root<br/>changed by write A"] --- X2["X2<br/>changed by write A"]
    X1 --- X3["X3<br/>in both proofs"]
    X2 --- X4["X4<br/>in proof A"]
    X2 --- X5["X5<br/>changed by write A<br/>stale in proof B"]
    X4 --- X8["X8 leaf 0<br/>write B"]
    X4 --- X9["X9<br/>in proof B"]
    X5 --- X10["X10 leaf 2<br/>write A"]
    X5 --- X11["X11<br/>in proof A"]
    classDef changed fill:#FDE2C8,stroke:#B5651D,stroke-width:2px
    classDef stale fill:#F8D0D0,stroke:#A33,stroke-width:3px
    class X1,X2,X10 changed
    class X5 stale

The fix rests on one observation: two leaf paths share every node above the level where they split, and differ below it. Write A changed exactly one node of proof B, the sibling at the level where the two paths separate. If the tree remembers the path that write A recomputed, it can copy the new X5 into proof B, and proof B then matches the new root.

The change log buffer

The tree account stores a ring buffer of change logs. Each change log records one write: the leaf index, the root after the write, and the new value of every node on the written path, from the leaf up. The buffer has a fixed capacity, written B in this article (MAX_BUFFER_SIZE in the code), a power of two chosen when the tree is created. A counter points to the newest entry, and a fill count says how many entries are in use.

A write carries five values: the root its proof was built against, the previous leaf value, the new leaf value, the proof and the leaf index. The previous value is needed because the proof is checked for the leaf as it stands; only then is the new value written along the same path.

Account Compression exposes these operations as instructions:

Instruction What it does Proof Authority signs
append Writes a leaf at the next empty index No Yes
replace_leaf Replaces the leaf at an index, from its previous value Yes Yes
insert_or_append Writes a leaf at an index whose value was empty; if a replayed write changed that leaf, appends it instead Yes Yes
verify_leaf Checks that a leaf is in the tree, writes nothing Yes No
transfer_authority Hands the write authority to another key No Yes
close_empty_tree Closes a tree whose leaves are all empty and sends its lamports to a recipient No Yes

The library functions behind them are append, set_leaf, fill_empty_or_append and prove_leaf.

A write’s root is the starting point of the repair. The tree searches the buffer for that root, from the newest entry back. If entry j holds it, the proof is valid for the state after write j, and every write after j may have changed one of its nodes. The tree replays those writes on the proof, one by one, and only then checks it.

Implementation: ChangeLog and update_proof_or_leaf in changelog.rs; the buffer in concurrent_merkle_tree.rs.

The source comment on this field describes it as the root before the write; the code stores the root after it (see where the documentation and the code disagree).

Fast-forwarding an out-of-date proof

For each later change log, the tree decides which proof node to replace from the two leaf indices alone. In binary, read from the most significant bit, a leaf index spells the path from the root: a 0 is a left turn and a 1 a right turn. XOR-ing the two indices gives 0 bits where the paths agree. The number of leading zeros is the number of steps the two paths share, and the proof node just below the last shared node is the one the other write changed.

The code calls the position of that node in the proof the critbit index. Proof entries are counted from the leaf, so for a tree of depth D the critbit index is D - 1 - leading zeros. The tree copies that node from the change log into the proof.

In the whitepaper’s example, write A is on leaf 2 and write B on leaf 0:

Bit, from the root Leaf 2 (010) Leaf 0 (000) Node reached
1st 0, left 0, left X2 for both: shared
2nd 1, right 0, left X5 for leaf 2, X4 for leaf 0: the paths split
3rd 0, left 0, left X10 and X8

2 XOR 0 = 010 has one leading zero: the paths share one step, to X2, and split below it. The node of proof B that write A changed is X5, the sibling one level below X2, at critbit index 3 - 1 - 1 = 1. Replaying write A sets proof B to {X9, X5’, X3}, where X5’ is the new value of X5, and this proof hashes to the new root. The model reproduces this: the replay touches proof index 1 only, and the resulting root equals the root of a plain tree with both writes applied.

If a later change log is for the same leaf, there is no node to swap: the leaf itself has changed. The tree then refuses the write with LeafContentsModified, because the caller’s previous_leaf no longer matches what the leaf holds. A user who signed a transfer of an NFT cannot have that transfer applied to an asset that was meanwhile transferred elsewhere. The comparison is with the latest value the replayed entries record for that leaf: a leaf changed and then changed back to its old value passes, as the model shows.

The error names in this section are those of the library. The program returns one error, ConcurrentMerkleTreeError, for all of them, and writes the library error’s message to the transaction log.

flowchart TB
    S["Write: root R, previous leaf,<br/>new leaf, proof, index"] --> F{"R found<br/>in the buffer?"}
    F -- "yes, at entry j" --> J["Replay entries after j<br/>on the proof"]
    F -- "no, replace or verify" --> A["Replay every entry<br/>after the oldest one"]
    F -- "no, insert" --> N["Refuse: RootNotFound"]
    J --> L{"Leaf value differs<br/>after the replay?"}
    A --> L
    L -- "yes, replace or verify" --> M["Refuse: LeafContentsModified"]
    L -- "yes, insert" --> AP["Append the leaf instead"]
    L -- "no" --> C{"Proof hashes to the<br/>CURRENT root?"}
    C -- "no" --> I["Refuse: InvalidProof"]
    C -- "yes" --> W["Write the new path,<br/>push a change log"]

The root is a hint, the current root decides

The last check in every path is a plain Merkle check against the current root, the one in the newest change log. The root sent by the caller only chooses where the replay starts. This has two consequences that are easy to misread:

  • A root that is not in the buffer does not stop a replace. The replace and verify paths fall back to a full replay, which the code calls an inferred proof: when the root is unknown, the tree replays the whole buffer on the proof and still accepts it if the result matches the current root. Entries are replayed from oldest to newest, so each swapped node ends at its latest value, and a proof that was already current is not damaged. When the same root appears twice in the buffer, the search from the newest entry back uses the newer one. In the model, a replace with a root that never existed, but with a current proof, succeeds. The insert path does not allow this and fails with RootNotFound.
  • A successful check proves membership in the current tree, not in an old one. Because the final comparison is with the current root, a leaf that was replaced after the proof was built fails, whatever root the caller names.

Implementation: find_root_in_changelog, check_valid_leaf and fast_forward_proof in concurrent_merkle_tree.rs.

How old a proof may be

A proof’s root stays in the buffer for B - 1 later writes. This is the limit the program documents, counted from the other side: the comment on init_empty_merkle_tree counts the replaces “executed with proofs dated for the same root”, and the first request plus B - 1 later ones make B. In the model, 8 requests built against one root all succeed with a buffer of 8. Two steps decide what happens to an older proof:

  1. The root lookup covers B - 1 writes. A proof built against the root of one entry is matched while that entry is in the ring, that is for B - 1 later writes. The next write overwrites the entry, and the root becomes unknown.
  2. The full replay does not rescue write number B. It would need to apply the B stored entries, but it skips the oldest one, which is exactly the first write after the proof. If that write changed a proof node that no later write in the buffer changed again, the check fails with InvalidProof. The skip comes from the replay loop, which moves to the next entry before applying one.

The ring below has B = 8 slots. The proof was built against entry j; writes j+1 to j+8 followed, and write j+8 took the slot of j. Read the arrows as the order of the full replay:

flowchart LR
    S1["Slot of j, now write j+8<br/>newest"] --- S2["j+1<br/>oldest, skipped"]
    S2 --> S3["j+2<br/>replay starts"] --> S4["j+3"] --> S5["j+4"] --> S6["j+5"] --> S7["j+6"] --> S8["j+7"] --> S9["j+8<br/>replay ends"]
    classDef skipped fill:#F8D0D0,stroke:#A33,stroke-width:3px
    class S2 skipped

The model shows both sides with a buffer of 8: with 7 writes since the proof, the write succeeds; with 8 writes, the first changing proof node 1 and the 7 others only proof node 3, it fails, and replaying from the oldest entry inclusive would have produced a valid proof. The library’s own test of old proofs stops at BUFFER_SIZE - 1 writes, BUFFER_SIZE being the test’s name for B. This affects only liveness: the user fetches a fresh proof and retries. It does not let an invalid proof through, because the final check stays against the current root.

Appends without a proof

Minting an NFT appends a leaf. The tree keeps a rightmost proof: the proof of the last filled leaf, with that leaf and the index of the next empty one. In this section, levels are counted from the leaves, the leaf level being 0.

When a leaf is appended at index i, its proof has three parts:

  • Below the intersection level, empty subtrees. Everything to the right of the new leaf is empty, so these siblings are roots of empty subtrees, which the program computes.
  • At the intersection level, one node of the old rightmost path. The program hashes the rightmost leaf with its proof up to that level.
  • Above it, the old rightmost proof. These nodes are shared with the previous rightmost path.

The intersection level is the number of trailing zeros of i. The two paths meet one level higher, at the parent of that node.

In the whitepaper’s figure 4, X13 is the last filled leaf, at index 5, and the append goes to X14, at index 6. Index 6 is 110 in binary, with one trailing zero, so the new proof takes the old path’s node at level 1, X6, and the two paths meet one level higher, at X3. The diagram marks where each node of the new proof {X15, X6, X2} comes from:

flowchart TB
    X1["X1 root"] --- X2["X2<br/>copied from the old rightmost proof"]
    X1 --- X3["X3"]
    X3 --- X6["X6 = H(X12, X13)<br/>from the rightmost leaf and its proof"]
    X3 --- X7["X7"]
    X6 --- X12["X12"]
    X6 --- X13["X13<br/>old rightmost leaf"]
    X7 --- X14["X14<br/>new leaf"]
    X7 --- X15["X15<br/>empty subtree root"]
    classDef proof fill:#D9D5F5,stroke:#5B4FB5,stroke-width:2px
    classDef newleaf fill:#FDE2C8,stroke:#B5651D,stroke-width:2px
    class X2,X6,X15 proof
    class X14 newleaf

Every replace also updates the rightmost proof: a replace on another leaf can change one node of the rightmost path, exactly as it changes one node of any other proof, so the tree applies the same swap to the rightmost proof and always has it ready.

The append instruction therefore takes no proof at all, and concurrent appends cannot collide: each one reads the rightmost proof as the previous append left it. The model checks, after each of six appends, that the root and the rightmost proof equal those of a plain tree. Appending an all-zero leaf is refused (CannotAppendEmptyNode), so an append cannot be confused with an empty slot.

Implementation: append in concurrent_merkle_tree.rs.

The canopy: shorter proofs in the transaction

A proof for a tree of depth 24 is 24 nodes of 32 bytes. Since the nodes travel as account entries in a transaction of at most 1,232 bytes, deep trees cannot be modified with a full proof. The program’s documentation states that a tree “of depth > 24 without a canopy will be impossible to modify on-chain until TransactionV2 is launched”, TransactionV2 being a future transaction format that the comment does not describe further.

The canopy stores the top N levels of the tree, without the root, in extra bytes at the end of the tree account. A caller then sends only the lower D - N proof nodes; the program fills in the upper ones from the canopy, using the hash of an empty subtree when a canopy slot is still zero. After each write, the program copies the new path nodes of those levels into the canopy.

The account is laid out in three parts:

flowchart LR
    H["Header, 56 bytes<br/>depth, buffer size,<br/>authority, creation slot"] --> T["Tree<br/>counters, change log ring,<br/>rightmost proof"] --> C["Canopy<br/>top N levels,<br/>root excluded"]

The canopy holds 2 + 4 + … + 2^N = 2^(N+1) - 2 nodes. The code requires exactly this: the canopy length plus 2 must be a power of two.

The module comment and the SDK comment give other sizes (see where the documentation and the code disagree). In the model, a 2-level canopy of 6 nodes is accepted, 7 nodes is refused, and a replace with a 2-node proof plus the canopy succeeds on a depth-4 tree.

Implementation: canopy.rs and Canopy.ts.

Choosing the depth and the buffer size

The program accepts only a fixed list of depth and buffer pairs, compiled in by a macro: the smallest is depth 3 with a buffer of 8, the largest depth 30 with a buffer of 2,048. The depth sets the capacity, 2^depth leaves; the buffer capacity B sets how many writes a proof survives; the canopy sets how short the proofs in transactions are. All three are fixed when the account is created, since the account size depends on them.

Choice What it buys What it costs
Depth D 2^D leaves Longer proofs; above 24, a canopy is needed
Buffer B A proof’s root stays stored for B - 1 later writes, that is B requests on one root B change logs of 32 * D + 40 bytes each
Canopy N Callers send D - N proof nodes (2^(N+1) - 2) * 32 extra bytes

The whitepaper’s figure 7 sizes a tree of depth 24 with a buffer of 1,024: 827 KB of change logs and an 808-byte rightmost proof. The model reproduces these figures from the struct layout: a change log is 808 bytes, holding the root, 24 path nodes, the index and padding, so 1,024 of them take 827,392 bytes. The rightmost proof is also 808 bytes, since it holds 24 proof nodes, the leaf, the index and padding.

With 24 bytes of counters, the tree takes 827,392 + 808 + 24 = 828,224 bytes, plus the 56-byte header. The annex lists every allowed pair. The buffer, not the leaves, is the main cost of the account.

What a program on top must still check

Account Compression stores and checks hashes; it does not know what a leaf means. A composing program, such as Bubblegum for NFTs, decides who may write and what the leaf commits to. The points below come from the program’s interface and from the audit and advisory history; each is a question for a review of such a program.

Which tree is being read

verify_leaf has no signer. Its only account is the tree, and the program checks only that the account is owned by Account Compression and is a concurrent Merkle tree. Any user can create a tree, be its authority, and append any leaf to it. A program that calls verify_leaf to accept “this leaf is in the tree” must therefore check that the tree account is the one it expects, for example by comparing it with an address stored in its own configuration or derived as a PDA. Without that check, a valid proof in an attacker’s tree passes.

Implementation: VerifyLeaf and verify_leaf in lib.rs.

Who holds the authority

append, replace_leaf, insert_or_append, transfer_authority and close_empty_tree require the tree’s authority to sign. The program documents the authority as “typically a program, e.g., the Bubblegum contract validates that leaves are valid NFTs”. A program signs through a PDA, so when the authority is such a PDA, only that program’s code can write, and its own instruction checks (owner signature, delegate) become the real access control. A tree whose authority is a plain key can be rewritten by whoever holds the key, and transfer_authority can hand it to someone else.

Bubblegum follows the PDA pattern. Its create_tree creates a TreeConfig account at a PDA whose only seed is the tree’s address, one per tree, and makes it the tree authority; every later write signs the call to Account Compression with that PDA. Its transfer accepts the signature of the owner or of the delegate, rebuilds the old and the new leaf, and resets the delegate to the new owner.

Implementation: create_tree.rs and transfer.rs in mpl-bubblegum.

What the leaf commits to

The leaf is 32 opaque bytes. The comment on replace_leaf puts the burden on the caller: “Composing programs should check that the data hashed into previous_leaf matches the authority information necessary to execute this instruction”. The whitepaper’s schema hashes the owner, the delegate, the name, the URI, an asset ID, the creator and the royalty into the leaf.

Bubblegum’s first leaf version hashes a version byte, the asset ID, the owner, the delegate, a nonce, a hash of the metadata and a hash of the creators. The last two are passed as instruction arguments, as the code in leaf_schema.rs shows. A composing program rebuilds that hash from instruction arguments, so any field it forgets to include, or to check against a signature, becomes something a caller can change.

The one advisory in the GitHub Advisory Database for these packages concerns the logic above the tree, not the tree. GHSA-8r76-fr72-j32w (12 December 2022), found by Solshield, affected mpl-bubblegum before 0.6.0, together with mpl-token-metadata, the crate of Metaplex’s Token Metadata program, from 1.5.0 until the fix in 1.6.3. Token Metadata had a provision that let creators who had signed compressed NFTs decompress them with verified creators; through it, a caller could “verify a creator that did not sign”. The advisory does not say which check was missing, nor give the code path (see Gaps).

Index bounds and proof availability

OtterSec audited the library and the program in October 2022, at commit 6e81794 of the former solana-labs/solana-program-library monorepo, and reported one medium finding, OS-CMT-ADV-00. The rightmost index is the index of the first empty leaf, so on a full tree it equals 2^depth, a value that is not a leaf index. set_leaf and prove_leaf checked only index <= rightmost index, so on a full tree the index 2^depth passed.

OtterSec’s proof of concept fills a depth-3 tree and calls set_leaf with index 8, which makes a later write panic on an arithmetic overflow. The library alone “could lead to security implications”; in Account Compression, other checks mitigated it. The current code checks index < 2^depth in both functions and in the program’s handlers.

Proofs also have to come from somewhere. After each write, the program calls a no-op program, one that does nothing, with the change log as instruction data. The module comment gives the reason: logs are truncated beyond a limit, while “CPI instruction data is never truncated”, so indexers can always read the change log from the ledger.

Each change-log event sent to the no-op program carries a sequence number, a counter of successful writes that lets an indexer detect missing entries. The program’s module documentation states that the trees “must be supplemented by off-chain indexers” to serve up-to-date proofs. When no indexer answers, holders cannot get proofs from it, even though every change log, and so every leaf, is in the ledger’s transaction history.

Where the documentation and the code disagree

Several comments in the repository describe the code wrongly. None of them changes what the code does, but a reviewer or a client author who trusts them gets a wrong number:

Place The comment says The code does
ChangeLog.root in changelog.rs “Historical root value before Path was applied” replace_and_recompute_path stores the root computed after the new path, and get_root reads the current root from the newest entry
ConcurrentMerkleTreeHeader in concurrent_merkle_tree_header.rs Only depths 14, 20, 24, 26 and 30 are valid, depth 26 also with buffers of 64 and 256 macros.rs accepts depths from 3 to 30 and, for depth 26, only 512, 1,024 and 2,048; OtterSec reported this as OS-CMT-SUG-00
Module comment of canopy.rs The canopy needs (pow(2, N+1)-1) * 32 bytes It requires (2^(N+1) - 2) * 32 bytes and refuses the commented size with CanopyLengthMismatch
Module comment of canopy.rs The canopy makes it possible to “modify trees up to depth 31” check_bounds asserts a depth below 31; the largest pair has depth 30

The TypeScript SDK computes the canopy size as ((1 << (canopyDepth + 1)) - 2) * 32, which matches the program, while its own comment gives a third formula, (2^(N) - 1 - 1) * 32.

One comment is easy to misread without being wrong. On init_empty_merkle_tree, a buffer of 1,024 “means that a minimum of 1024 replaces can be executed before a new proof must be generated”, the replaces being those “executed with proofs dated for the same root”. Counted that way, the first request included, it matches the code. Read as 1,024 writes after the proof was built, it would promise one write too many.

Verification model results

The verification directory holds cmt.py, a Python model of the library’s write path and of the program’s canopy code, with Keccak-256 written in pure Python. Each result is compared with a plain tree that recomputes every node; the run prints 22/22 PASS. The table groups the checks that support a claim of this article into 11 cases; the other three check Keccak on the empty string, the empty root and the level where an append takes a node of the old path:

Case Result in the model
Six appends without proofs Root and rightmost proof equal the plain tree after each one
Whitepaper figure 3: write on leaf 2, then on leaf 0 with a proof against the old root Second write succeeds; one proof node swapped, at index 1
Rewrite of a leaf from its old value Refused with LeafContentsModified
Leaf changed and changed back, then written with a proof for the old value Accepted
Replace with a root that never existed and a current proof Accepted; insert_or_append with the same root refused with RootNotFound
Buffer of 8, proof older than the buffer, later writes all on the half of the tree that does not contain the proof’s leaf Accepted after the full replay
Buffer of 8, 7 writes since the proof Root found, write accepted
Buffer of 8, 8 requests built against the same root All 8 accepted
Buffer of 8, 8 writes since the proof, the first changing proof node 1 and the 7 others only proof node 3 Refused with InvalidProof; replaying from the oldest entry inclusive would succeed
Canopy of 6 nodes, then 7 nodes 6 accepted, 7 refused; a 2-node proof plus the canopy is accepted
Depth 24, buffer 1,024 827,392 bytes of change logs and an 808-byte rightmost proof, as in the whitepaper

The model mirrors the Rust code line by line but is not the Rust code; the Rust library was not run for this article.

Conclusion

A concurrent Merkle tree trades account space for liveness: by storing the recent paths, it lets writes built against slightly old roots succeed in the same slot.

  • The change log buffer records the path of each recent write; a proof built against any root still in the buffer is repaired by copying, for each later write, the one node where the two paths split.
  • The check is always against the current root, so a repaired proof proves membership now; the root sent by the caller only selects where the repair starts.
  • Appends need no proof, because the tree keeps the proof of its rightmost leaf, and the canopy shortens the proofs a transaction must carry.
  • A proof’s root is kept for B - 1 later writes, the B same-root requests the documentation counts; beyond that, the full replay may still repair the proof, but it skips the oldest stored entry.
  • The security of an application sits above the tree: which tree account is read, who holds the authority, and what the leaf hash commits to.

Mindmap of SPL's concurrent Merkle tree: the change log buffer, proof fast-forwarding, the rightmost proof, the canopy, sizing and the checks a composing program must make

Annex

Key Terms

Term Definition
Account Compression The SPL program (cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK) that creates and modifies concurrent Merkle tree accounts.
Bubblegum Metaplex’s program for compressed NFTs; one TreeConfig PDA per tree is the tree’s authority, and the program builds each leaf from the asset’s data.
Canopy The top levels of the tree, root excluded, cached at the end of the tree account so that callers can send shorter proofs.
Change log One buffer entry: the index of a written leaf, the new nodes of its path, and the root after the write.
Concurrent Merkle tree A Merkle tree that keeps recent change logs so that writes with proofs against recent roots can still be applied.
Critbit index The position, in a proof, of the node that a write on another leaf changed; computed from the XOR of the two leaf indices.
Fast-forwarding Updating an old proof with the change logs written after its root, before checking it against the current root.
Rightmost proof The proof of the last filled leaf, kept by the tree so that appends need no proof.
Sequence number A counter of successful writes, emitted with each change log so that indexers can detect gaps.

Supported depth and buffer pairs

The program accepts these pairs, listed in macros.rs. Without a canopy, an account takes 56 + 24 + (B + 1) × (32D + 40) bytes. The terms are the header, the counters, then B change logs and the rightmost proof of 32D + 40 bytes each.

Depth D Buffer capacities B
3 8
5 8
6 to 9 16
10 to 13 32
14 64, 256, 1,024, 2,048
15 to 19 64
20 64, 256, 1,024, 2,048
24 64, 256, 512, 1,024, 2,048
26 512, 1,024, 2,048
30 512, 1,024, 2,048

Account sizes without a canopy for a few pairs: depth 14 with 64 entries, 31,800 bytes; depth 20 with 1,024, 697,080 bytes; depth 24 with 1,024, 828,280 bytes; depth 30 with 2,048, 2,049,080 bytes.

Security Implementation Checklist

For a program that uses Account Compression:

  • Every instruction that reads a tree checks the tree’s address against a stored or derived value, not only its owner.
  • The tree authority is a PDA of the program, or the reason for an external key is documented.
  • The leaf hash covers every field the program relies on (owner, delegate, asset ID, metadata, creators), and the program rebuilds it from checked inputs.
  • Each signer requirement of the program (owner, delegate, creator) is checked before the CPI that changes the leaf.
  • Depth, buffer and canopy are sized for the expected write rate and transaction size; the guaranteed proof age is buffer size minus one.
  • Clients treat ConcurrentMerkleTreeError, whose logged message names the library error, as a stale proof and fetch a fresh one.
  • Off-chain code that sizes accounts uses (2^(N+1) - 2) * 32 canopy bytes, as the program code does.
  • The indexer serving proofs is named, and holders have a fallback if it stops.

Timeline

Events up to 3 December 2026.

Date Event Source
July 2022 Whitepaper draft Compressing Digital Assets with Concurrent Merkle Trees (Xiao, Gundotra and Yakovenko of Solana Labs, Adams of Metaplex Studios) Whitepaper PDF, created 7 July 2022
3 to 21 October 2022 OtterSec audits Account Compression and the library at commit 6e81794 of solana-labs/solana-program-library; patches confirmed 24 October 2022 OtterSec report
12 December 2022 GHSA-8r76-fr72-j32w published for mpl-bubblegum before 0.6.0 (creator verification) GitHub Advisory
4 October 2024 “make account compression verifiable” commit in the standalone solana-program/account-compression repository Repository history
28 February 2025 Commit b229799, the revision read for this article (spl-account-compression 0.3.3, spl-concurrent-merkle-tree 0.3.0) Repository history

Frequently Asked Questions

Q: Does a concurrent Merkle tree let several writes run in parallel?

No. Writes to one tree account are still applied one at a time. The whitepaper separates concurrency from parallelism: many requests can be built against the same root and all succeed, but the tree changes one request at a time.

Q: Can a fast-forwarded proof let someone write a leaf they do not own?

Not through the tree. The repaired proof must hash to the current root, and the previous leaf must equal the leaf currently stored. Ownership is checked by the composing program, which must rebuild the previous leaf from the owner and the asset data.

Q: Why does insert_or_append refuse an unknown root when replace_leaf accepts it?

fill_empty_or_append, the library function behind insert_or_append, calls the check without the full-buffer replay. If the root is not in the buffer, it returns RootNotFound instead of trying to infer the proof. A LeafContentsModified error, by contrast, makes it fall back to an append.

Q: How many writes can happen between building a proof and using it?

If at most B - 1 writes happened since the proof was built, its root is still in the buffer and the proof is repaired, unless one of those writes changed the leaf itself. Beyond that, the write may still succeed through the full replay, unless the oldest stored write, which the replay skips, changed a proof node that no later write changed again.

Q: What does the canopy cost?

(2^(N+1) - 2) * 32 bytes of account space for N cached levels, paid once in rent when the account is created. In exchange, each write sends N fewer proof nodes.

Gaps

The sources leave the following points open.

Gap Why it matters What to read or verify
The Rust library and program were not built or run; the behaviour is reproduced by a Python model written from the code. A difference between the model and the Rust code would go unnoticed. Run the library’s tests/tests.rs in a container and add a case with BUFFER_SIZE writes since the proof.
Only Bubblegum’s tree creation, leaf schema and transfer were read; its second-generation trees use Metaplex’s fork mpl-account-compression, which was not read. The article describes the SPL program; the fork may differ. metaplex-foundation/mpl-account-compression, and Bubblegum’s processor/ for the other instructions.
The advisory text names the finder and the fix but not the code path in detail. The exact provision that let an unsigned creator be verified is not quoted. The advisory and fix commit c18591a in metaplex-program-library.
Whether the skipped oldest entry in the full replay is known upstream was not checked. It may be intended, or already discussed. The issues and pull requests of solana-program/account-compression.
The stored whitepaper is the July 2022 draft; OtterSec reported errors in it (OS-CMT-SUG-03), and a corrected version was not found. The draft’s Algorithm 1 uses PushFront where PushBack is meant, and it defines the rightmost leaf as the first empty one. A later version of the whitepaper, if one was published.
The transaction budget behind the depth-24 limit is not broken down in the sources: the bytes taken by the signature, the fixed accounts and the instruction data. It is not shown whether a depth-24 tree fits without a canopy, or with how many spare bytes. A byte count of a replace_leaf transaction built with the SDK.
The depth, buffer and canopy that large mints use, and the rent they pay, were not looked up. The sizing section gives the trade-off but no configuration seen in practice. Tree accounts on mainnet and the Metaplex documentation for creating Bubblegum trees.
The program deployment date and the mainnet tree sizes in use were not looked up. The Timeline has no row for the launch of compressed NFTs. The program account cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK on an explorer.

References

Analyzed source

Papers, audits and advisories

You might also enjoy