Skip to content

Compressed clvm

Richard Kiss edited this page Jun 13, 2024 · 4 revisions

CLVM compression works roughly like this:

  • Given a clvm tree, calculate the sha256tree hash for each node.
  • Start to serialize.
  • At each node to be serialized, check to see if it's been serialized by looking at the sha256tree cache.
  • If in the cache, check to see if it's shorter to serialize by memoizing. If the regular serialization is longer than a few bytes, memoizing is usually better. Write a 0xfe byte followed by a path in the partial-serialization tree to the previously serialized clvm.
  • Otherwise, serialize the old way.
  • Repeat until done.

Implementation:

https://github.com/Chia-Network/clvm_rs/blob/main/src/serde/ser_br.rs#L28

See also https://gist.github.com/richardkiss/86f8ba4a04f4eb6b44234f014daa3d31

Clone this wiki locally