FrontierMerkleTree

scalus.crypto.tree.FrontierMerkleTree
See theFrontierMerkleTree companion object

Frontier-based append-only Merkle tree.

Stores only D sibling hashes (the "frontier") instead of the full tree, giving O(D) memory regardless of how many elements have been inserted. Supports depths up to 256, enabling trees with up to 2^256 leaf slots.

Produces identical root hashes and append proofs as IncrementalMerkleTree for the same key sequence. On-chain IncrementalMerkleTree.append() and verifyMembership() work unchanged with proofs from this tree.

Membership proofs require an external element source — see proveMembership.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

Append a new key to the next available slot.

Append a new key to the next available slot.

Returns (newTree, appendProof) where appendProof is D * 32 bytes of sibling hashes (bottom-up), compatible with on-chain IncrementalMerkleTree.append().

Attributes

def capacity: BigInt

Total number of leaf slots: 2^depth.

Total number of leaf slots: 2^depth.

Attributes

Generate an append proof for the next empty slot (D * 32 bytes).

Generate an append proof for the next empty slot (D * 32 bytes).

This is equivalent to the proof returned by the next append() call, without actually performing the append.

Attributes

def proveMembership(slot: BigInt, getElement: BigInt => ByteString, cache: SubtreeHashCache = ...): ByteString

Generate a membership proof for the element at the given slot.

Generate a membership proof for the element at the given slot.

Since the frontier tree does not store the full tree, an external element source is required. The getElement function must return the original key at each slot index (0 until size).

Returns D * 33 bytes: D repetitions of (direction[1] + sibling[32]), compatible with on-chain IncrementalMerkleTree.verifyMembership().

Value parameters

cache

optional cache for subtree hashes; reuse across multiple proofs for O(D) per proof after the first O(N) warmup

getElement

function returning the original key at a given slot index

slot

the leaf slot to prove (0 until size)

Attributes

Concrete fields

val depth: Int
val size: BigInt