Reconstruct a ZKsync state-diff value encoded as a delta
ZKsync pubdata can encode a storage update as an operation on the previous value. Treating the compressed payload as the new raw value can turn a one-unit increase into a nearly complete balance loss.
Apply the encoding to the previous state
Read the compression strategy and its encoded length from the protocol version’s format. For an Add record, combine the delta with the previously reconstructed slot value. The example yields 1,000,001, not one.
initial slot value = 1,000,000
final slot value = 1,000,001
candidate encoding = Add(1)
Other packing choices include subtraction, transformation and an uncompressed value. Decode the selected operation rather than inferring it from the number of bytes. Resolve the correct slot key or enumeration index before applying a delta.
Require a trusted reconstruction boundary
A delta stream requires the right preceding state. Starting from an arbitrary later batch without its initial slot values produces plausible but incorrect results. Verify reconstructed state commitments against the appropriate batch records. docs.zksync.io ZKsync documentation