Module skewed

A module with a skewed merkle tree implementation as described in https://medium.com/codechain/skewed-merkle-tree-259b984acc0c.

Description

A module with a skewed merkle tree implementation as described in https://medium.com/codechain/skewed-merkle-tree-259b984acc0c. This module implements a skewed merkle tree where value can be added/stacked via add/3, the time and memory it takes to create is linearly proportional to the number of values.

Data Types

hash()

hash() = binary()

skewed()

skewed() = #skewed{root = tree(), count = non_neg_integer()}

tree()

tree() = #leaf{hash = hash(), value = any()} | #empty{hash = hash()} | #node{hash = hash(), height = non_neg_integer(), left = tree(), right = tree()}

Function Index

add/3 Add/stack new value (leaf) on top and recalculate root hash.
count/1 get the number of leaves int he skewed tree.
hash_value/1 A commonly used hash value for skewed trees.
height/1 Get the height of the given skewed tree.
new/0 Create new empty skewed merkle tree.
new/1
root_hash/1 Gets the root hash of the given skewed tree.
verify/3 Verify will check that the HashToVerify is correctly in the tree with the provided, in order, lists of hashes (proof) and compare it to the RootHash.

Function Details

add/3

add(Value::any(), HashFun::function(), Skewed::skewed()) -> skewed()

Add/stack new value (leaf) on top and recalculate root hash.

count/1

count(Skewed::skewed()) -> non_neg_integer()

get the number of leaves int he skewed tree.

hash_value/1

hash_value(Value::any()) -> hash()

A commonly used hash value for skewed trees. This function will SHA256 hash the given value when it is binary. A convenience form detects non-binary forms and uses term_to_binary/1 to convert other erlang terms to a binary form. It is not recommended to use the non-binary form if the resulting trees or proofs are to be sent over a network.

height/1

height(Skewed::skewed()) -> non_neg_integer()

Get the height of the given skewed tree. This is a fast operation since the height was calculated on construction of the tree.

new/0

new() -> skewed()

Create new empty skewed merkle tree.

new/1

new(Hash::hash()) -> skewed()

root_hash/1

root_hash(Skewed::skewed()) -> hash()

Gets the root hash of the given skewed tree. This is a fast operation since the hash was calculated on construction of the tree.

verify/3

verify(HashToVerify::hash(), Hashes::[hash()], RootHash::hash()) -> boolean()

Verify will check that the HashToVerify is correctly in the tree with the provided, in order, lists of hashes (proof) and compare it to the RootHash.


Generated by EDoc