pub enum Node<'a> {
Soft(Cell<'a>),
Hard(Cell<'a>, Cell<'a>),
}
Expand description
The only component of monotree
. In a big picture, monotree
simply consists of structured Node
s.
Schematic
There are two types of Node
– Soft node and Hard node.
- Hard: a node that has two real cells as components. two links to child nodes.
- Soft: a node that has only one real cell and it has only one link going out to child node.
// Root
// / \
// NodeA NodeB
// / \ \
// NodeC LeafB LeafC
// /
// LeafA
where NodeA is a Hard node, NodeB and NodeC are Soft nodes.
Byte-Serialized View
Numbers in parentheses refer to byte length.
By default HashLen = 32
, BitsLen = 2
.
SoftNode = Cell
+ 0x00
(1), where
Cell
= hash
(HASH_LEN
) + path
(< HASH_LEN
) + range_start
(BitsLen
) + range_end
(BitsLen
).
0x00
is an indicator for soft node.
HardNode = Cell_L
+ Cell_R
+ 0x01
(1), where
Cell_L
= hash_L
(HASH_LEN
) + path_L
(< HASH_LEN
) + range_L_start
(BitsLen
) + range_L_end
(BitsLen
)
Cell_R
= path_R
(< HASH_LEN
) _ range_R_start
(BitsLen
) + range_R_end
(BitsLen
) + hash_R
(HASH_LEN
).
0x01
is an indicator for hard node.
To make Merkle proof easier, we purposely placed the hashes on outskirts of the serialized form.
With only 1-bit information of left or right, provers can easily guess
which side the hash he holds should be appended for the next step.
Refer to verify_proof()
implementation regarding on this discussion.