The Zcash ArboretumThe Complete Arboretum PDF

3 Merkle mountain ranges

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 j by a path from which the root over the prefix of length j−1 is recomputed, and, under the right fold, also the root over the prefix of length j. 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, H:{0,1}∗→{0,1}κ 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 H, using the number of evaluations of H 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.

3.1 The recursive definition

Definition 3.1 (Merkle mountain range).

Let n≥1 and x1,…,xn∈{0,1}κ. The Merkle mountain range Mn over (x1,…,xn) 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 {0,1}κ at every node, defined by recursion on n:

  1. 1.

    if n=1, M1 is the single leaf with value x1;

  2. 2.

    if n>1, let i=⌊log2⁡(n−1)⌋, so that 2i<n≤2i+1 and 2i is the largest power of two strictly below n; the root has as left child the range M2i over (x1,…,x2i) and as right child the range Mn−2i over (x2i+1,…,xn), where 1≤n−2i≤2i.

Every internal node with children of values vℓ and vr has value H⁢(vℓ∥vr), the image of the 2⁢κ-bit concatenation of its children’s values. The leaves are ordered from left to right and leaf j holds xj. The root 𝗋𝗍n 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 a is a subtree with 2a leaves, all at depth a below its root; its root node v has altitude alt⁢(v)=a. 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 n=1, implicit there, made explicit. Every node of Mn is the root of a range over a run of consecutive values, by the recursion. Its depth is fixed in Lemma 3.2.

Lemma 3.2 (Left children are perfect).

Let n≥1.

  1. 1.

    A range over 2a values is a perfect subtree of altitude a.

  2. 2.

    Every left child in Mn is perfect: the left child of a node over m≥2 leaves is the perfect range over 2⌊log2⁡(m−1)⌋ leaves.

  3. 3.

    Descend the right spine of Mn 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 n.

  4. 4.

    The range Mn has depth exactly ⌈log2⁡n⌉, which is 0 for n=1.

Proof.

(1) By induction on a. For a=0 the range is a leaf. For a≥1, ⌊log2⁡(2a−1)⌋=a−1, so the root has two children over 2a−1 values each, perfect of altitude a−1 by hypothesis; all leaves lie at depth a.

(2) Every node over m≥2 leaves is a range Mm, whose left child is a range over 2⌊log2⁡(m−1)⌋ values, perfect by (1).

(3) Let a right-spine node have m leaves. If m is a power of two, the node is perfect by (1) and the descent stops. Otherwise 2⌊log2⁡m⌋<m, hence m−1≥2⌊log2⁡m⌋ and ⌊log2⁡(m−1)⌋=⌊log2⁡m⌋: the left child takes the highest term 2⌊log2⁡m⌋ of the binary expansion of m and the right child the remaining terms. By induction along the spine, the left children passed take the terms of the expansion of n 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 n. For n=1 the depth is 0. For n>1 let i=⌊log2⁡(n−1)⌋. The left child is perfect over 2i leaves, of depth i; the right child has n−2i≤2i leaves and depth ⌈log2⁡(n−2i)⌉≤i by hypothesis. The depth of Mn is therefore i+1, which equals ⌈log2⁡n⌉ since 2i<n≤2i+1. □

Example 3.3 (Six and seven leaves).

For n=6, i=⌊log2⁡5⌋=2 and 6=4+2. The left child is the perfect range P1 over x1,…,x4; the right child has two leaves, is perfect, and has value P2=H⁢(x5∥x6); hence 𝗋𝗍6=H⁢(P1∥P2). For n=7, i=⌊log2⁡6⌋=2 and 7=4+3; the three-leaf right child splits as 3=2+1, so 7=4+(2+1) and

