Skip to content

Commit

Permalink
test: fuzz: bring in fuzzers
Browse files Browse the repository at this point in the history
Adds fuzzers and passes we've built since 2020 and before, that use
oss-fuzz's continuous fuzzing infrastructure.

Fixes #7921.
  • Loading branch information
odeke-em committed Jun 6, 2022
1 parent 2b7aca7 commit d742568
Show file tree
Hide file tree
Showing 973 changed files with 2,243 additions and 1 deletion.
14 changes: 14 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Fuzzing

## Running

The fuzz tests are in standard [Go format](https://go.dev/doc/fuzz/).
To run a fuzz test, use the `-fuzz` flag to `go test`. For example:

```
$ go test -fuzz FuzzCryptoHDNewParamsFromPath ./tests
```

## oss-fuzz build status

https://oss-fuzz-build-logs.storage.googleapis.com/index.html#cosmos-sdk
35 changes: 35 additions & 0 deletions fuzz/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -euo pipefail

export FUZZ_ROOT="github.com/cosmos/cosmos-sdk"

build_go_fuzzer() {
local function="$1"
local fuzzer="$2"

gotip run github.com/orijtech/otils/corpus2ossfuzz@latest -o "$OUT"/"$fuzzer"_seed_corpus.zip -corpus fuzz/tests/testdata/fuzz/"$function"
compile_native_go_fuzzer "$FUZZ_ROOT"/fuzz/tests "$function" "$fuzzer"
}

gotip get github.com/AdamKorcz/go-118-fuzz-build/utils
gotip get github.com/prometheus/common/[email protected]

build_go_fuzzer FuzzCryptoHDDerivePrivateKeyForPath fuzz_crypto_hd_deriveprivatekeyforpath
build_go_fuzzer FuzzCryptoHDNewParamsFromPath fuzz_crypto_hd_newparamsfrompath

build_go_fuzzer FuzzCryptoTypesCompactbitarrayMarshalUnmarshal fuzz_crypto_types_compactbitarray_marshalunmarshal

build_go_fuzzer FuzzStoreInternalProofsCreateNonmembershipProof fuzz_store_internal_proofs_createnonmembershipproof

build_go_fuzzer FuzzTendermintAminoDecodeTime fuzz_tendermint_amino_decodetime

build_go_fuzzer FuzzTypesParseCoin fuzz_types_parsecoin
build_go_fuzzer FuzzTypesParseDecCoin fuzz_types_parsedeccoin
build_go_fuzzer FuzzTypesParseTimeBytes fuzz_types_parsetimebytes
build_go_fuzzer FuzzTypesVerifyAddressFormat fuzz_types_verifyaddressformat
build_go_fuzzer FuzzTypesDecSetString fuzz_types_dec_setstring

build_go_fuzzer FuzzUnknownProto fuzz_unknownproto

build_go_fuzzer FuzzXBankTypesAddressFromBalancesStore fuzz_x_bank_types_addressfrombalancesstore
34 changes: 34 additions & 0 deletions fuzz/tests/crypto_hd_deriveprivatekeyforpath_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build gofuzz || go1.18

package tests

import (
"bytes"
"testing"

"github.com/cosmos/cosmos-sdk/crypto/hd"
bip39 "github.com/cosmos/go-bip39"
)

func mnemonicToSeed(mnemonic string) []byte {
return bip39.NewSeed(mnemonic, "" /* Default passphrase */)
}

func FuzzCryptoHDDerivePrivateKeyForPath(f *testing.F) {
f.Fuzz(func(t *testing.T, in []byte) {
splits := bytes.Split(in, []byte("*"))
if len(splits) == 1 {
return
}
mnemonic, path := splits[0], splits[1]
if len(path) > 1e5 {
// Deriving a private key takes non-trivial time proportional
// to the path length. Skip the longer ones that trigger timeouts
// on fuzzing infrastructure.
return
}
seed := mnemonicToSeed(string(mnemonic))
master, ch := hd.ComputeMastersFromSeed(seed)
hd.DerivePrivateKeyForPath(master, ch, string(path))
})
}
15 changes: 15 additions & 0 deletions fuzz/tests/crypto_hd_newparamsfrompath_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build gofuzz || go1.18

package tests

import (
"testing"

"github.com/cosmos/cosmos-sdk/crypto/hd"
)

func FuzzCryptoHDNewParamsFromPath(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
hd.NewParamsFromPath(string(data))
})
}
27 changes: 27 additions & 0 deletions fuzz/tests/crypto_types_compactbitarray_marshalunmarshal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build gofuzz || go1.18

package tests

import (
"testing"

"github.com/cosmos/cosmos-sdk/crypto/types"
)

