Skip to main content

Module shamap

Module shamap 

Source
Expand description

The ledger transaction tree (SHAMap) and inclusion proofs.

A SHAMap is a tree with fan-out 16 over a 256-bit key: at depth d the branch is chosen by the d-th nibble of the key. A leaf sits at the depth where it becomes the only one in its subtree. The root is always an inner node.

Hashes, as in xrpld:

  • transaction-with-metadata leaf: SHA-512Half(SND\0, VL(tx), VL(meta), key);
  • inner node: SHA-512Half(MIN\0, 16 child hashes; zeros for an empty one);
  • transaction key: its hash, SHA-512Half(TXN\0, tx);
  • state object leaf: SHA-512Half(MLN\0, object, key); the state tree is built the same way, and its root is the header’s AccountHash.

The transaction tree root is stored in the ledger header (TransactionHash), and the header hash is the ledger hash that validators sign. So the path from a leaf to the root ties the transaction to the network’s signatures.

Structs§

Path
Path from the root to a leaf: the children of each inner node on the way, top down. The slot of the branch taken holds the hash of the node below, or of the leaf itself.

Functions§

encode_vl
XRPL length prefix (VL) for len bytes.
has_duplicates
Whether the leaves contain a duplicate key: such a set has no tree.
prove
Path to the leaf with key key, if there is such a leaf.
root
Tree root from leaves (key, leaf hash). An empty tree is zeros.
state_leaf_hash
Hash of a state object leaf: SHA-512Half(MLN\0, object, key). The root of a tree of such leaves is the ledger header’s AccountHash.
subtree_hash
Hash of the subtree at depth for sorted leaves that share their first depth nibbles: zeros if empty, the leaf itself if alone, else an inner node.
tx_id
Transaction hash: its identifier and its key in the tree.
tx_leaf_hash
Hash of a “transaction with metadata” leaf.
verify
The path checks out: leaf leaf with key key is in the tree with root root.
walk_from
Inner nodes from depth down to the slot of key, for sorted leaves that share the key’s first depth nibbles, and the leaf in that slot: the key’s own, another key’s (which proves the key absent), or none.

Type Aliases§

Hash