𝗋𝗍7=H(P1∥H(H(x5∥x6)∥x7)).
Refer to caption
Figure 1: The range M6 over x1,…,x6 in single-rooted form (solid): the root 𝗋𝗍6 has left child P1, the perfect range over x1,…,x4, and right child P2=H⁢(x5∥x6), the perfect range over x5,x6. The nodes P1 and P2 are the peaks of Definition 3.4; P2 is the first perfect node on the right spine of M6, whose last node is the leaf x6. Dashed: appending x7 creates only the nodes H⁢(P2∥x7) and 𝗋𝗍7=H(P1∥H(P2∥x7)); the nodes P1, P2 and every node beneath them are shared by M6 and M7.

3.2 Peaks and bagging

For n≥1, popcount⁢(n) is the number of ones in the binary expansion of n.

Definition 3.4 (Peaks).

Let n≥1 and write n=2a1+⋯+2ad with a1>⋯>ad≥0, so that d=popcount⁢(n), and let si=∑l<i2al for 1≤i≤d. The peaks of the sequence (x1,…,xn) are P1,…,Pd, where Pi is the perfect range over (xsi+1,…,xsi+2ai), of altitude alt⁢(Pi)=ai. There is one peak per set bit of n, of altitude that bit’s index; the altitudes strictly decrease from the left, and the peaks cover consecutive runs of leaves. The symbol Pi 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.

Definition 3.5 (Bagging orders).

Let P1,…,Pd be the peaks of (x1,…,xn). The right fold and the left fold of the peaks are

BagR⁢(P1,…,Pd) =H(P1∥H(P2∥⋯H(Pd−1∥Pd)⋯)),
BagL⁢(P1,…,Pd) =H⁢(⋯⁢H⁢(H⁢(P1∥P2)∥P3)⁢⋯∥Pd);

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 b∈{R,L} the tree Mnb consists of the d perfect peak subtrees joined by the d−1 internal bagging nodes of Bagb, and 𝗋𝗍nb is its root value. Both are determined by n, b and the leaf sequence.

Proposition 3.6 (Peaks of the recursive form).

For every n≥1 the peaks of (x1,…,xn) are exactly the left children of the right-spine nodes of Mn, from the root down to the first perfect right-spine node, followed by that node. Hence Mn=MnR and 𝗋𝗍n=BagR⁢(P1,…,Pd).

Proof.

By Lemma 3.2(3) the nodes named are perfect subtrees whose sizes are the terms of the binary expansion of n, largest first, covering consecutive runs of leaves from the left: they are P1,…,Pd in order. Along the spine, the t-th node passed has value H⁢(Pt∥vt+1) with vt+1 the value of the next spine node, and the last spine node considered is Pd; unwinding gives the right fold. □

Lemma 3.7 (Path lengths under the two baggings).

Let n≥1 have peaks P1,…,Pd of altitudes a1>⋯>ad, let b∈{R,L}, and let leaf j lie in Pi. The depth depthb⁢(n,j) of leaf j in Mnb is

