Module canopy

Module canopy 

Source
Expand description

Canopy is way to cache the upper N levels of a SPL ConcurrentMerkleTree.

By caching the upper N levels of a depth D SPL ConcurrentMerkleTree, proofs can be truncated to the first D - N nodes. This helps reduce the size of account compression transactions, and makes it possible to modify trees up to depth 31, which store more than 1 billion leaves.

Note: this means that creating a tree of depth > 24 without a canopy will be impossible to modify on-chain until TransactionV2 is launched.

To initialize a canopy on a ConcurrentMerkleTree account, you must initialize the ConcurrentMerkleTree account with additional bytes. The number of additional bytes needed is (pow(2, N+1)-1) * 32, where N is the number of levels of the merkle tree you want the canopy to cache.

The canopy will be updated everytime the concurrent merkle tree is modified. No additional work needed.

Functionsยง

check_canopy_bytes
fill_in_proof_from_canopy
update_canopy