Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

fuzz: add .Delete fuzzing #52

Merged
merged 2 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions fuzz/delete/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package delete

import (
"bytes"
"crypto/sha256"

"github.com/celestiaorg/smt"
)

func Fuzz(data []byte) int {
if len(data) == 0 {
return -1
}

splits := bytes.Split(data, []byte("*"))
if len(splits) < 3 {
return -1
}

smn, smv := smt.NewSimpleMap(), smt.NewSimpleMap()
tree := smt.NewSparseMerkleTree(smn, smv, sha256.New())
for i := 0; i < len(splits)-1; i += 2 {
key, value := splits[i], splits[i+1]
tree.Update(key, value)
}

deleteKey := splits[len(splits)-1]
newRoot, err := tree.Delete(deleteKey)
if err != nil {
return 0
}
if len(newRoot) == 0 {
panic("newRoot is nil yet err==nil")
}
return 1
}
3 changes: 2 additions & 1 deletion oss-fuzz-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export FUZZ_ROOT="github.com/celestiaorg/smt"

compile_go_fuzzer "$FUZZ_ROOT"/fuzz Fuzz fuzz_basic_op fuzz
compile_go_fuzzer "$FUZZ_ROOT"/fuzz Fuzz fuzz_basic_op fuzz
compile_go_fuzzer "$FUZZ_ROOT"/fuzz/delete Fuzz fuzz_delete fuzz