This section constructs the commitment on which the FlyClient protocol and the chain-history commitment of ZIP 221 rest: a binary hash tree over a sequence of values whose shape is fixed by the length of the sequence, extended by one value at logarithmic cost, and opened at one position by a path from which the root over the prefix of length is recomputed, and, under the right fold, also the root over the prefix of length . The construction is parametrised by the order in which its perfect subtrees are joined: the right fold of ePrint 2019/226 and the left fold of ZIP 221, “Background”. The fixed-depth trees of the Crypto Guide, §“Binary Merkle trees” and §“Append-only and incrementally updatable trees”, are the special case of a sequence whose length is a power of two.
Throughout, is a hash function drawn from a family that is collision resistant in the sense of the Crypto Guide, Definition “Collision resistance” (§“Security notions: preimage, second-preimage, and collision resistance”); ePrint 2019/226, Definition 8, states the same assumption. A statement holds barring a collision when a deterministic procedure, given any input on which the statement fails, outputs two distinct strings with equal images under , using the number of evaluations of stated with it. Such a procedure is a tight reduction in the sense of the Crypto Guide, Definition “Reduction loss and tightness” (§“Reductions”), so a probabilistic polynomial-time adversary makes the statement fail with negligible probability.
Let and . The Merkle mountain range over is the rooted ordered binary tree, every internal node of which has exactly two children, a left and a right one, with a value in at every node, defined by recursion on :
if , is the single leaf with value ;
if , let , so that and is the largest power of two strictly below ; the root has as left child the range over and as right child the range over , where .
Every internal node with children of values and has value , the image of the -bit concatenation of its children’s values. The leaves are ordered from left to right and leaf holds . The root is the value of the root node; range abbreviates Merkle mountain range.
The depth of a node is the number of edges from the root to it, and the depth of a tree the maximal depth of a leaf. A perfect subtree of altitude is a subtree with leaves, all at depth below its root; its root node has altitude . The right spine is the sequence of nodes that starts at the root and continues from each internal node to its right child, ending at a leaf.
ZIP 221, “Terminology”, calls a Merkle mountain range a binary hash tree that admits appends of new leaves without changing the value of existing nodes; Theorem 3.11 and Proposition 3.12 below establish it for Definition 3.1 for the peaks and every node beneath them. An append rehashes only the right-spine nodes above the first perfect one, the counterparts of the bagging nodes of ZIP 221, “Background”. Definition 3.1 is ePrint 2019/226, Definition 11, with the base case , implicit there, made explicit. Every node of is the root of a range over a run of consecutive values, by the recursion. Its depth is fixed in Lemma 3.2.
Let .
A range over values is a perfect subtree of altitude .
Every left child in is perfect: the left child of a node over leaves is the perfect range over leaves.
Descend the right spine of from the root, stopping at the first node whose leaf count is a power of two. The left children of the nodes passed, followed by the node where the descent stops, are perfect subtrees of pairwise distinct power-of-two sizes, decreasing from the root downwards, covering consecutive runs of leaves from left to right; their sizes are the terms of the binary expansion of .
The range has depth exactly , which is for .
(1) By induction on . For the range is a leaf. For , , so the root has two children over values each, perfect of altitude by hypothesis; all leaves lie at depth .
(2) Every node over leaves is a range , whose left child is a range over values, perfect by (1).
(3) Let a right-spine node have leaves. If is a power of two, the node is perfect by (1) and the descent stops. Otherwise , hence and : the left child takes the highest term of the binary expansion of and the right child the remaining terms. By induction along the spine, the left children passed take the terms of the expansion of from the highest downwards, and the descent stops when one term is left. The runs are consecutive because each left child precedes its sibling’s leaves.
(4) By induction on . For the depth is . For let . The left child is perfect over leaves, of depth ; the right child has leaves and depth by hypothesis. The depth of is therefore , which equals since . □
For , and . The left child is the perfect range over ; the right child has two leaves, is perfect, and has value ; hence . For , and ; the three-leaf right child splits as , so and
For , is the number of ones in the binary expansion of .
Let and write with , so that , and let for . The peaks of the sequence are , where is the perfect range over , of altitude . There is one peak per set bit of , of altitude that bit’s index; the altitudes strictly decrease from the left, and the peaks cover consecutive runs of leaves. The symbol denotes both the subtree and its root value.
The peaks are the mountains of ZIP 221, “Background”, whose leftmost peak is the highest. The same section numbers nodes in the order of their creation; that numbering enters no committed value and no check, and the root is a function of the leaf sequence and the bagging order of Definition 3.5 alone. No node numbering is used in this volume.
Let be the peaks of . The right fold and the left fold of the peaks are
a single peak is its own bag under either fold. The left fold is the order of ZIP 221, “Background”, which repeatedly joins the two leftmost peaks. For the tree consists of the perfect peak subtrees joined by the internal bagging nodes of , and is its root value. Both are determined by , and the leaf sequence.
For every the peaks of are exactly the left children of the right-spine nodes of , from the root down to the first perfect right-spine node, followed by that node. Hence and .
By Lemma 3.2(3) the nodes named are perfect subtrees whose sizes are the terms of the binary expansion of , largest first, covering consecutive runs of leaves from the left: they are in order. Along the spine, the -th node passed has value with the value of the next spine node, and the last spine node considered is ; unwinding gives the right fold. □
Let have peaks of altitudes , let , and let leaf lie in . The depth of leaf in is
Consequently the depth of is ; the depth of is , attained by the leaves of ; and the two depths differ exactly when . For they are and ; for they are and . Leaf depths are functions of ; for they are not all equal.
The leaf lies at depth below the root of ; it remains to find the depth of that root in the bag. Under the -th bagging node lies at depth and has left child for , and the last bagging node has right child ; so lies at depth for and at depth . Under the root has right child and left child , and inductively lies at depth for while shares depth with ; for the single peak lies at depth .
Maxima. Under , gives and ; the maximum is for and for , which is in both cases, as is a power of two exactly when . Under , for , , so the maximum is , attained by ; with and this is the stated value and bound. The maxima and coincide for , both equal for , and differ for . For a leaf of and a leaf of differ in depth under ( against at most ), and a leaf of and a leaf of under (). □
A cycle of is a value and a nonempty sequence of evaluations of that, starting from inputs that include , recomputes .
Let have peaks. The shapes and coincide if and only if . For :
the roots and are distinct hash expressions over the same peaks, and from values of the peaks for which a collision or a cycle of is computed;
for every leaf , the sequence of sides of the siblings on leaf ’s path above its peak differs between and ;
the peaks and the perfect subtrees beneath them coincide, and so do the asymptotic costs of append, of storage of the peaks and of a path, each logarithmic in ; the leaf depths differ as in Lemma 3.7, so the bound on the path length of ePrint 2019/226 does not hold for .
Definition 3.1 splits with the first peak on the left and recurses on the rest, which is the right fold (Proposition 3.6). For both folds are and for both are . For the root’s left child is under and a bagging node under , so the shapes differ.
(1) The root inputs are and . If the root values agree and these -bit strings differ, they are a collision. Otherwise and , each a value recomputed from itself by evaluations of : a cycle.
(2) Above the path has under the single sibling and under the siblings . Above it has under the siblings and under the single sibling . Above with the first sibling is on the right under , namely , and on the left under , namely .
(3) Both trees are built on the peaks of Definition 3.4, which depend on the leaf sequence alone; there are of them. Appending joins the last peaks of equal altitude with , at most evaluations of , and re-bagging the at most new peaks costs one evaluation fewer than their number, under either fold. A path has at most siblings under either fold by Lemma 3.7, whose depths are the stated ones. □
Collision resistance alone does not exclude a cycle, so part (1) does not assert that the two roots differ numerically. No later statement of this volume uses such an inequality; the later sections use the shapes and path lengths of part (2) and Lemma 3.7.
Every node of a range carries its leaf count . Procedure takes the root of a range over leaves and a value and returns the root of a range over leaves:
if is a power of two ( is perfect; included), return a new node with left child , right child the leaf , value and leaf count ;
otherwise, with children and , replace by , set the value of to with the new , set its leaf count to , and return .
The construction is ePrint 2019/226, Algorithm 5. The order in step 1 is that of the algorithm and of Definition 3.1; the base case of the paper’s proof of its Theorem 6 writes the reverse order.
For , is over : the leaves of followed by as the rightmost leaf.
By induction on , following ePrint 2019/226, Theorem 6. If , Definition 3.1 for has and right part : left child , right child the leaf , which is step 1. Otherwise with , and with the same , since . The left child is unchanged, and the right child is applied to the range over , which is over by hypothesis; step 2 rehashes the root. □
Procedure creates or rehashes only right-spine nodes of and one new node, with at most evaluations of . Every left child of , and the perfect right-spine node at which the recursion stops, is a subtree of with unchanged values.
The recursion descends the right spine until the first node whose leaf count is a power of two, at depth at most (Lemma 3.2(4)), evaluates once to create the new node, and once more at each spine node above it. Left children and the node where the descent stops are never modified. □
Figure 1 shows the case : two evaluations of create and .
Let , , , and (Lemma 3.7). Let be the nodes from leaf to the root of . The inclusion path of leaf is , where is the value of the sibling of , listed bottom-up. The side records whether that sibling is the left or the right child of . The sides and are functions of through the shape of .
The verifier , on and a sequence of -bit values:
rejects unless ;
sets and, for , if and otherwise;
accepts if and only if .
By construction accepts with the inclusion path of leaf against . Under every path has at most siblings (Lemma 3.7); ePrint 2019/226, Definition 10, counts at most hashes, the leaf pair included. For , path lengths differ between leaves (Lemma 3.7). The paper’s Algorithm 4 requires and so rejects valid paths: of the leaf paths of the ranges , , among them both leaves of and leaf of . The verifier above fixes the length from instead. For a power of two, is a perfect tree, and the inclusion path and its verifier coincide with the Crypto Guide’s Definition “Authentication path” and Definition “Path verification” (§“Authentication paths and membership proofs”) at index , with the bits fixed by instead of carried in the path.
For , from and the inclusion path of leaf in a verifier computes and, for , , the roots of the ranges over and .
For , by induction on , following ePrint 2019/226, Theorem 7, with siblings bottom-up. If , is the recomputed root . Otherwise ; let be the largest power of two strictly below , so that the root’s children are and a range over values.
If , is the value of the root’s left child, which is .
If , the path without its top sibling is the inclusion path of leaf in the left child , and the hypothesis applies.
If , then and , so is also the largest power of two strictly below . The top sibling is , the value of , and the path without it is the inclusion path of leaf in the right child; by hypothesis it yields the root over , and by Definition 3.1.
For , the bottom-up fold of Lemma 3.15, whose proof does not use this theorem. The paper’s proof lists the path top-down with the path nodes included, while its Algorithm 3 outputs the siblings bottom-up; the bottom-up format of Definition 3.13 is the one fixed here. □
Let , , and consider the inclusion path of leaf in . Its left siblings are subtrees whose leaf runs partition , higher siblings covering earlier leaves; its right siblings cover and enter none of the folds below. Let and let leaf lie in peak .
Under the left siblings, from the top down, are the peaks of . The bottom-up fold (set to the lowest left sibling, then for each further left sibling upwards) yields ; started instead from and applied to every left sibling, it yields .
Under , for the topmost left sibling is and the others lie in , with sizes the terms of the binary expansion of ; for all left siblings lie in . The top-down fold (set to the topmost left sibling, then for each further left sibling downwards) yields .
A leaf leaves the path of leaf at their lowest common ancestor, in whose left child lies; that left child is a left sibling on the path. Distinct ancestors give disjoint runs, higher ancestors earlier runs. The same argument for gives the right siblings. Inside a perfect subtree the left siblings of the leaf at offset from its first leaf are perfect subtrees whose sizes are the terms of the binary expansion of , largest highest.
Leaf lies at offset in , and , so the peaks of are followed by the left siblings inside , top-down. Under the siblings lie above as left children of bagging nodes (proof of Lemma 3.7); the bottom-up fold is then the right fold of the peaks of , which is by Proposition 3.6. Started from , it is the right fold of those peaks followed by . The largest power of two strictly below is the highest term of , the size of the first of these peaks, and the recursion of Definition 3.1 on splits off the peaks of in turn and ends at the single leaf ; this fold is therefore . Under with the root of is the right child of the bagging node , and every higher node on the path is a left child; the top-down fold is the left fold of the peaks of . For the root of is a left child and every higher node on the path too. □
Correctness of the construction is Lemma 3.15. The construction corrects the printed pseudocode of ePrint 2019/226, Algorithm 6, which uses an undefined index, ends in a vestigial boolean comparison, and has a call signature that does not match its call in Algorithm 2, and it fixes the siblings bottom-up.
Let , and . From any , chosen by the adversary, and two pairs both accepted by , a collision of is computed with at most evaluations of . In particular yields a collision, and the siblings of an accepted path and every value it recomputes are functions of , barring a collision.
Both chains and of Definition 3.13 have the length and the sides fixed by , and . Since , some step has differing inputs; let be the highest step with . Then : for both equal , and for the inputs of step agree. The two -bit inputs of step place their operands on the same sides and differ, and maps both to : a collision. For the path is empty and accepts only , so no two distinct pairs are accepted. The extractor is deterministic and the reduction tight in the sense of the Crypto Guide, §“Reductions”; it is the first-level-of-agreement argument of the Crypto Guide, Proposition “Binding of the root” (§“Binary Merkle trees”) and §“Soundness: forging a path implies a collision”. □
The theorem extends the Crypto Guide’s Theorem “Merkle trees are succinct position-binding vector commitments” (§“Vector commitments”) from perfect trees to the shapes fixed by and the bagging order. It is stated for a root chosen by the adversary, not for a fixed honest root as in the Crypto Guide’s Remark “Scope: a fixed honest root”: in FlyClient the root of the head comes from the prover.
Let and .
If over and accepts at position , then and, for , over , barring a collision: one accepted path binds as a prefix of the committed sequence.
If differs from at some , then , barring a collision: changing changes every root with .
When is the hash of block , binding the blocks themselves requires in addition collision resistance of that hash.
(1) The honest pair is accepted. By Theorem 3.17 the pairs and are equal barring a collision, so and the fold of Construction 3.16 on is the fold on , which is by Lemma 3.15. (2) The two trees have the same shape . The honest paths of leaf in both are accepted against the common root, with ; Theorem 3.17 yields a collision. □
Part (1) is ePrint 2019/226, Corollary 3, and part (2) its Corollary 4, stated for both bagging orders and with the collision named.
A verifier that samples leaves by cumulative weight needs each path to bind the sampled leaf’s weight interval, and a verifier that constrains unsampled leaves needs aggregates over their runs; both follow from metadata propagated up the tree (ePrint 2019/226, Section 2 and Section 6).
An aggregating range extends Definition 3.1, after ZIP 221, “Specification”, which propagates metadata “by either summing the metadata of both children, or inheriting the metadata of a specific child”. It is given by:
a set of node tuples with ;
a serialisation from tuples to bit strings that is injective and prefix-free, no value of being a proper prefix of another, so that determines the pair ;
a leaf map from a leaf’s data to its tuple;
for each field one rule: inherit from the left child, inherit from the right child, or sum, in or in ;
the parent map , whose hash field is , over the children’s full serialisations, and whose other fields follow the rules.
A labelling of the shape with leaf tuples at the leaves is consistent when every internal node is of its children; its root is the root’s tuple. Inclusion paths and are those of Definition 3.13 with tuples in place of values and in place of ; accepts if and only if the recomputed root tuple equals the given one.
A serialisation of fixed width is prefix-free. Injectivity alone does not suffice: with , and , the pairs and have the same concatenation .
Let be injective and prefix-free, and .
From two consistent labellings of with equal root tuples that differ at some node, a collision of is computed; barring a collision, equal roots imply agreement on every field of every node.
From any root tuple, chosen by the adversary, and two distinct accepted paths (leaf tuple and sibling tuples) at one position , a collision of is computed: an accepted path binds the full tuple of every node it recomputes and of every sibling it carries.
For and the inclusion path of leaf in a consistent labelling, the folds of Lemma 3.15 run with in place of yield the root tuple of the consistent labelling of over the first leaf tuples.
Unique decoding: if , one of , is a prefix of the other, hence they are equal, and by injectivity; then and .
(1) Take a node at which the labellings differ and whose parent they agree on; one exists because they agree at the root. The parent tuples are equal, so their hash fields are, while the child pairs differ; by unique decoding the two hash inputs differ: a collision.
(2) As in the proof of Theorem 3.17, with tuples: at the highest step whose inputs differ, the outputs are equal tuples, hence have equal hash fields, and the inputs are distinct pairs, hence by unique decoding distinct strings: a collision.
(3) In a consistent labelling the tuple of every subtree, a bagging node included, is determined by its leaf tuples through . By Lemma 3.15 the left siblings are, under , the peak tuples of the consistent labelling over the first leaves, and so are they under with . Under with , the topmost is the tuple of the bagging node of that labelling, and the others are its peak tuples inside . The folds of that lemma, run with , therefore yield the root tuple of . The engine of (1) and (2) is the Crypto Guide, Proposition “Binding of the root” (§“Binary Merkle trees”). □
Let be injective and prefix-free, let be a summed field, the -field of the tuple of leaf , and the sum of the -fields of the left siblings on an accepted path of leaf .
Binding, for any root tuple chosen by the adversary: barring a collision, and are functions of the root, , and . One accepted path therefore binds the interval of leaf .
Meaning, for the path of a consistent labelling: , under either bagging order. For a sum taken modulo , this holds as an identity of integers when the sum of over all leaves is below .
Part (2) is not claimed for a root chosen by the adversary, whose siblings off the path are never recomputed from their children.