Skip to main content

Crate tari_jellyfish

Crate tari_jellyfish 

Source
Expand description

Jellyfish Merkle Tree for Tari.

§Hash schemes

Node hashing is selected by JmtHashScheme, passed explicitly to JellyfishMerkleTree::new and to every SparseMerkleProofExt::verify_* call. There is no default. A verifier takes the scheme from its authenticated context (e.g. the protocol version in a signed header), never from a proof, which carries no scheme tag.

SchemeDomain (name, version)Leaf labelInternal labelFirst crate version
JmtHashScheme::V1com.tari.jmt, 0"Leaf""Internal"6.0.1-pre.2

Earlier crate versions hashed leaf and internal nodes with the single label "Node". That scheme is not supported: no live root uses it. jmt_node_hash and jmt_node_hash2 still use the "Node" label but are general-purpose helpers (e.g. key derivation), independent of the scheme.

A store does not record its scheme: opening an existing store under a different scheme silently yields roots that verify under neither scheme.

A scheme never changes once released. A new scheme is a new variant with its own domain version and distinct leaf and internal labels, and callers gate it on their own protocol version.

§Encoding

Tree, node and proof types implement serde and borsh. The minicbor feature adds native minicbor Encode, Decode and CborLen impls with a compact array-based format, documented in src/cbor.rs. Proof types are validated on decode. Tree node types are not, for speed, and must only be decoded from trusted storage.

§Version pinning

command_merkle_root in a sidechain block header is built by the validator node and verified by tari_sidechain, so a build that links a different tari_jellyfish into each, or maps a protocol version to a different scheme in each, produces roots the other side rejects.

Structs§

Child
Each child of InternalNode encapsulates a nibble forking at this node.
ChildNibbles
Iterates the occupied nibbles of Children in ascending order.
Children
The children of an InternalNode, indexed by nibble (0 to 15, inclusive) and always in ascending nibble order.
DomainSeparatedBorshHasher
A domain-separated hasher that feeds the Borsh encoding of its input to the digest, so hashing is canonical.
InternalNode
Represents a 4-level subtree with 16 children at the bottom level. Theoretically, this reduces IOPS to query a tree by 4x since we compress 4 levels in a standard Merkle tree into 1 node. Though we choose the same internal node structure as that of Patricia Merkle tree, the root hash computation logic is similar to a 4-level sparse Merkle tree except for some customizations.
JellyfishMerkleTree
The Jellyfish Merkle tree data structure. See crate for description.
JmtHashDomain
A hashing domain instance
LeafKey
A leaf key (i.e. a complete nibble path).
LeafKeyBitIterator
An iterator over LeafKey that generates one bit for each iteration.
LeafKeyRef
A leaf key (i.e. a complete nibble path).
LeafNode
Leaf node, capturing the value hash and carrying an arbitrary payload.
Nibble
NibbleBitIterator
BitIterator iterates a nibble path by bit.
NibbleIterator
NibbleIterator iterates a nibble path by nibble.
NibbleOutOfRange
NibblePath
NibblePath defines a path in Merkle tree in the unit of nibble (4 bits).
NodeKey
The unique key of each node.
SortedLeafRootBuilder
Computes the root hash of the tree holding a set of leaves, from the leaves in strictly ascending key order, without storing the tree.
SparseMerkleInternalNode
SparseMerkleLeafNode
SparseMerkleProof
A proof that can be used to authenticate an element in a Sparse Merkle Tree given trusted root hash. For example, TransactionInfoToAccountProof can be constructed on top of this structure.
SparseMerkleProofExt
A more detailed version of SparseMerkleProof with the only difference that all the leaf siblings are explicitly set as SparseMerkleLeafNode instead of its hash value.
SparseMerkleRangeProof
Note: this is not a range proof in the sense that a range of nodes is verified! Instead, it verifies the entire left part of the tree up to a known rightmost node. See the description below.
StaleNodeIndex
Indicates a node becomes stale since stale_since_version.
TreeHash
TreeHashSizeError
TreeUpdateBatch
The nodes to write and the nodes made stale by one batch_put_value_set call.

Enums§

InternalNodeError
JmtHashScheme
The scheme used to hash JMT leaf and internal nodes, and so every root and proof.
JmtProofVerifyError
JmtStorageError
Error originating from underlying storage failure / inconsistency.
NibblePathError
Node
The concrete node type of [JellyfishMerkleTree].
NodeInProof
A sibling in a SparseMerkleProofExt.
NodeType
SortedLeafRootError
StaleTreeNode
A part of a tree that may become stale (i.e. need eventual pruning).
TreeNode

Constants§

MAX_NIBBLE_PATH_BYTES
The maximum number of bytes in a NibblePath.
MAX_NIBBLE_PATH_LEN
The maximum number of nibbles in a NibblePath, i.e. the nibble length of a LeafKey.
MAX_PROOF_SIBLINGS
The maximum number of siblings in a proof, i.e. the bit length of a LeafKey.
SPARSE_MERKLE_PLACEHOLDER_HASH

Traits§

IteratedLeafKey
Peekable
TreeStore
Implementers are able to read and write nodes to a tree store.
TreeStoreReader
Implementers are able to read nodes from a tree store.
TreeStoreWriter
Implementers are able to insert nodes to a tree store.

Functions§

jmt_node_hash
jmt_node_hash2
tari_hasher32
Returns a 32-byte TariDomainHasher for the domain M and the given label.

Type Aliases§

JmtHasher
ProofValue
TariDomainHasher
A DomainSeparatedBorshHasher over Blake2b with an output of OutSize bytes.
Version