Skip to content

Commit 425d0e1

Browse files
committed
comments for decompSubtreeProof
1 parent f65b26e commit 425d0e1

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

proof/verify.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,32 @@ func decompInclProof(index, size uint64) (int, int) {
250250
return inner, border
251251
}
252252

253-
// decompSubtreeProof returns the exact proof slice indices (subInner, inner,
254-
// and inner+subBorder) needed to reconstruct hash1.
253+
// decompSubtreeProof computes the exact proof slice indices needed to reconstruct
254+
// the [start, end) subtree root (hash1):
255+
// - subInner: end index of inner proof hashes inside the subtree (proof[:subInner])
256+
// - inner: start index of border proof hashes (proof[inner:])
257+
// - inner+subBorder: end index of border proof hashes inside the subtree
255258
func decompSubtreeProof(start, end, size uint64, border int) (int, int, int) {
259+
// xor trims the common prefix between the first and last entry. The bit len
260+
// of the result is the height of the subtree.
256261
h := bits.Len64((end - 1) ^ start)
262+
// Using a similar technique, we compute where paths to leaves |end-1| and
263+
// |size-1| diverge.
257264
forkLevel := bits.Len64((end - 1) ^ (size - 1))
265+
// Height of the rightmost full subtree within the argument subtree.
266+
// The proof starts at this level.
258267
shift := bits.TrailingZeros64(end - start)
259268

269+
// Number of inner proof nodes from level |shift| up to subtree height |h|
270+
// (clamped at |forkLevel|) that belong inside the [start, end) subtree.
260271
subInner := min(h, forkLevel) - shift
272+
// Total number of inner proof nodes between level |shift| and |forkLevel|.
261273
inner := forkLevel - shift
274+
// Number of border proof nodes above |forkLevel| and below subtree height |h|
275+
// that belong inside the [start, end) subtree.
262276
subBorder := max(0, border-bits.OnesCount64((end-1)>>uint(h)))
277+
// The proof slice indices needed to reconstruct hash1 are [0:subInner] for inner
278+
// chaining and [inner:inner+subBorder] for border chaining.
263279
return subInner, inner, inner + subBorder
264280
}
265281

0 commit comments

Comments
 (0)