Skip to content

Commit

Permalink
Fuzz ConsistencyProof function against reference implementation
Browse files Browse the repository at this point in the history
Add remaining fuzz tests to ClusterFuzzLite
  • Loading branch information
hickford committed Jul 25, 2022
1 parent 8eafa9d commit d549346
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ go install github.com/AdamKorcz/go-118-fuzz-build@latest
go get github.com/AdamKorcz/go-118-fuzz-build/utils
# necessary to list each fuzz test explicitly
compile_native_go_fuzzer github.com/transparency-dev/merkle/compact FuzzRangeNodes FuzzRangeNodes
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzConsistencyProof FuzzConsistencyProof
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProof FuzzInclusionProof
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzHashAtAgainstReferenceImplementation FuzzHashAtAgainstReferenceImplementation
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProofAgainstReferenceImplementation FuzzInclusionProofAgainstReferenceImplementation
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzConsistencyProofAgainstReferenceImplementation FuzzConsistencyProofAgainstReferenceImplementation
26 changes: 26 additions & 0 deletions testonly/tree_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,29 @@ func FuzzInclusionProofAgainstReferenceImplementation(f *testing.F) {
}
})
}

func FuzzConsistencyProofAgainstReferenceImplementation(f *testing.F) {
for size := 0; size <= 8; size++ {
for end := 0; end <= size; end++ {
for begin := 0; begin <= end; begin++ {
f.Add(uint64(size), uint64(begin), uint64(end))
}
}
}
f.Fuzz(func(t *testing.T, size, begin, end uint64) {
t.Logf("size=%d, begin=%d, end=%d", size, begin, end)
if begin > end || end > size {
return
}
entries := genEntries(size)
tree := newTree(entries)
got, err := tree.ConsistencyProof(begin, end)
if err != nil {
t.Errorf("ConsistencyProof: %v", err)
}
want := refConsistencyProof(entries[:end], end, begin, tree.hasher, true)
if diff := cmp.Diff(got, want, cmpopts.EquateEmpty()); diff != "" {
t.Errorf("ConsistencyProof: diff (-got +want)\n%s", diff)
}
})
}

0 comments on commit d549346

Please sign in to comment.