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’sAccountHash.
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
lenbytes. - 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’sAccountHash. - subtree_
hash - Hash of the subtree at
depthfor sorted leaves that share their firstdepthnibbles: 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
leafwith keykeyis in the tree with rootroot. - walk_
from - Inner nodes from
depthdown to the slot ofkey, for sorted leaves that share the key’s firstdepthnibbles, and the leaf in that slot: the key’s own, another key’s (which proves the key absent), or none.