From f5e1dc52b3453b76c726c9e7438f25d8da4aef01 Mon Sep 17 00:00:00 2001 From: hickford Date: Thu, 21 Jul 2022 12:22:54 +0100 Subject: [PATCH] Fuzz ConsistencyProof function against reference implementation --- .clusterfuzzlite/build.sh | 1 + testonly/tree_fuzz_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) 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) + } + }) +}