Compressed asset vault design
The compressed NFT vault example shows how a Solana program can hold compressed NFTs under a program-derived address and later transfer them to a chosen recipient. It places custody with the program rather than with a user wallet, while Bubblegum and the account compression program verify each asset transfer against its Merkle tree state. See Compressed asset programs for the parent view and Compressed NFT lifecycle operations for owner-controlled asset changes.
Vault scope and relationships
The vault is a custody pattern for compressed NFTs (cNFTs), which are NFT records stored as leaves in a Merkle tree instead of as separate full accounts. The example accepts assets sent to its fixed vault address and exposes transfer actions that move them to a new owner.
The vault program is not a complete policy service. It demonstrates custody and transfer wiring, but it does not decide whether a particular caller or recipient should be allowed to withdraw an asset. This distinction is central to the example: technical control of the cNFT is separate from business permission to release it.
Custody address
The vault uses one program-derived address (PDA) as the cNFT owner. A PDA is an address derived from program rules that the program can sign for, even though no private key exists for it. Users can send cNFTs to this address through normal compressed NFT transfers, after which the program can act as the owner.
The vault PDA is not a storage account that holds the full NFT record. Bubblegum records the asset in the Merkle tree, while the PDA supplies the owner signature needed for a later transfer. compression/…/README.md• L3-8 compression/…/lib.rs• L269-295
References: compression/…/README.md• L3-8 compression/…/lib.rs• L269-295
Custody lifecycle
The custody lifecycle has three separate actors. A sender deposits the cNFT into the vault PDA. The vault program signs as the current owner when a withdrawal is requested. Bubblegum validates the leaf and updates the compressed tree so the recipient becomes the new owner.
This diagram shows the custody boundary and the downstream state change.
sequenceDiagram
participant S as Sender
participant T as Compressed tree
participant V as Vault PDA
participant P as Vault program
participant R as Recipient
S->>T: Transfer cNFT to vault PDA
T-->>V: Record vault PDA as leaf owner
R->>P: Request withdrawal
P->>P: Sign as vault PDA
P->>T: Ask Bubblegum to transfer leaf
T-->>R: Record recipient as new owner
References: compression/…/README.md• L5-8 compression/…/lib.rs• L87-147
Withdrawal authority
Withdrawal authority comes from the current compressed leaf owner and the tree rules. The example binds the downstream transfer to the vault PDA as leaf_owner, then uses the PDA seeds to sign the cross-program call. The recipient is only the destination; the recipient does not authorize release of the asset.
Owner authorization
The vault program can sign only for its own PDA. Bubblegum therefore accepts the transfer only when the compressed leaf identifies that PDA as the owner or delegate expected by the transfer. A user transaction may call the vault instruction, but the user does not replace the vault as the asset authority.
The example does not add an application-level authorization check. Its README states that anyone can withdraw any cNFT in the vault. Production custody logic must add a policy boundary before the program signs the Bubblegum transfer.
References: compression/…/lib.rs• L101-145 compression/…/lib.rs• L269-295 compression/…/README.md• L20-23
Tree authority
The tree authority is a Bubblegum-controlled address derived from the Merkle tree. It is not the vault owner and it does not decide who may use the vault. Its role is to connect the transfer to the correct compressed tree so Bubblegum can apply the leaf update.
The vault program passes Bubblegum, the account compression program, the log wrapper, and the system program as downstream dependencies. These programs provide the environment for proof checking and tree mutation, while the vault PDA provides the owner signature.
References: compression/…/lib.rs• L10-22 compression/…/lib.rs• L46-80 compression/…/lib.rs• L269-295
Proof-backed withdrawal
Each withdrawal uses current asset data and a Merkle proof. A Merkle proof is the set of sibling hashes that lets Bubblegum check that one leaf belongs to the root recorded for the tree. The client gathers this data from a compressed-asset read service, then the vault program forwards it to Bubblegum.
Asset and proof inputs
The client first reads the asset and its proof by asset ID. The asset read supplies the tree, leaf position, data hash, and creator hash. The proof read supplies the current root and proof path. The client converts the encoded values into instruction inputs and passes the proof nodes as read-only accounts.
The client must read both results for the same asset. The proof describes a position in one tree state, while the hashes describe the leaf at that position. Mixing results from different assets or stale tree state makes the transfer fail.
References: compression/…/readAPI.ts• L5-45 compression/…/utils.ts• L10-28 compression/…/tests.ts• L21-60
Bubblegum transfer
The vault program acts as a narrow bridge between the caller and Bubblegum. It builds a transfer request from the root, leaf hashes, nonce, index, tree accounts, recipient, and proof accounts. It then invokes Bubblegum with the vault PDA as the signed leaf owner.
Bubblegum performs the compressed state change. The vault program does not keep a separate ownership record, so the updated tree state and the external read service remain the source of the asset’s new owner.
References: compression/…/lib.rs• L24-80 compression/…/lib.rs• L87-147
Transfer forms
The example supports one-asset and two-asset withdrawals. Both forms use the same custody boundary and proof-backed transfer, but the two-asset form combines two independent tree updates in one program call.
Single withdrawal
The single withdrawal accepts one compressed asset and one recipient. Its proof accounts follow the fixed accounts in the request, which lets the downstream transfer use the complete path from the leaf to the tree root.
References: compression/…/lib.rs• L87-147 compression/…/withdraw.ts• L9-50
Batched withdrawal
The batched withdrawal handles two assets that may belong to different Merkle trees and may have different recipients. The client joins the two proof paths into one account list and supplies the length of the first path so the program can separate the inputs before it performs the two transfers.
The two transfers use the same vault signer. They remain separate Bubblegum calls, so failure in either call prevents the enclosing transaction from completing as a successful withdrawal.
References: compression/…/lib.rs• L150-265 compression/…/withdrawTwo.ts• L10-76
Address lookup support
Proof paths can require many account addresses. The lookup example moves repeated addresses into an address lookup table so a versioned transaction can carry the batched withdrawal within Solana transaction size limits. The lookup table changes transaction packaging only; it does not change who owns the cNFT or who may authorize its transfer.
References: compression/…/withdrawWithLookup.ts• L19-107 compression/…/withdrawWithLookup.ts• L121-172
Compressed asset utilities
The cNFT utilities example provides the wider support pattern around vault custody. It shows how an application program can mint a compressed NFT into a collection and verify a leaf owner before adding application-specific behavior. The vault example uses the same Bubblegum and account compression model, but focuses on custody and transfer rather than minting.
Mint and verify support
The utility program exposes mint and verify actions. Minting connects a compressed NFT to a collection and chooses its initial owner and delegate. Verification checks the leaf against the supplied root and hashes while requiring the leaf owner to sign.
These actions show two useful authority boundaries for a larger asset service. A collection authority controls collection-backed minting, while the current leaf owner controls owner verification. Neither role should be confused with the vault PDA, which controls only assets already assigned to its custody address.
References: compression/…/README.md• L3-10 compression/…/lib.rs• L36-54 compression/…/mint.rs• L12-65 compression/…/verify.rs• L5-17
Read support
The utility clients use compressed-asset reads to obtain asset state and proof data before they build program requests. This read layer is an input service rather than an authority: it helps the client find current data, but Bubblegum remains responsible for checking the proof during the on-chain action.
References: compression/…/readAPI.ts• L1-45 compression/…/compression.ts• L257-376 compression/…/tests.ts• L24-42
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the vault PDA seed and the client’s derived address identical. A seed change can make deposited assets unreachable by the program.
- Keep the Bubblegum transfer account order, signer role, tree authority derivation, and proof account order aligned. These values form one downstream transfer contract.
- Treat the two-asset proof split length as part of the batch interface. A wrong boundary sends proof accounts to the wrong tree update.
- Preserve the separation between custody authority and withdrawal policy. Adding or removing policy checks changes who can release every asset in the vault.
- Keep the DAS asset fields and proof fields paired by asset ID. The tree, leaf index, root, and hashes must describe one current compressed leaf.
- Keep address lookup table contents in step with any new fixed or proof accounts used by versioned withdrawal transactions.
- Keep the Anchor and Solana toolchain versions, provider targets, program addresses, and downloaded CPI fixtures aligned with the vault or utility flow. A mismatch can make local validation use the wrong runtime or missing support programs.
- Keep the package manifest, workspace override policy, and lockfile aligned when changing the Anchor, Bubblegum, account compression, or read-service dependencies. A mismatch can change the client and program support set without changing the vault interface.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A cNFT is not owned by the vault PDA | Bubblegum rejects the transfer because the vault cannot sign for the current owner. | Deposit the asset to the PDA before requesting withdrawal and use the same PDA seed. |
| A caller supplies an asset that is not in vault custody | The downstream transfer fails or the request targets an unrelated leaf. | Check the current owner from the asset read and add application-level withdrawal policy. |
| The asset data and proof come from different or stale reads | The leaf does not match the supplied root and the transfer fails. | Fetch both values for the same asset and use current proof data. |
| The proof path is empty, incomplete, or in the wrong order | Bubblegum cannot validate the leaf. | Map every proof node as a read-only account after the fixed accounts. |
| The batch proof length is wrong | The second transfer receives part of the first proof or vice versa. | Split the combined account list at the first proof’s exact length. |
| The transaction omits required lookup-table addresses | The versioned transaction cannot resolve all accounts or exceeds its size limit. | Extend and load the address lookup table before sending the batch. |
| The Anchor or Solana toolchain, provider target, or CPI fixture set does not match the example | Local tests can fail before the custody flow runs or validate against the wrong support programs. | Keep each Anchor.toml toolchain, cluster, wallet, program address, and fixture list aligned with its example. |
| The dependency manifest and lockfile do not agree | The example can install a different support set from the one used to validate the client and program flows. | Update the workspace overrides and lockfile with the package manifest. |
Key files
| File | Why to read it |
|---|---|
| compression/…/README.md | States the custody goal, supported withdrawals, and example limitations. |
| compression/…/Anchor.toml | Defines the vault example’s toolchain, devnet target, program identity, and CPI fixture setup. |
| compression/…/lib.rs | Defines the vault signer boundary and the single and batched Bubblegum transfers. |
| compression/…/tests.ts | Shows the end-to-end client inputs for one and two withdrawals. |
| compression/…/readAPI.ts | Shows the asset and proof reads needed before a withdrawal. |
| compression/…/withdrawWithLookup.ts | Shows how proof-heavy withdrawals use a versioned transaction and address lookup table. |
| compression/…/package.json | Defines the vault example’s program and client support dependencies. |
| compression/…/pnpm-workspace.yaml | Defines dependency overrides that keep the example’s support packages on selected versions. |
| compression/…/Anchor.toml | Defines the utility example’s toolchain, provider target, program identity, and minting fixture setup. |
| compression/…/mint.rs | Shows the collection and initial-owner boundary for compressed NFT minting. |
| compression/…/verify.rs | Shows owner-signed proof verification as a reusable utility pattern. |