diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh index 8c7bc09..adbe663 100644 --- a/.clusterfuzzlite/build.sh +++ b/.clusterfuzzlite/build.sh @@ -15,3 +15,4 @@ compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzConsist compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProofAndVerify FuzzInclusionProofAndVerify 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 diff --git a/testonly/tree_fuzz_test.go b/testonly/tree_fuzz_test.go index f884017..2dd1b29 100644 --- a/testonly/tree_fuzz_test.go +++ b/testonly/tree_fuzz_test.go @@ -122,3 +122,32 @@ 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) { + if size >= math.MaxUint16 { + return + } + 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) + } + }) +}