State Compression

A cost-saving technique that stores only a Merkle tree fingerprint of data on-chain while keeping the full data in the cheaper ledger space, slashing storage costs by orders of magnitude for large-scale asset minting.

What is State Compression

State compression represents a fundamental shift in data architecture on Solana. It is how Solana achieves high efficiency and low costs for large collections by storing massive amounts of data as hashed leaves in an on-chain Merkle tree, rather than as separate account data. Only the Merkle tree root hash remains in the account data, which is the expensive part of Solana. The rest of the data lives on the ledger, which is the cheap, append-only history that every validator already maintains. One of the most popular use cases for state compression is compressed NFTs (cNFTs), which are minted via Metaplex's Bubblegum program.

A helpful analogy is a photographer's contact sheet. Rather than having a photographer hang 10,000 printed photographs on a gallery wall, they will post one contact sheet and keep the negatives filed in a binder for safe keeping. If anyone wants to verify a particular photograph, they simply have to pull out the corresponding negative and compare it to the sheet. The Merkle root is the contact sheet. The data lives in the ledger (or, like the negatives, the binder). A Merkle proof is just the verification process that allows you to compare the negative against the sheet.

The Technical Mechanics of State Compression

A normal Merkle tree works by repeatedly pairing and hashing data until only one hash, the root, remains. Any change to the data at any leaf will result in a change in the root. The root is stored in a program's state, and is updated through transaction writes. If two programs attempted to write different leaves to the same tree in the same slot, they would invalidate each other's Merkle proofs.

Solana addresses this issue via concurrent Merkle trees. Rather than updating the program state in the same slot as writing a new leaf, the program maintains a changelog buffer containing the latest roots for any given Merkle tree. This allows the program to replay many recent root writes rather than only processing one per transaction. By doing so, Merkle trees are no longer constrained to a single thread of execution, so many writes to a given tree can succeed within the same slot.

If the data never actually exists in the compressed account (since it lives in the ledger and not in account data), how do you even read the asset? The answer here is that you actually do not need to read it on-chain to do so. Indexers like Helius are able to provide data through the Digital Asset Standard (DAS) API by monitoring the ledger for all data that belongs to a given asset. The wallet applications we know and love, like Phantom and the apps that power marketplaces such as Tensor or Magic Eden, depend on DAS and run these queries in order to display all assets owned by a user. If you own an asset but haven't used it yet, your app will still show it; all that is happening behind the scenes is an indexer query on DAS. Only the transfer transactions occur on-chain, and even those involve a Merkle proof against the root hash as opposed to the full data.

When you create a compressed collection, you get to specify its configuration settings, including its height (the number of bits for the Merkle hash) and tree capacity, and the "size" of its "canopy," or the portion of the Merkle tree you choose to store on-chain, as opposed to off-chain. These settings determine how many data items can be compressed within the collection and the size of Merkle proofs needed to validate the ownership of a compressed asset at any given time. For example, a 20-bit Merkle tree can hold around one million cNFTs, but it will forever hold only around one million cNFTs; if you mint a million and one, you need a new Merkle tree.

The Economic Impact of State Compression

State compression is about cost. Let's take that same collection of one million cNFTs. The total cost to mint and compress this collection on Solana is around 5 to 10 SOL ($400 to $800 USD at an $80 SOL price). Contrast that with a traditional Solana NFT collection that takes up individual accounts, with a rent-exempt storage cost per account, for a total cost in the tens of thousands of SOL (a difference of orders of magnitude). And compare that with a collection on Ethereum: minting even a mere 100,000 regular NFTs will cost millions of dollars in gas fees on Ethereum, under most gas prices.

These price differences have created a niche market for cNFTs, one that is both cheap and popular. DRiP, for example, has distributed hundreds of millions of cNFTs to collectors in order to create a unique and low-friction way for fans to participate in their favorite artists' communities. It has become so successful that it has become a new standard for airdrops. If DRiP were to mint each cNFT using traditional accounts, it would cost them thousands of dollars per airdrop, not to mention the high gas fees of the individual minting transaction. Magic Eden and Tensor have made their services available for cNFTs, too, so the cheaper mints didn't come at the cost of lower trading volumes.

The Broader Importance of State Compression

State compression matters because of the use cases it unlocks. Imagine a record label hosting a 50,000-person music festival and wanting to distribute a commemorative digital souvenir to each attendee in the form of a cNFT ticket stub. Even if they were a small label, that would be around $4,000 to $8,000 USD to do so. Now imagine what the cost would be if it were a non-compressed NFT collection; the headliner artist wouldn't cover it! This same math applies to loyalty programs, game items, proof-of-attendance passes, and other types of collections; things which have value but are cheap enough only if they are compressed.

This comes with some tradeoffs. If you are the user of this cNFT collection or the issuer, the provenance of your assets will still be on-chain, and a transaction can always prove that the asset is yours. Accessing that asset on-chain would be painful, since it requires reading and decoding the whole ledger for a particular collection. So the ability to quickly and smoothly verify the authenticity and ownership of your cNFT is dependent on a third-party service, such as Helius, that has an up-to-date snapshot of that data. But there is a 99%+ discount on the costs of your cNFTs, and most million-item collections will not find this to be a bad deal.

Contents

Writen By

Hanko

Hanko is the Founder and CEO of Soladex. As an early believer in Solana, he has planted deep roots in the ecosystem including operating a validator for over 3 years. With a decade of experience in affiliate marketing and SEO, Hanko brings proven digital expertise to the blockchain space. Through Soladex, he's on a mission to share Solana's potential with the world, creating educational content and resources for the rapidly growing Solana community.

Stay Updated - Follow us on X

Project review threads, dApp insights, announcements, news, and more.