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

Commit

Permalink
fuzz: add .Delete fuzzing (#52)
Browse files Browse the repository at this point in the history
* fuzz: add .Delete fuzzing

* Update fuzz/delete/fuzz.go

Remove spurious newline.

Co-authored-by: Ismail Khoffi <[email protected]>

Co-authored-by: Ismail Khoffi <[email protected]>
  • Loading branch information
Emmanuel T Odeke and liamsi authored Jul 29, 2021
1 parent 2e3797d commit a8b51d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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

0 comments on commit a8b51d5

Please sign in to comment.