View Source ProofOfReserves.MerkleSumTree (proof_of_reserves v0.1.0)
MerkleSumTree is a module that represents a Merkle Sum Tree. It is used to calculate a Proof of Liabilities. In this module, a Node struct can represent a leaf or a branch. But when a variable is named leaves, it refers to the lowest level of the tree.
Summary
Functions
build_merkle_tree builds a Merkle Sum Tree from a list of leaves. Returns an error if the number of leaves is not a power of 2.
get_leaves returns the leaves (the lowest level) of a tree.
get_tree_root returns the root of a tree if it is complete.
merkleize_one_level takes a list of nodes and combines them into a new list of nodes which will be half the size.
parse_tree parses a stream of serialized Node strings into a tree.
serialize_tree serializes a tree into a list of strings, where each string represents a node. This is a breadth first serialization, where each level is serialized in order.
verify_tree? rebuilds the entire tree and compares the root and the height of the tree.
Types
@type tree() :: [[ProofOfReserves.MerkleSumTree.Node.t()]]
Functions
@spec build_merkle_tree([ProofOfReserves.MerkleSumTree.Node.t()]) :: tree() | {:error, String.t()}
build_merkle_tree builds a Merkle Sum Tree from a list of leaves. Returns an error if the number of leaves is not a power of 2.
@spec get_leaves(tree()) :: [ProofOfReserves.MerkleSumTree.Node.t()]
get_leaves returns the leaves (the lowest level) of a tree.
@spec get_tree_root(tree()) :: {:ok, ProofOfReserves.MerkleSumTree.Node.t()} | {:error, String.t()}
get_tree_root returns the root of a tree if it is complete.
@spec merkleize_one_level([ProofOfReserves.MerkleSumTree.Node.t()]) :: [ ProofOfReserves.MerkleSumTree.Node.t() ]
merkleize_one_level takes a list of nodes and combines them into a new list of nodes which will be half the size.
parse_tree parses a stream of serialized Node strings into a tree.
serialize_tree serializes a tree into a list of strings, where each string represents a node. This is a breadth first serialization, where each level is serialized in order.
verify_tree? rebuilds the entire tree and compares the root and the height of the tree.