Skip to content

Commit c937f3c

Browse files
committed
Fuzz ConsistencyProof function against reference implementation
1 parent 8f0b85c commit c937f3c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.clusterfuzzlite/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzConsist
1515
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProofAndVerify FuzzInclusionProofAndVerify
1616
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzHashAtAgainstReferenceImplementation FuzzHashAtAgainstReferenceImplementation
1717
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProofAgainstReferenceImplementation FuzzInclusionProofAgainstReferenceImplementation
18+
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzConsistencyProofAgainstReferenceImplementation FuzzConsistencyProofAgainstReferenceImplementation

testonly/tree_fuzz_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,32 @@ func FuzzInclusionProofAgainstReferenceImplementation(f *testing.F) {
122122
}
123123
})
124124
}
125+
126+
func FuzzConsistencyProofAgainstReferenceImplementation(f *testing.F) {
127+
for size := 0; size <= 8; size++ {
128+
for end := 0; end <= size; end++ {
129+
for begin := 0; begin <= end; begin++ {
130+
f.Add(uint64(size), uint64(begin), uint64(end))
131+
}
132+
}
133+
}
134+
f.Fuzz(func(t *testing.T, size, begin, end uint64) {
135+
if size >= math.MaxUint16 {
136+
return
137+
}
138+
t.Logf("size=%d, begin=%d, end=%d", size, begin, end)
139+
if begin > end || end > size {
140+
return
141+
}
142+
entries := genEntries(size)
143+
tree := newTree(entries)
144+
got, err := tree.ConsistencyProof(begin, end)
145+
if err != nil {
146+
t.Errorf("ConsistencyProof: %v", err)
147+
}
148+
want := refConsistencyProof(entries[:end], end, begin, tree.hasher, true)
149+
if diff := cmp.Diff(got, want, cmpopts.EquateEmpty()); diff != "" {
150+
t.Errorf("ConsistencyProof: diff (-got +want)\n%s", diff)
151+
}
152+
})
153+
}

0 commit comments

Comments
 (0)