Skip to content

Compressed clvm

Richard Kiss edited this page May 29, 2024 · 5 revisions

CLVM compression works roughly like this:

  1. Given a clvm tree, calculate the sha256tree hash for each node.
  2. Start to serialize.
  3. At each node to be serialized, check to see if it's been serialized by looking at the sha256tree cache. 3a. 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. 3b. Otherwise, serialize the old way.
  4. Repeat until done.

Implementation:

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

Clone this wiki locally