func FuzzCryptoTypesCompactbitarrayMarshalUnmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
cba, err := types.CompactUnmarshal(data)
if err != nil {
return
}
if cba == nil && string(data) != "null" {
panic("Inconsistency, no error, yet BitArray is nil")
}
if cba.SetIndex(-1, true) {
panic("Set negative index success")
}
if cba.GetIndex(-1) {
panic("Get negative index success")
}
})
}
37 changes: 37 additions & 0 deletions fuzz/tests/store_internal_proofs_createnonmembershipproof_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build gofuzz || go1.18

package tests

/*
// TODO: Retrofit to the right parameters for CreateNonmembershipProof
import (
"encoding/json"
"testing"
iavlproofs "github.com/cosmos/cosmos-sdk/store/tools/ics23/iavl"
)
type serialize struct {
Data map[string][]byte
Key string
}
func FuzzStoreInternalProofsCreateNonmembershipProof(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
sz := new(serialize)
if err := json.Unmarshal(data, sz); err != nil {
return
}
if len(sz.Data) == 0 || len(sz.Key) == 0 {
return
}
icp, err := iavlproofs.CreateNonMembershipProof(sz.Data, []byte(sz.Key))
if err != nil {
return
}
if icp == nil {
panic("nil CommitmentProof with nil error")
}
})
}
*/
25 changes: 25 additions & 0 deletions fuzz/tests/tendermint_amino_decodetime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build gofuzz || go1.18

package tests

import (
"fmt"
"testing"

amino "github.com/tendermint/go-amino"
)

func FuzzTendermintAminoDecodeTime(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
if len(data) == 0 {
return
}
_, n, err := amino.DecodeTime(data)
if err != nil {
return
}
if n < 0 {
panic(fmt.Sprintf("n=%d < 0", n))
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u2003\u202f\u2003\u202f\u202f\u2003\u202f\u202f\u202f\u2003\u2003\u202f\u202f\u2003\u202f\u2003\u202f\u2003\u202f\u202f\u2003\u202f\u202f\u2003\u202f\u2003\u202f\u202f\u2003\u202f/9")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u2003\u202f\u2003\u202f\u202f\u2003\u202f\u2003\u202f/6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\u00a0\r\v\r\fm/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u2003\u2003\u202f/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("artwork blanket carpet cricket disorder disorder artwork blanket carpet cricket disorder disorder*1'/2147483647'/1/0'/0/0\n")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("s!*1/1/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("der*1'/8/1/0'/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m/1*********************************************************************")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1'/8'/0'/1'/0'/5'/8'/8'/8'")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\r\f\r\f\f\r\f\r\r\f\r\f\f\r\f\f\r\f/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("I am become Death, the destroyer of worlds!*m/1'/2147483647'/1/0'/0/0\n")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\u00a0m\v\r\f\f\r\f\r\r/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0/9")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/1/0/0/0/0/0/0/130/0/0/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("I ald*1/7")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\r\f\r\f\r\f\r\f/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u2003\u202f\u2003\u202f\u202f\u2003\u202f\u202f\u2003\u202f/6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\r\f\r\f/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\v\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1'/8'/8'/0'/1'/0'/5'/8'/8'/8'/0'/1'/0'/5'/8'/8'/8'")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("e!*1/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\u00a0m/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("der*1/8/11/4/0'/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\r\f\r\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\rm/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*5/1////////")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\r\f\r\f\r\f\r\f\r\r\f\r\f\r\f\r\r\f\r\r\r\f\r\f\r\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\r\r\r\f\r\f\r\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\r\f/6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/1/0/11/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/5/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m/1***")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("de\xc1*1/8/4/0/1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u2003\u202f\u00a0\u00a0\u00a0\u00a0\u00a0\u2003\u202f\u202f\u2003\u202f\u202f\u00a0\u00a0\u00a0\u202f\u2003\u00a0\u00a0\u2003\u202f\u202f\u2003\u202f\u2003\u202f\u00a0\u00a0\u00a0\u00a0\u00a0\u2003\u202f\u202f\u2003\u202f\u2003\u202f/9")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("carpet cricket disorder cricket cricket artwork carpet cricket disorder cricket cricket artwork*m/44'/0'/0'/0/0\n")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*5/1//")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u2003/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m\u2003\u202f\u2003\u202f\u2003\u202f/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\r\f\r\f\r\f\r\f\r\r\fm/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1'/8'/0'/8'")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/11/0/1/0/1/0/1/0/0/0/0/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/0/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\r\f\rm/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m/1*")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*5/1////////////////")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m/1********************************")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("!*1/1/0/0/0/0/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("!*1/1/0/0/0/0/0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*m/1********")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\f\r\f\r\f\r\f\r\f\r\r\f\r\f\r\f\r\r\f\r\r\r\f\r\f\r\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\r\r\r\f\r\f\r\f\r\f\r\f\r\f\r\f\r\r\f\r\r\r\f\rm/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*5/1////")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*\f\r\f\rm/4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("*1/1/0/1/0/11/0/0/0/0/0/1/1/0/0/0/0/0/0/1/0/0/0/0/0/1/1/0/0/0/0/0/0/0/0")
Loading

0 comments on commit d742568

Please sign in to comment.