Overview
ProofLevel<N> represents one level of an N-ary Merkle inclusion proof. It contains the child position and sibling hashes needed to reconstruct the parent hash at that level.
Type Definition
Generic Parameters
The branching factor (arity) of the tree. Determines the size of the
siblings array. At most N-1 siblings are valid.Fields
Child position within the group (
0..N-1). Indicates which child in the parent’s group is on the path from leaf to root.Number of valid siblings in the
siblings array. A value of 0 indicates a lifted node (a node that was promoted directly to the next level without siblings).Sibling hashes. Only the first
sibling_count elements are valid. A Hash is a 32-byte array ([u8; 32]).The sibling at position is omitted (it’s the hash being proven). Siblings before position are stored first, then siblings after position.Derive Traits
DebugCloneCopyPartialEqEqwincode::SchemaWrite(withwincodefeature)wincode::SchemaRead(withwincodefeature)serde::Serialize(withserdefeature)serde::Deserialize(withserdefeature)
Understanding the Structure
Fixed-Size Array
Thesiblings array has a fixed size of N elements, but only the first sibling_count elements are valid. This design:
- Avoids dynamic allocation
- Enables stack storage
- Supports efficient serialization
Sibling Layout
For a group withsibling_count + 1 children total, where the proven child is at position:
Lifted Nodes
Whensibling_count == 0, the node has no siblings and is “lifted” directly to the next level:
Examples
Binary Tree (N=2)
Ternary Tree (N=3)
Lifted Node in Binary Tree
Verification Process
During verification, each level reconstructs the parent hash:- Lifted node (
sibling_count == 0): The hash passes through unchanged - Normal node (
sibling_count > 0):- Create a children array of size
sibling_count + 1 - Place siblings before and after the proven hash
- Hash all children to get the parent hash
- Create a children array of size
Memory Layout
For aProofLevel<N> struct:
position: 1 bytesibling_count: 1 bytesiblings: 32 × N bytes- Total: 2 + 32N bytes
ProofLevel<2>: 66 bytesProofLevel<3>: 98 bytesProofLevel<4>: 130 bytesProofLevel<8>: 258 bytes
Serialization
With wincode feature
The entire fixed-size array is serialized, including unused slots. This is efficient for binary formats.
With serde feature
The serde feature uses serde_with to serialize the fixed-size array. The entire array is serialized.
Validation Rules
Valid proof levels must satisfy:position < Nsibling_count < N(at most N-1 siblings)position < sibling_count + 1(position must be within the group)- If
sibling_count == 0, the node is lifted (no validation of siblings)
NaryProof::verify.
Related Types
ConsistencyLevel
For consistency proofs, a similar structure exists:See Also
- NaryProof - Contains an array of ProofLevels
- ConsistencyProof - Uses ConsistencyLevel instead
- TreeSnapshot - Generates proofs containing ProofLevels
