1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! This module defines the types of a binary merkle trie, generalized over a 256 bit hash function.
//! All lookup paths in the trie are 256 bits.
//!
//! All nodes are 256 bits. There are three kinds of nodes.
//! 1. Internal nodes, which each have two children. The value of an internal node is
//! given by hashing the concatenation of the two child nodes and setting the MSB to 0.
//! 2. Leaf nodes, which have zero children. The value of a leaf node is given by hashing
//! the concatenation of the 256-bit lookup path and the hash of the value stored at the leaf,
//! and setting the MSB to 1.
//! 3. [`TERMINATOR`] nodes, which have the special value of all 0s. These nodes have no children
//! and serve as a stand-in for an empty sub-trie at any height. Terminator nodes enable the
//! trie to be tractably represented.
//!
//! All node preimages are 512 bits.
use crateNodeHasher;
/// A node in the binary trie. In this schema, it is always 256 bits and is the hash of either
/// an [`LeafData`] or [`InternalData`], or zeroed if it's a [`TERMINATOR`].
///
/// [`Node`]s are labeled by the [`NodeHasher`] used to indicate whether they are leaves or internal
/// nodes. Typically, this is done by setting the MSB.
pub type Node = ;
/// The path to a key. All paths have a 256 bit fixed length.
pub type KeyPath = ;
/// The hash of a value. In this schema, it is always 256 bits.
pub type ValueHash = ;
/// The terminator hash is a special node hash value denoting an empty sub-tree.
/// Concretely, when this appears at a given location in the trie,
/// it implies that no key with a path beginning with the location has a value.
///
/// This value may appear at any height.
pub const TERMINATOR: Node = ;
/// Whether the node hash indicates the node is a leaf.
/// Whether the node hash indicates the node is an internal node.
/// Whether the node holds the special `EMPTY_SUBTREE` value.
/// The kind of a node.
/// The data of an internal (branch) node.
/// The data of a leaf node.