Skip to content

Commit 46afbf8

Browse files
committed
comments
1 parent 141d627 commit 46afbf8

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

testonly/reference_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ func refConsistencyProof(entries [][]byte, size2, size1 uint64, hasher merkle.Lo
104104

105105
// refSubtreeConsistencyProof returns the subtree consistency proof for the
106106
// subtree [start, end) in a Merkle tree with the given entries and size.
107-
// This is a reference implementation for cross-checking.
108-
func refSubtreeConsistencyProof(entries [][]byte, size, start, end uint64, hasher merkle.LogHasher, haveRoot1 bool) [][]byte {
107+
// This is a reference implementation based on the recursive algorithm from
108+
// the RFC to be used for cross-checking only.
109+
func refSubtreeConsistencyProof(start, end uint64, entries [][]byte, known bool, hasher merkle.LogHasher) [][]byte {
110+
size := uint64(len(entries))
109111
if start >= end {
110112
return nil
111113
}
@@ -116,7 +118,7 @@ func refSubtreeConsistencyProof(entries [][]byte, size, start, end uint64, hashe
116118
if start == 0 && end == size {
117119
// Record the hash of this subtree if it's not the root for which the proof
118120
// was originally requested (which happens when [start, end) is a full subtree).
119-
if !haveRoot1 {
121+
if !known {
120122
return [][]byte{refRootHash(entries[:size], hasher)}
121123
}
122124
return nil
@@ -130,14 +132,14 @@ func refSubtreeConsistencyProof(entries [][]byte, size, start, end uint64, hashe
130132
// subtree.
131133
case end <= split:
132134
return append(
133-
refSubtreeConsistencyProof(entries[:split], split, start, end, hasher, haveRoot1),
135+
refSubtreeConsistencyProof(start, end, entries[:split], known, hasher),
134136
refRootHash(entries[split:], hasher))
135137
// The subtree is on the right of split. Prove that the subtree is consistent
136138
// with the subtree on the right of split, and record the root of the left
137139
// subtree.
138140
case split <= start:
139141
return append(
140-
refSubtreeConsistencyProof(entries[split:], size-split, start-split, end-split, hasher, haveRoot1),
142+
refSubtreeConsistencyProof(start-split, end-split, entries[split:], known, hasher),
141143
refRootHash(entries[:split], hasher))
142144
// Otherwise, split is between start and end.
143145
// This means that start is 0.
@@ -158,7 +160,7 @@ func refSubtreeConsistencyProof(entries [][]byte, size, start, end uint64, hashe
158160
// - Thus, k must be 0, meaning start is 0.
159161
default:
160162
return append(
161-
refSubtreeConsistencyProof(entries[split:], size-split, 0, end-split, hasher, false),
163+
refSubtreeConsistencyProof(0, end-split, entries[split:], false, hasher),
162164
refRootHash(entries[:split], hasher))
163165
}
164166
}

testonly/tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func TestSubtreeTreeConsistencyProof(t *testing.T) {
223223
if err != nil {
224224
t.Fatalf("SubtreeConsistencyProof: %v", err)
225225
}
226-
want := refSubtreeConsistencyProof(entries[:size], size, start, end, mt.hasher, true)
226+
want := refSubtreeConsistencyProof(start, end, entries[:size], true, mt.hasher)
227227
if diff := cmp.Diff(got, want, cmpopts.EquateEmpty()); diff != "" {
228228
t.Errorf("SubtreeConsistencyProof: diff (-got +want)\n%s", diff)
229229
}

0 commit comments

Comments
 (0)