general

Calldata Compression

Calldata compression is a technique used in blockchain systems — particularly Layer 2 rollups — to reduce the size of transaction input data posted to a base layer like Ethereum. By encoding data more efficiently before publishing it on-chain, protocols cut gas costs significantly. It's a critical optimization for rollups that must post user transaction data to L1 for security and data availability purposes.

What Is Calldata Compression in Blockchain?

Calldata compression is the process of encoding transaction input data into a smaller byte representation before it's submitted on-chain. If you've ever wondered why some Layer 2 transactions are dramatically cheaper than others, calldata compression is often a big part of the answer.

Every transaction on Ethereum includes calldata — the raw input bytes that tell a smart contract what to do. On rollups, batches of L2 transactions get compressed and posted to Ethereum's L1 as calldata. Pre-EIP-4844, this was the dominant cost driver for rollup fees. A single uncompressed byte of non-zero calldata cost 16 gas. Zero bytes cost 4 gas. That asymmetry is exactly why compression matters.

How Calldata Compression Actually Works

Think of it like zip files, but for blockchain transactions. Standard compression algorithms — most commonly zlib or a variant — look for repeating patterns in the raw transaction data and replace them with shorter references. Addresses, function selectors, and token amounts all follow predictable patterns, making them highly compressible.

Here's a simplified view of what gets compressed in a typical rollup batch:

Data TypeRaw SizeTypical Compressed Size
20-byte address20 bytes~4–8 bytes
32-byte hash32 bytes~10–15 bytes
ETH transfer amount32 bytes~3–6 bytes
Function selector4 bytes~1–2 bytes

Protocols like Optimism and Arbitrum have each built custom compression pipelines. Arbitrum's Nitro stack, for example, uses a combination of dictionary compression and byte-pair encoding that achieves compression ratios of roughly 3:1 to 5:1 on typical transaction batches. That directly translates to user fees — a 4x compression ratio means fees approximately one-quarter the cost of uncompressed posting.

EIP-4844 Changed the Math (But Not the Need)

With EIP-4844 introducing blob transactions in March 2024, rollups gained access to a cheaper data availability channel — blobs — with a separate fee market from regular calldata. Blob space costs significantly less per byte than calldata under normal conditions.

Does that make calldata compression obsolete? No. It doesn't.

Even with blobs, compression remains valuable for two reasons. First, blob space is limited — each block supports a target of 3 blobs and a max of 6. During high-throughput periods, blob fees spike aggressively. Second, some rollups use a hybrid approach, mixing blob data with calldata depending on current market conditions. Compression keeps both channels as cheap as possible.

For a deep look at how these fee dynamics play out across rollup architectures, the Layer 2 Rollup Gas Fee Comparison Analysis breaks down the numbers across major networks.

Zero-Byte Optimization: The Sneaky Edge

One underappreciated trick within calldata compression is deliberate zero-byte stuffing. Since zero bytes cost 4 gas versus 16 gas for non-zero bytes, some protocols structure their encoded data to maximize zero bytes in the output — even if the raw input contains mostly non-zero data.

Warning: Zero-byte padding can sometimes increase encoded data size in byte count while decreasing gas cost. This confuses developers who optimize for size alone rather than actual gas cost. Always optimize for gas, not bytes.

I've seen teams waste weeks shaving bytes off their encoding schemes while leaving gas savings on the table because they ignored the 4/16 gas split entirely.

Compression in the Context of ZK Rollups vs Optimistic Rollups

The compression requirements differ slightly between rollup types:

  • Optimistic rollups (Arbitrum, Optimism/OP Stack) post full transaction data to L1. Higher data volumes mean compression savings are enormous and directly user-facing.
  • ZK rollups (zkSync Era, Starknet, Scroll) can use validity proofs to avoid posting some state data, but still benefit from compressed calldata for inputs that must be verifiable on-chain.

StarkNet's SHARP prover batches proofs across multiple applications, achieving significant amortization of proof costs — but calldata compression is still applied to the input layer. zkSync's Boojum upgrade also implemented aggressive compression at the data layer.

Real-World Impact on Gas Fees

Pre-blob, Arbitrum's calldata compression typically saved users approximately 3–5x on transaction fees compared to posting raw data. Post-EIP-4844, fees on major rollups dropped by 80–95% on average during low-congestion periods. But when blob space fills up — which happens during NFT mint events or token launches — compressed calldata batches still serve as a critical fallback.

For context, Arbitrum processed over 1 million daily transactions at peak in 2024. Without compression, L1 posting costs would have made the network economically unviable for small transactions.

Why Most Developers Don't Think About This

Most protocol developers abstract away compression entirely. They write their contract interfaces and leave the sequencer to handle encoding. That's fine for most use cases.

But high-frequency protocols — DEX aggregators, order book rollups, and perpetuals platforms — can extract meaningful competitive advantages by designing calldata-efficient function interfaces from the ground up. Shorter function selectors, packed structs, and delta-encoded values all feed into better compression ratios downstream.

If you're building on an L2 and your gas optimization strategy ends at "use a rollup," you're leaving real savings on the table.

The Future: Beyond Calldata

Proto-danksharding (EIP-4844) is a stepping stone toward full danksharding, which targets data availability at a scale orders of magnitude beyond current capacity. Even in that future, compression remains relevant — more capacity doesn't eliminate the incentive to use less of it. Efficiency and cost minimization compound at scale.

Calldata compression isn't glamorous. But it's one of the unglamorous mechanisms that makes cheap, scalable blockchains actually work in the context of Layer 2 scaling solutions. For those concerned about MEV bot strategies and their interaction with transaction ordering, understanding how calldata is structured and compressed also provides useful context for how rollup sequencers process and prioritize batches. Developers and traders looking to understand how sequencers interact with pending transactions may also benefit from understanding mempool monitoring and how transaction visibility affects batch ordering. When a block proposer selects which batches to include, the size and cost of that compressed calldata directly influences prioritization decisions. Each batch submitted to L1 also carries a nonce in blockchain transactions that ensures ordering and prevents replay, making the sequencer's management of that field another dimension of how batches get processed and prioritized.

For further reading on the data structures underlying these systems, ethereum.org's rollup documentation and L2Beat's data availability breakdown are both solid starting points.