Zksync pubdata and storage-driven fees
Zksync Era's EraVM fee model charges for publishing storage changes, so a transaction's data footprint affects its fee alongside contract execution costs. Pubdata is the information that the rollup publishes to Ethereum to support reconstruction of its state. Storage updates appear as compressed differences across a batch, with shorter references for previously published keys and compact encodings for suitable values. Those savings reduce publication data; computation and batch overhead remain part of the transaction fee.
Updated:
Key takeaway: A shorter storage encoding reduces publication bytes; the final EraVM fee still includes execution costs and batch overhead.
Batch-level changes and the publication footprint
Multiple writes to the same storage slot within a batch contribute to a final state difference, which determines the storage data that requires publication. A storage slot is a location that a contract uses to retain a value. The batch records the change between its starting and ending state. This approach lets repeated updates share a published storage record, although each executed operation still consumes computation. Changes in different batches create separate publication requirements.
Initial writes and shorter storage references
A first published write introduces a storage key, while a later batch can refer to that key through its assigned enumeration index. EraVM derives the key from the contract address and the contract's storage slot. The initial-write representation includes the full 32-byte derived key. Subsequent published changes can identify the same location with a shorter index. The distinction follows publication history, not the number of times a contract executes a write instruction. Writing a new location carries different key overhead from changing a previously published location. The value still needs its own encoding, so reusing a key does not make the entire change costless.
Value encodings and their reconstruction rules
A storage value occupies a 32-byte word, but its publication encoding can use fewer bytes when the new value or its change fits a smaller representation. The compression format distinguishes arithmetic changes from direct replacements.
Arithmetic encodings describe the difference between the batch's initial and final values. Replacement encodings carry the new value itself.
| Encoding | Value payload | Reconstruction rule |
|---|---|---|
| Add | Compact increase | Add the encoded difference to the prior value modulo 2 256 . |
| Sub | Compact decrease | Subtract the encoded difference from the prior value modulo 2 256 . |
| Transform | Compact replacement | Use the encoded new value directly. |
| NoCompression | Full 32-byte replacement | Use the complete new value directly. |
Value encodings and their reconstruction rules
A storage value occupies a 32-byte word, but its publication encoding can use fewer bytes when the new value or its change fits a smaller representation. The compression format distinguishes arithmetic changes from direct replacements.
Arithmetic encodings describe the difference between the batch's initial and final values. Replacement encodings carry the new value itself.
- Value payload (Encoding) Add: Compact increase Sub: Compact decrease Transform: Compact replacement NoCompression: Full 32-byte replacement
- Reconstruction rule (Encoding) Add: Add the encoded difference to the prior value modulo 2 256 . Sub: Subtract the encoded difference from the prior value modulo 2 256 . Transform: Use the encoded new value directly. NoCompression: Use the complete new value directly.
The NoCompression mode publishes the complete 32-byte storage value. A one-byte packing tag identifies the encoding and, for compact representations, the payload length.
An initial write can still use a compact value encoding even though it needs the full derived key. Key reuse and value compression affect separate parts of the published record.
The Compressor contract verifies state-diff compression against the expanded state differences. A smaller record must still reconstruct the storage change that execution produced.
The NoCompression mode publishes the complete 32-byte storage value. A one-byte packing tag identifies the encoding and, for compact representations, the payload length.
An initial write can still use a compact value encoding even though it needs the full derived key. Key reuse and value compression affect separate parts of the published record.
The Compressor contract verifies state-diff compression against the expanded state differences. A smaller record must still reconstruct the storage change that execution produced.
Execution, publication, and batch overhead
Publication gas follows a byte-based relationship: the bytes charged to the transaction multiplied by the applicable gas per pubdata byte. That quantity expresses gas, not a token payment. The gas price converts gas usage into a monetary fee. Execution also consumes gas, and the fee model includes contributions toward running and settling batches. Proof generation and verification add overhead beyond the storage bytes themselves. These gas quantities use EraVM's native accounting unit, also called ergs. Transaction data also occupies the bootloader's limited memory, another input to the allocation of batch overhead.
The operator's pricing inputs cover both computation and pubdata. Publication pricing reflects Ethereum data costs and the overhead associated with exhausting a batch's data capacity. Fewer bytes can reduce one cost component without producing the same percentage reduction in the final fee. Paymaster sponsorship changes the payer for an eligible transaction while leaving publication requirements in the fee calculation.
Post-charging and the transaction's gas budget
EraVM measures pubdata during execution and settles its gas charge afterward, because the transaction's actual state changes determine how much publication data it adds. The bootloader, which coordinates transaction processing, checks whether enough gas remains for that charge. If the validation-stage pubdata check fails, the transaction does not enter the block. If the post-execution check fails, the transaction reverts its state changes and still incurs computation charges.
A gas-per-pubdata-byte limit caps the permitted gas charge per byte. It does not specify the number of publication bytes that a transaction can use.
Zksync-specific EIP-712 transactions carry a gas_per_pubdata_limit field for that per-byte bound. Ethereum-format transactions lack that field, so this user-selected bound belongs to the Zksync-specific transaction format. The total gas limit must also leave room for publication after execution. A very low per-byte bound can prevent a transaction from satisfying the applicable pricing requirements, even when the sender holds enough funds. A paymaster's optional postTransaction hook also undergoes a pubdata check.
Bytecode, messages, and Ethereum publication
Storage differences make up only part of pubdata; published contract bytecode and L2-to-L1 logs and messages also contribute data that the protocol must make available. Publishing previously unknown bytecode can therefore create a publication cost that storage reuse alone cannot remove. Bytecode compression uses a different representation from storage-value compression, so the Add and Sub modes do not describe every byte of a deployment's pubdata.
The post-EIP-4844 commitment format supports publishing pubdata through either Ethereum calldata or blobs. Calldata places that data in the Ethereum transaction input, while blobs provide a separate data-availability channel. Blob publication changes the Ethereum cost inputs without replacing the storage compression rules.
Storage design and the limits of fee estimates
Fewer newly introduced slots and compact value changes can reduce publication requirements, provided that the contract preserves the same intended behavior and necessary state. A smaller storage footprint can still accompany more expensive computation. Temporary writes that restore a slot's earlier value can reverse pubdata-counter increments, while their executed instructions still consume gas. A fee comparison therefore needs the same contract operation and comparable state, together with the applicable pubdata price.
Questions and answers about Zksync
-
Can an off-chain contract call create pubdata fees?
- An eth_call simulation creates no blockchain transaction and publishes no storage changes. It executes contract logic against a chosen state without committing any resulting changes. A fee-paying transaction that invokes a contract belongs to a different path, even if the application presents both interactions as contract calls.
-
Does clearing a storage slot eliminate its pubdata cost?
- Clearing a slot that was nonzero at the start of a batch can shrink its value payload while still requiring a published state difference. Transform can represent a zero replacement with no value payload, while the surviving state diff still needs its key reference and packing metadata. A slot that returns to its batch-start value has different accounting because that temporary change leaves no final storage difference.
-
Is smaller transaction calldata enough to lower pubdata fees?
- Smaller transaction calldata does not necessarily reduce storage pubdata. Calldata supplies the contract's input; state-diff pubdata represents the storage changes that survive execution. A more compact input can still produce the same final storage differences, so input-size savings do not establish a storage-publication saving.
-
Can a subcall gas limit cap the transaction's full pubdata cost?
- A subcall's computation gas cap does not necessarily cap the outer transaction's pubdata charge under EraVM post-charging. The callee can increase the pubdata counter through storage writes or other publishable output. The bootloader settles that data charge after execution, outside the subcall's immediate computation budget. Contract logic that treats forwarded gas as the complete cost therefore needs to account for the separate publication charge.
-
Why can a well-funded transaction exceed pubdata limits?
- A transaction can require more publication data than a batch permits, regardless of the sender's ability to pay. The protocol enforces data capacity as well as gas and fee rules. A larger offered fee cannot make an oversized state-change footprint fit that capacity. The applicable byte limit belongs to the chain's configuration and protocol version.
-
Who controls the refund for repeated storage writes?
- The operator supplies repeated-write pubdata refund adjustments in the EraVM fee model. A reused storage reference can reduce the publication bytes that the update requires, and several changes within a batch can share a final difference. The resulting reduction is not a fixed refund percentage or a promise that the transaction's entire fee falls by the same proportion.
-
Which RPC method exposes the active pubdata fee parameters?
- The zks_getFeeParams remote procedure call (RPC) returns the node's fee configuration, including pubdata pricing and batch-capacity settings. The V2 response includes L1 gas and pubdata prices alongside minimum L2 gas pricing and overhead inputs. It describes configuration, not a transaction-specific bill; the cost of a particular call also requires its execution and state changes.
-
Does pubdata compression make stored values confidential?
- Pubdata compression does not make published storage changes confidential. Enumeration indexes and compact values preserve enough information to reconstruct updates from earlier state. Compressing the representation changes its size, while the underlying rollup data remains public.