depthR⁢(n,j)={ai+ii<d,ad+d−1i=d,depthL⁢(n,j)={a1+d−1i=1,ai+d−i+1i≥2.

Consequently the depth of MnR is ⌈log2⁡n⌉; the depth of MnL is ⌊log2⁡n⌋+popcount⁢(n)−1≤2⁢⌊log2⁡n⌋, attained by the leaves of P1; and the two depths differ exactly when d≥3. For n=7 they are 3 and 4; for n=127 they are 7 and 12. Leaf depths are functions of (b,n,j); for d≥2 they are not all equal.

Proof.

The leaf lies at depth ai below the root of Pi; it remains to find the depth of that root in the bag. Under BagR the t-th bagging node lies at depth t−1 and has left child Pt for t≤d−1, and the last bagging node has right child Pd; so Pi lies at depth i for i<d and Pd at depth d−1. Under BagL the root has right child Pd and left child BagL⁢(P1,…,Pd−1), and inductively Pi lies at depth d−i+1 for i≥2 while P1 shares depth d−1 with P2; for d=1 the single peak lies at depth 0.

Maxima. Under R, ai≤a1−(i−1) gives ai+i≤a1+1 and ad+d−1≤a1; the maximum is a1+1 for d≥2 and a1 for d=1, which is ⌈log2⁡n⌉ in both cases, as n is a power of two exactly when d=1. Under L, for i≥2, ai+d−i+1≤a1+d−2⁢i+2≤a1+d−2, so the maximum is a1+d−1, attained by P1; with a1=⌊log2⁡n⌋ and d=popcount⁢(n)≤⌊log2⁡n⌋+1 this is the stated value and bound. The maxima a1+1 and a1+d−1 coincide for d=2, both equal a1 for d=1, and differ for d≥3. For d≥2 a leaf of P1 and a leaf of Pd differ in depth under R (a1+1 against at most a1), and a leaf of P1 and a leaf of P2 under L (a1≠a2). □

A cycle of H is a value v and a nonempty sequence of evaluations of H that, starting from inputs that include v, recomputes v.

Theorem 3.8 (Fold order).

Let n≥1 have d peaks. The shapes MnR and MnL coincide if and only if d≤2. For d≥3:

  1. 1.

    the roots 𝗋𝗍nR and 𝗋𝗍nL are distinct hash expressions over the same peaks, and from values of the peaks for which 𝗋𝗍nR=𝗋𝗍nL a collision or a cycle of H is computed;

  2. 2.

    for every leaf j, the sequence of sides of the siblings on leaf j’s path above its peak differs between MnR and MnL;

  3. 3.

    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 n; the leaf depths differ as in Lemma 3.7, so the bound ⌈log2⁡n⌉ on the path length of ePrint 2019/226 does not hold for MnL.

Proof.

Definition 3.1 splits n=2⌊log2⁡(n−1)⌋+(rest) with the first peak on the left and recurses on the rest, which is the right fold (Proposition 3.6). For d=1 both folds are P1 and for d=2 both are H⁢(P1∥P2). For d≥3 the root’s left child is P1 under R and a bagging node under L, so the shapes differ.

(1) The root inputs are P1∥BagR⁢(P2,…,Pd) and BagL⁢(P1,…,Pd−1)∥Pd. If the root values agree and these 2⁢κ-bit strings differ, they are a collision. Otherwise P1=BagL⁢(P1,…,Pd−1) and Pd=BagR⁢(P2,…,Pd), each a value recomputed from itself by d−2≥1 evaluations of H: a cycle.

(2) Above P1 the path has under R the single sibling BagR⁢(P2,…,Pd) and under L the d−1≥2 siblings P2,…,Pd. Above Pd it has under R the d−1≥2 siblings Pd−1,…,P1 and under L the single sibling BagL⁢(P1,…,Pd−1). Above Pi with 2≤i<d the first sibling is on the right under R, namely BagR⁢(Pi+1,…,Pd), and on the left under L, namely BagL⁢(P1,…,Pi−1).

(3) Both trees are built on the peaks of Definition 3.4, which depend on the leaf sequence alone; there are d≤⌊log2⁡n⌋+1 of them. Appending xn+1 joins the last peaks of equal altitude with xn+1, at most ⌊log2⁡n⌋+1 evaluations of H, and re-bagging the at most ⌊log2⁡(n+1)⌋+1 new peaks costs one evaluation fewer than their number, under either fold. A path has at most 2⁢⌊log2⁡n⌋ 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.

Example 3.9 (Eleven leaves).

The eleven-leaf tree of ZIP 221, “Background”, has 11=8+2+1 and peaks P1, P2, P3 of altitudes 3, 1 and 0, joined by two bagging nodes. The left fold that ZIP 221 commits and the right fold are

𝗋𝗍11L=H(H(P1∥P2)∥P3),𝗋𝗍11R=H(P1∥H(P2∥P3)).

A leaf of P1, P2, P3 has path length 4, 3, 2 under BagR and 5, 3, 1 under BagL. Figure 2 shows both trees.

Refer to caption
Figure 2: The eleven-leaf tree of Example 3.9, without node numbering. Both panels carry the same peaks P1, P2, P3 (blue) of altitudes 3, 1, 0 over the same leaves. Left: the left fold 𝗋𝗍11L=H⁢(H⁢(P1∥P2)∥P3) that ZIP 221 commits. Right: the right fold 𝗋𝗍11R=H(P1∥H(P2∥P3)) of the recursion of Definition 3.1. Bagging nodes are amber. The leaves of P1 lie one level deeper under the left fold; the depths below each panel are those of a leaf of P1, P2, P3.

3.3 Appending a leaf

Construction 3.10 (Append).

Every node v of a range carries its leaf count m. Procedure Append⁢(v,x) takes the root v of a range over m leaves and a value x∈{0,1}κ and returns the root of a range over m+1 leaves:

  1. 1.

    if m is a power of two (v is perfect; m=1 included), return a new node with left child v, right child the leaf x, value H⁢(v∥x) and leaf count m+1;

  2. 2.

    otherwise, with children vℓ and vr, replace vr by Append⁢(vr,x), set the value of v to H⁢(vℓ∥vr) with the new vr, set its leaf count to m+1, and return v.

The construction is ePrint 2019/226, Algorithm 5. The order H⁢(v∥x) 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.

Theorem 3.11 (Correctness of append).

For n≥1, Append⁢(Mn,xn+1) is Mn+1 over (x1,…,xn+1): the leaves of Mn followed by xn+1 as the rightmost leaf.

Proof.

By induction on n, following ePrint 2019/226, Theorem 6. If n=2i, Definition 3.1 for n+1 has ⌊log2⁡n⌋=i and right part 1: left child Mn, right child the leaf xn+1, which is step 1. Otherwise n=2i+m with 1≤m<2i, and n+1=2i+(m+1) with the same i, since m+1≤2i. The left child M2i is unchanged, and the right child is Append applied to the range Mm over (x2i+1,…,xn), which is Mm+1 over (x2i+1,…,xn+1) by hypothesis; step 2 rehashes the root. □

Proposition 3.12 (Cost of append).

Procedure Append⁢(Mn,xn+1) creates or rehashes only right-spine nodes of Mn and one new node, with at most ⌈log2⁡n⌉+1 evaluations of H. Every left child of Mn, and the perfect right-spine node at which the recursion stops, is a subtree of Mn+1 with unchanged values.

Proof.

The recursion descends the right spine until the first node whose leaf count is a power of two, at depth at most ⌈log2⁡n⌉ (Lemma 3.2(4)), evaluates H 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 n=6: two evaluations of H create H⁢(P2∥x7) and 𝗋𝗍7.

3.4 Inclusion paths and prefix roots

Definition 3.13 (Inclusion path).

Let b∈{R,L}, n≥1, 1≤j≤n, and m=depthb⁢(n,j) (Lemma 3.7). Let u0,u1,…,um be the nodes from leaf j to the root of Mnb. The inclusion path of leaf j is π=(π1,…,πm), where πt is the value of the sibling of ut−1, listed bottom-up. The side σt∈{left,right} records whether that sibling is the left or the right child of ut. The sides and m are functions of (b,n,j) through the shape of Mnb.

The verifier Verifyb⁢(𝗋𝗍,n,j,x,π), on 𝗋𝗍,x∈{0,1}κ and a sequence π of κ-bit values:

  1. 1.

    rejects unless |π|=depthb⁢(n,j);

  2. 2.

    sets y0=x and, for t=1,…,m, yt=H⁢(πt∥yt−1) if σt=left and yt=H⁢(yt−1∥πt) otherwise;

  3. 3.

    accepts if and only if ym=𝗋𝗍.

By construction Verifyb accepts (xj,π) with π the inclusion path of leaf j against 𝗋𝗍nb. Under BagR every path has at most ⌈log2⁡n⌉ siblings (Lemma 3.7); ePrint 2019/226, Definition 10, counts at most log2⁡n+1 hashes, the leaf pair included. For d≥2, path lengths differ between leaves (Lemma 3.7). The paper’s Algorithm 4 requires |π|=⌈log2⁡(n−1)⌉ and so rejects valid paths: 1,225 of the 8,384 leaf paths of the ranges Mn, 2≤n≤129, among them both leaves of M2 and leaf 5 of M6. The verifier above fixes the length from (b,n,j) instead. For n a power of two, Mnb 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 j−1, with the bits bt fixed by j instead of carried in the path.

Theorem 3.14 (Prefix roots from one path).

For 1≤j≤n, from xj and the inclusion path of leaf j in Mn a verifier computes 𝗋𝗍j and, for j≥2, 𝗋𝗍j−1, the roots of the ranges over (x1,…,xj) and (x1,…,xj−1).

Proof.

For 𝗋𝗍j, by induction on n, following ePrint 2019/226, Theorem 7, with siblings bottom-up. If j=n, 𝗋𝗍j=𝗋𝗍n is the recomputed root ym. Otherwise n>1; let 2i be the largest power of two strictly below n, so that the root’s children are M2i and a range over n−2i values.

  1. 1.

    If j=2i, 𝗋𝗍j is the value of the root’s left child, which is ym−1.

  2. 2.

    If j<2i, the path without its top sibling is the inclusion path of leaf j in the left child M2i, and the hypothesis applies.

  3. 3.

    If 2i<j<n, then j−1≥2i and j<2i+1, so 2i is also the largest power of two strictly below j. The top sibling is P, the value of M2i, and the path without it is the inclusion path of leaf j−2i in the right child; by hypothesis it yields the root r′ over (x2i+1,…,xj), and 𝗋𝗍j=H⁢(P∥r′) by Definition 3.1.

For 𝗋𝗍j−1, 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. □

Lemma 3.15 (Left siblings cover the prefix).

Let b∈{R,L}, 1≤j≤n, and consider the inclusion path of leaf j in Mnb. Its left siblings are subtrees whose leaf runs partition {1,…,j−1}, higher siblings covering earlier leaves; its right siblings cover {j+1,…,n} and enter none of the folds below. Let j≥2 and let leaf j lie in peak Pi.

  1. 1.

    Under BagR the left siblings, from the top down, are the peaks of (x1,…,xj−1). The bottom-up fold (set r to the lowest left sibling, then r←H⁢(π∥r) for each further left sibling π upwards) yields 𝗋𝗍j−1; started instead from r=xj and applied to every left sibling, it yields 𝗋𝗍j.

  2. 2.

    Under BagL, for i≥2 the topmost left sibling is BagL⁢(P1,…,Pi−1) and the others lie in Pi, with sizes the terms of the binary expansion of j−1−si; for i=1 all left siblings lie in P1. The top-down fold (set r to the topmost left sibling, then r←H⁢(r∥π) for each further left sibling π downwards) yields 𝗋𝗍j−1L.

Proof.

A leaf l<j leaves the path of leaf j at their lowest common ancestor, in whose left child l lies; that left child is a left sibling on the path. Distinct ancestors give disjoint runs, higher ancestors earlier runs. The same argument for l>j gives the right siblings. Inside a perfect subtree the left siblings of the leaf at offset o from its first leaf are perfect subtrees whose sizes are the terms of the binary expansion of o, largest highest.

Leaf j lies at offset o=j−1−si in Pi, and j−1=si+o, so the peaks of (x1,…,xj−1) are P1,…,Pi−1 followed by the left siblings inside Pi, top-down. Under R the siblings Pi−1,…,P1 lie above Pi as left children of bagging nodes (proof of Lemma 3.7); the bottom-up fold is then the right fold of the peaks of (x1,…,xj−1), which is 𝗋𝗍j−1 by Proposition 3.6. Started from xj, it is the right fold of those peaks followed by xj. The largest power of two strictly below j is the highest term of j−1, the size of the first of these peaks, and the recursion of Definition 3.1 on j splits off the peaks of j−1 in turn and ends at the single leaf xj; this fold is therefore 𝗋𝗍j. Under L with i≥2 the root of Pi is the right child of the bagging node H⁢(BagL⁢(P1,…,Pi−1)∥Pi), and every higher node on the path is a left child; the top-down fold is the left fold of the peaks of (x1,…,xj−1). For i=1 the root of P1 is a left child and every higher node on the path too. □

Construction 3.16 (Prefix root).

Procedure PrefixRootb⁢(n,j,π) takes b∈{R,L}, 2≤j≤n and a sequence π of κ-bit values with |π|=depthb⁢(n,j), with sides σt as in Definition 3.13. It selects the πt with σt=left and outputs their bottom-up fold for b=R and their top-down fold for b=L (Lemma 3.15).

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.

Theorem 3.17 (Position binding).

Let b∈{R,L}, n≥1 and 1≤j≤n. From any 𝗋𝗍∈{0,1}κ, chosen by the adversary, and two pairs (x,π)≠(x′,π′) both accepted by Verifyb⁢(𝗋𝗍,n,j,⋅,⋅), a collision of H is computed with at most 2⁢depthb⁢(n,j) evaluations of H. In particular x≠x′ yields a collision, and the siblings of an accepted path and every value it recomputes are functions of (𝗋𝗍,b,n,j), barring a collision.

Proof.

Both chains y0,…,ym and y0′,…,ym′ of Definition 3.13 have the length m=depthb⁢(n,j) and the sides fixed by (b,n,j), and ym=ym′=𝗋𝗍. Since (x,π)≠(x′,π′), some step has differing inputs; let t be the highest step with (yt−1,πt)≠(yt−1′,πt′). Then yt=yt′: for t=m both equal 𝗋𝗍, and for t<m the inputs of step t+1 agree. The two 2⁢κ-bit inputs of step t place their operands on the same sides and differ, and H maps both to yt: a collision. For n=1 the path is empty and Verifyb accepts only x=𝗋𝗍, 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 n 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.

Corollary 3.18 (Prefix binding and root sensitivity).

Let b∈{R,L} and 1≤j≤n.

  1. 1.

    If 𝗋𝗍=𝗋𝗍nb over (x1,…,xn) and Verifyb accepts (x,π) at position j, then x=xj and, for j≥2, PrefixRootb⁢(n,j,π)=𝗋𝗍j−1b over (x1,…,xj−1), barring a collision: one accepted path binds x1,…,xj as a prefix of the committed sequence.

  2. 2.

    If (x1′,…,xm′) differs from (x1,…,xm) at some i≤m, then 𝗋𝗍mb⁢(x′)≠𝗋𝗍mb⁢(x), barring a collision: changing xi changes every root 𝗋𝗍mb with m≥i.

When xi is the hash of block i, binding the blocks themselves requires in addition collision resistance of that hash.

Proof.

(1) The honest pair (xj,π∗) is accepted. By Theorem 3.17 the pairs (x,π) and (xj,π∗) are equal barring a collision, so x=xj and the fold of Construction 3.16 on π is the fold on π∗, which is 𝗋𝗍j−1b by Lemma 3.15. (2) The two trees have the same shape Mmb. The honest paths of leaf i in both are accepted against the common root, with xi≠xi′; 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.

3.5 Aggregating ranges

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).

Definition 3.19 (Aggregating range).

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:

  1. 1.

    a set of node tuples v=(v.𝗁,v.f1,…,v.fr) with v.𝗁∈{0,1}κ;

  2. 2.

    a serialisation ser from tuples to bit strings that is injective and prefix-free, no value of ser being a proper prefix of another, so that ser⁢(ℓ)∥ser⁢(r) determines the pair (ℓ,r);

  3. 3.

    a leaf map from a leaf’s data to its tuple;

  4. 4.

    for each field fi one rule: inherit from the left child, inherit from the right child, or sum, in ℤ or in ℤ/2256⁢ℤ;

  5. 5.

    the parent map par⁢(ℓ,r), whose hash field is H⁢(ser⁢(ℓ)∥ser⁢(r)), over the children’s full serialisations, and whose other fields follow the rules.

A labelling of the shape Mnb with leaf tuples at the leaves is consistent when every internal node is par of its children; its root is the root’s tuple. Inclusion paths and Verifyb are those of Definition 3.13 with tuples in place of values and par in place of H(⋅∥⋅); Verifyb 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 ser⁢(x)=0, ser⁢(y)=01 and ser⁢(z)=10, the pairs (x,z) and (y,x) have the same concatenation 010.

Lemma 3.20 (Aggregate binding).

Let ser be injective and prefix-free, b∈{R,L} and n≥1.

  1. 1.

    From two consistent labellings of Mnb with equal root tuples that differ at some node, a collision of H is computed; barring a collision, equal roots imply agreement on every field of every node.

  2. 2.

    From any root tuple, chosen by the adversary, and two distinct accepted paths (leaf tuple and sibling tuples) at one position j, a collision of H is computed: an accepted path binds the full tuple of every node it recomputes and of every sibling it carries.

  3. 3.

    For 2≤j≤n and the inclusion path of leaf j in a consistent labelling, the folds of Lemma 3.15 run with par in place of H(⋅∥⋅) yield the root tuple of the consistent labelling of Mj−1b over the first j−1 leaf tuples.

Proof.

Unique decoding: if ser⁢(ℓ)∥ser⁢(r)=ser⁢(ℓ′)∥ser⁢(r′), one of ser⁢(ℓ), ser⁢(ℓ′) is a prefix of the other, hence they are equal, and ℓ=ℓ′ by injectivity; then ser⁢(r)=ser⁢(r′) and r=r′.

(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 par. By Lemma 3.15 the left siblings are, under R, the peak tuples of the consistent labelling over the first j−1 leaves, and so are they under L with i≤2. Under L with i≥3, the topmost is the tuple of the bagging node BagL⁢(P1,…,Pi−1) of that labelling, and the others are its peak tuples inside Pi. The folds of that lemma, run with par, therefore yield the root tuple of Mj−1b. The engine of (1) and (2) is the Crypto Guide, Proposition “Binding of the root” (§“Binary Merkle trees”). □

Lemma 3.21 (Cumulative-weight interval of a leaf).

Let ser be injective and prefix-free, let w be a summed field, wj the w-field of the tuple of leaf j, and W the sum of the w-fields of the left siblings on an accepted path of leaf j.

  1. 1.

    Binding, for any root tuple chosen by the adversary: barring a collision, W and wj are functions of the root, b, n and j. One accepted path therefore binds the interval [W,W+wj) of leaf j.

  2. 2.

    Meaning, for the path of a consistent labelling: W=∑i<jwi, under either bagging order. For a sum taken modulo 2256, this holds as an identity of integers when the sum of w over all n leaves is below 2256.

Part (2) is not claimed for a root chosen by the adversary, whose siblings off the path are never recomputed from their children.

Proof.

(1) Lemma 3.20(2). (2) In a consistent labelling the summed field of a node is the sum over its leaves, by induction on height; with the total below 2256 no reduction occurs. The left siblings partition {1,…,j−1} by Lemma 3.15, a property of any binary tree. □

Two instances follow. The difficulty Merkle mountain range of ePrint 2019/226, whose nodes aggregate difficulty and time, is Definition 5.6 in §5.3. The node vector of ZIP 221, whose nodes aggregate work, heights and pool data, is Definition 6.3 in §6.3.