fuzzer_functions.go 710 Bytes
Newer Older
Maurelian's avatar
Maurelian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package fuzzerutils

import (
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	fuzz "github.com/google/gofuzz"
)

// AddFuzzerFunctions takes a fuzz.Fuzzer and adds a list of functions to handle different
// data types in a fuzzing campaign. It adds support for commonly used types throughout the
// application.
func AddFuzzerFunctions(fuzzer *fuzz.Fuzzer) {
	fuzzer.Funcs(
		func(e *big.Int, c fuzz.Continue) {
			var temp [32]byte
			c.Fuzz(&temp)
			e.SetBytes(temp[:])
		},
		func(e *common.Hash, c fuzz.Continue) {
			var temp [32]byte
			c.Fuzz(&temp)
			e.SetBytes(temp[:])
		},
		func(e *common.Address, c fuzz.Continue) {
			var temp [20]byte
			c.Fuzz(&temp)
			e.SetBytes(temp[:])
		},
	)
}