Skip to content

Commit

Permalink
Fuzz ConsistencyProof function against reference implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
hickford committed Aug 4, 2022
1 parent 8f0b85c commit c937f3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions testonly/tree_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

0 comments on commit c937f3c

Please sign in to comment.