Documentation ¶
Overview ¶
Package merkletree is a binary SHA256 Merkle tree.
The binary Merkle tree contains two types of nodes: leaves (type 0x00) and intermediate nodes (type 0x01).
The leaf hash is a hash of its data, prefixed by a zero byte: `SHA256(0x00 || leaf)`.
The intermediate hash is a hash of the child hashes, prefixed by a one byte: `SHA256(0x01 || left || right)`
Construction ¶
Solana consensus relies on deterministic construction of Merkle trees.
The "canoical" construction method arranges the tree into "layers" (identified by node distance to root), with the lowest layer always consisting of leaf nodes.
If the lowest layer contains more than one leaf, recursively construct upper layers of intermediate nodes that each hash a pair of two of the lower layer's nodes in order.
When any upper layer hashes an uneven amount of nodes, the last intermediate node shall hash the same lower node twice.
Index ¶
Constants ¶
const ( TypeLeaf = 0x00 TypeIntermediate = 0x01 )
One byte type prefix used as a hash domain.
Variables ¶
This section is empty.
Functions ¶
func HashIntermediate ¶
HashIntermediate returns the hash of an intermediate node.