Documentation
¶
Index ¶
- func DecodeJSONArgumentsFromMap(inputs abi.Arguments, values map[string]any, ...) ([]any, error)
- func DecodeJSONArgumentsFromSlice(inputs abi.Arguments, values []any, ...) ([]any, error)
- func EncodeABIArgumentsToString(inputs abi.Arguments, values []any, overrides map[common.Address]string) (string, error)
- func EncodeJSONArgumentsToMap(inputs abi.Arguments, values []any) (map[string]any, error)
- func EncodeJSONArgumentsToSlice(inputs abi.Arguments, values []any) ([]any, error)
- func GenerateAbiValue(generator ValueGenerator, inputType *abi.Type) any
- func MutateAbiValue(generator ValueGenerator, mutator ValueMutator, inputType *abi.Type, value any) (any, error)
- type MutationalValueGenerator
- func (g *MutationalValueGenerator) GenerateAddress() common.Address
- func (g *MutationalValueGenerator) GenerateBytes() []byte
- func (g *MutationalValueGenerator) GenerateFixedBytes(length int) []byte
- func (g *MutationalValueGenerator) GenerateInteger(signed bool, bitLength int) *big.Int
- func (g *MutationalValueGenerator) GenerateString() string
- func (g *MutationalValueGenerator) MutateAddress(addr common.Address) common.Address
- func (g *MutationalValueGenerator) MutateArray(value []any, fixedLength bool) []any
- func (g *MutationalValueGenerator) MutateBool(bl bool) bool
- func (g *MutationalValueGenerator) MutateBytes(b []byte) []byte
- func (g *MutationalValueGenerator) MutateFixedBytes(b []byte) []byte
- func (g *MutationalValueGenerator) MutateInteger(i *big.Int, signed bool, bitLength int) *big.Int
- func (g *MutationalValueGenerator) MutateString(s string) string
- type MutationalValueGeneratorConfig
- type RandomValueGenerator
- func (g *RandomValueGenerator) GenerateAddress() common.Address
- func (g *RandomValueGenerator) GenerateArrayOfLength() int
- func (g *RandomValueGenerator) GenerateBool() bool
- func (g *RandomValueGenerator) GenerateBytes() []byte
- func (g *RandomValueGenerator) GenerateFixedBytes(length int) []byte
- func (g *RandomValueGenerator) GenerateInteger(signed bool, bitLength int) *big.Int
- func (g *RandomValueGenerator) GenerateString() string
- func (g *RandomValueGenerator) MutateAddress(addr common.Address) common.Address
- func (g *RandomValueGenerator) MutateArray(value []any, fixedLength bool) []any
- func (g *RandomValueGenerator) MutateBool(bl bool) bool
- func (g *RandomValueGenerator) MutateBytes(b []byte) []byte
- func (g *RandomValueGenerator) MutateFixedBytes(b []byte) []byte
- func (g *RandomValueGenerator) MutateInteger(i *big.Int, signed bool, bitLength int) *big.Int
- func (g *RandomValueGenerator) MutateString(s string) string
- type RandomValueGeneratorConfig
- type ShrinkingValueMutator
- func (g *ShrinkingValueMutator) MutateAddress(addr common.Address) common.Address
- func (g *ShrinkingValueMutator) MutateArray(value []any, fixedLength bool) []any
- func (g *ShrinkingValueMutator) MutateBool(bl bool) bool
- func (g *ShrinkingValueMutator) MutateBytes(b []byte) []byte
- func (g *ShrinkingValueMutator) MutateFixedBytes(b []byte) []byte
- func (g *ShrinkingValueMutator) MutateInteger(i *big.Int, signed bool, bitLength int) *big.Int
- func (g *ShrinkingValueMutator) MutateString(s string) string
- type ShrinkingValueMutatorConfig
- type ValueGenerator
- type ValueMutator
- type ValueSet
- func (vs *ValueSet) Add(values []any)
- func (vs *ValueSet) AddAddress(a common.Address)
- func (vs *ValueSet) AddBytes(b []byte)
- func (vs *ValueSet) AddInteger(b *big.Int)
- func (vs *ValueSet) AddString(s string)
- func (vs *ValueSet) Addresses() []common.Address
- func (vs *ValueSet) Bytes() [][]byte
- func (vs *ValueSet) Clone() *ValueSet
- func (vs *ValueSet) ContainsAddress(a common.Address) bool
- func (vs *ValueSet) ContainsBytes(b []byte) bool
- func (vs *ValueSet) ContainsInteger(b *big.Int) bool
- func (vs *ValueSet) ContainsString(s string) bool
- func (vs *ValueSet) Integers() []*big.Int
- func (vs *ValueSet) RemoveAddress(a common.Address)
- func (vs *ValueSet) RemoveBytes(b []byte)
- func (vs *ValueSet) RemoveInteger(b *big.Int)
- func (vs *ValueSet) RemoveString(s string)
- func (vs *ValueSet) SeedFromAst(ast any)
- func (vs *ValueSet) SeedFromSlither(slither *compilationTypes.SlitherResults)
- func (vs *ValueSet) Strings() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSONArgumentsFromMap ¶
func DecodeJSONArgumentsFromMap(inputs abi.Arguments, values map[string]any, deployedContractAddr map[string]common.Address) ([]any, error)
DecodeJSONArgumentsFromMap decodes JSON values into a provided values of the given types, or returns an error of one occurs. The values provided must be generic JSON types (e.g. []any, map[string]any, etc) which will be transformed into a go-ethereum ABI packable values.
func DecodeJSONArgumentsFromSlice ¶
func DecodeJSONArgumentsFromSlice(inputs abi.Arguments, values []any, deployedContractAddr map[string]common.Address) ([]any, error)
DecodeJSONArgumentsFromSlice decodes JSON values into a provided values of the given types, or returns an error of one occurs. The values provided must be generic JSON types (e.g. []any, map[string]any, etc) which will be transformed into a go-ethereum ABI packable values.
func EncodeABIArgumentsToString ¶
func EncodeABIArgumentsToString(inputs abi.Arguments, values []any, overrides map[common.Address]string) (string, error)
EncodeABIArgumentsToString encodes provided go-ethereum ABI package input values into string that is human-readable for console output purpose. A mapping of overrides can also be provided to override the string representation of addresses for something else (useful for the vm.label cheatcode). Returns the string, or an error if one occurs.
func EncodeJSONArgumentsToMap ¶
EncodeJSONArgumentsToMap encodes provided go-ethereum ABI packable input values into a generic JSON type values (e.g. []any, map[string]any, etc). Returns the encoded values, or an error if one occurs.
func EncodeJSONArgumentsToSlice ¶
EncodeJSONArgumentsToSlice encodes provided go-ethereum ABI packable input values into generic JSON compatible values (e.g. []any, map[string]any, etc). Returns the encoded values, or an error if one occurs.
func GenerateAbiValue ¶
func GenerateAbiValue(generator ValueGenerator, inputType *abi.Type) any
GenerateAbiValue generates a value of the provided abi.Type using the provided ValueGenerator. The generated value is returned.
func MutateAbiValue ¶
func MutateAbiValue(generator ValueGenerator, mutator ValueMutator, inputType *abi.Type, value any) (any, error)
MutateAbiValue takes an ABI packable input value, alongside its type definition and a value generator, to mutate existing ABI input values.
Types ¶
type MutationalValueGenerator ¶ added in v0.1.1
type MutationalValueGenerator struct { // RandomValueGenerator is included to inherit from the random generator *RandomValueGenerator // contains filtered or unexported fields }
MutationalValueGenerator represents a ValueGenerator and ValueMutator for function inputs and call arguments. It leverages values from a ValueSet (e.g. AST literals) to generate new values or mutate existing ones.
func NewMutationalValueGenerator ¶ added in v0.1.1
func NewMutationalValueGenerator(config *MutationalValueGeneratorConfig, valueSet *ValueSet, randomProvider *rand.Rand) *MutationalValueGenerator
NewMutationalValueGenerator creates a new MutationalValueGenerator using a provided ValueSet to seed base-values for mutation.
func (*MutationalValueGenerator) GenerateAddress ¶ added in v0.1.1
func (g *MutationalValueGenerator) GenerateAddress() common.Address
GenerateAddress obtains an existing address from its underlying value set or generates a random one.
func (*MutationalValueGenerator) GenerateBytes ¶ added in v0.1.1
func (g *MutationalValueGenerator) GenerateBytes() []byte
GenerateBytes generates bytes and returns them.
func (*MutationalValueGenerator) GenerateFixedBytes ¶ added in v1.0.0
func (g *MutationalValueGenerator) GenerateFixedBytes(length int) []byte
GenerateFixedBytes generates a fixed-sized byte array to use when populating inputs.
func (*MutationalValueGenerator) GenerateInteger ¶ added in v0.1.1
func (g *MutationalValueGenerator) GenerateInteger(signed bool, bitLength int) *big.Int
GenerateInteger generates an integer of the provided properties and returns a big.Int representing it.
func (*MutationalValueGenerator) GenerateString ¶ added in v0.1.1
func (g *MutationalValueGenerator) GenerateString() string
GenerateString generates strings and returns them.
func (*MutationalValueGenerator) MutateAddress ¶ added in v0.1.1
func (g *MutationalValueGenerator) MutateAddress(addr common.Address) common.Address
MutateAddress takes an address input and sometimes returns a mutated value based off the input.
func (*MutationalValueGenerator) MutateArray ¶ added in v0.1.1
func (g *MutationalValueGenerator) MutateArray(value []any, fixedLength bool) []any
MutateArray takes a dynamic or fixed sized array as input, and returns a mutated value based off of the input. Returns the mutated value. If any element of the returned array is nil, the value generator will be called upon to generate it new.
func (*MutationalValueGenerator) MutateBool ¶ added in v0.1.1
func (g *MutationalValueGenerator) MutateBool(bl bool) bool
MutateBool takes a boolean input and returns a mutated value based off the input.
func (*MutationalValueGenerator) MutateBytes ¶ added in v0.1.1
func (g *MutationalValueGenerator) MutateBytes(b []byte) []byte
MutateBytes takes a dynamic-sized byte array input and returns a mutated value based off the input.
func (*MutationalValueGenerator) MutateFixedBytes ¶ added in v0.1.1
func (g *MutationalValueGenerator) MutateFixedBytes(b []byte) []byte
MutateFixedBytes takes a fixed-sized byte array input and returns a mutated value based off the input.
func (*MutationalValueGenerator) MutateInteger ¶ added in v0.1.1
MutateInteger takes an integer input and applies optional mutations to the provided value. Returns an optionally mutated copy of the input.
func (*MutationalValueGenerator) MutateString ¶ added in v0.1.1
func (g *MutationalValueGenerator) MutateString(s string) string
MutateString takes a string input and returns a mutated value based off the input.
type MutationalValueGeneratorConfig ¶ added in v0.1.1
type MutationalValueGeneratorConfig struct { // MinMutationRounds describes the minimum amount of mutations which should occur when generating a value. // This parameter is used when generating a new value by mutating a value in the value set, or when mutating // an existing value. MinMutationRounds int // MaxMutationRounds describes the maximum amount of mutations which should occur when generating a value. // This parameter is used when generating a new value by mutating a value in the value set, or when mutating // an existing value. MaxMutationRounds int // GenerateRandomIntegerBias defines the probability in which an address generated by the value generator is // entirely random, rather than selected from the MutationalValueGenerator's ValueSet. // range is [0.0, 1.0]. GenerateRandomAddressBias float32 // GenerateRandomIntegerBias defines the probability in which an integer generated by the value generator is // entirely random, rather than mutated. Value range is [0.0, 1.0]. GenerateRandomIntegerBias float32 // GenerateRandomStringBias defines the probability in which a string generated by the value generator is entirely // random, rather than mutated. Value range is [0.0, 1.0]. GenerateRandomStringBias float32 // GenerateRandomBytesBias defines the probability in which a byte array generated by the value generator is // entirely random, rather than mutated. Value range is [0.0, 1.0]. GenerateRandomBytesBias float32 // MutateAddressProbability defines the probability in which an existing address value will be mutated by // the value generator. Value range is [0.0, 1.0]. MutateAddressProbability float32 // MutateArrayStructureProbability defines the probability in which an existing array value will be mutated by // the value generator. Value range is [0.0, 1.0]. MutateArrayStructureProbability float32 // MutateAddressProbability defines the probability in which an existing boolean value will be mutated by // the value generator. Value range is [0.0, 1.0]. MutateBoolProbability float32 // MutateBytesProbability defines the probability in which an existing dynamic-sized byte array value will be // mutated by the value generator. Value range is [0.0, 1.0]. MutateBytesProbability float32 // MutateBytesGenerateNewBias defines the probability that when an existing dynamic-sized byte array will be // mutated, it is done so by being replaced with a newly generated one instead. Value range is [0.0, 1.0]. MutateBytesGenerateNewBias float32 // MutateFixedBytesProbability defines the probability in which an existing fixed-sized byte array value will be // mutated by the value generator. Value range is [0.0, 1.0]. MutateFixedBytesProbability float32 // MutateStringProbability defines the probability in which an existing string value will be mutated by // the value generator. Value range is [0.0, 1.0]. MutateStringProbability float32 // MutateStringGenerateNewBias defines the probability that when an existing string will be mutated, // it is done so by being replaced with a newly generated one instead. Value range is [0.0, 1.0]. MutateStringGenerateNewBias float32 // MutateIntegerProbability defines the probability in which an existing integer value will be mutated by // the value generator. Value range is [0.0, 1.0]. MutateIntegerProbability float32 // MutateIntegerGenerateNewBias defines the probability that when an existing integer will be mutated, // it is done so by being replaced with a newly generated one instead. Value range is [0.0, 1.0]. MutateIntegerGenerateNewBias float32 // RandomValueGeneratorConfig is adhered to in this structure, to power the underlying RandomValueGenerator. *RandomValueGeneratorConfig }
MutationalValueGeneratorConfig defines the operating parameters for a MutationalValueGenerator.
type RandomValueGenerator ¶
type RandomValueGenerator struct {
// contains filtered or unexported fields
}
RandomValueGenerator represents a ValueGenerator used to generate transaction fields and call arguments with values provided by a random number generator.
func NewRandomValueGenerator ¶
func NewRandomValueGenerator(config *RandomValueGeneratorConfig, randomProvider *rand.Rand) *RandomValueGenerator
NewRandomValueGenerator creates a new RandomValueGenerator.
func (*RandomValueGenerator) GenerateAddress ¶
func (g *RandomValueGenerator) GenerateAddress() common.Address
GenerateAddress generates a random address to use when populating inputs.
func (*RandomValueGenerator) GenerateArrayOfLength ¶
func (g *RandomValueGenerator) GenerateArrayOfLength() int
GenerateArrayOfLength generates a random array length to use when populating inputs. This is used to determine how many elements a non-byte, non-string array should have.
func (*RandomValueGenerator) GenerateBool ¶
func (g *RandomValueGenerator) GenerateBool() bool
GenerateBool generates a random bool to use when populating inputs.
func (*RandomValueGenerator) GenerateBytes ¶
func (g *RandomValueGenerator) GenerateBytes() []byte
GenerateBytes generates a random dynamic-sized byte array to use when populating inputs.
func (*RandomValueGenerator) GenerateFixedBytes ¶
func (g *RandomValueGenerator) GenerateFixedBytes(length int) []byte
GenerateFixedBytes generates a random fixed-sized byte array to use when populating inputs.
func (*RandomValueGenerator) GenerateInteger ¶
func (g *RandomValueGenerator) GenerateInteger(signed bool, bitLength int) *big.Int
GenerateInteger generates a random integer to use when populating inputs.
func (*RandomValueGenerator) GenerateString ¶
func (g *RandomValueGenerator) GenerateString() string
GenerateString generates a random dynamic-sized string to use when populating inputs.
func (*RandomValueGenerator) MutateAddress ¶
func (g *RandomValueGenerator) MutateAddress(addr common.Address) common.Address
MutateAddress takes an address input and returns a mutated value based off the input.
func (*RandomValueGenerator) MutateArray ¶
func (g *RandomValueGenerator) MutateArray(value []any, fixedLength bool) []any
MutateArray takes a dynamic or fixed sized array as input, and returns a mutated value based off of the input. Returns the mutated value. If any element of the returned array is nil, the value generator will be called upon to generate it new.
func (*RandomValueGenerator) MutateBool ¶
func (g *RandomValueGenerator) MutateBool(bl bool) bool
MutateBool takes a boolean input and returns a mutated value based off the input.
func (*RandomValueGenerator) MutateBytes ¶
func (g *RandomValueGenerator) MutateBytes(b []byte) []byte
MutateBytes takes a dynamic-sized byte array input and returns a mutated value based off the input.
func (*RandomValueGenerator) MutateFixedBytes ¶
func (g *RandomValueGenerator) MutateFixedBytes(b []byte) []byte
MutateFixedBytes takes a fixed-sized byte array input and returns a mutated value based off the input.
func (*RandomValueGenerator) MutateInteger ¶
MutateInteger takes an integer input and returns a mutated value based off the input.
func (*RandomValueGenerator) MutateString ¶
func (g *RandomValueGenerator) MutateString(s string) string
MutateString takes a string input and returns a mutated value based off the input.
type RandomValueGeneratorConfig ¶
type RandomValueGeneratorConfig struct { // GenerateRandomArrayMinSize defines the minimum size which a generated array should be. GenerateRandomArrayMinSize int // GenerateRandomArrayMaxSize defines the maximum size which a generated array should be. GenerateRandomArrayMaxSize int // GenerateRandomBytesMinSize defines the minimum size which a generated byte slice should be. GenerateRandomBytesMinSize int // GenerateRandomBytesMaxSize defines the maximum size which a generated byte slice should be. GenerateRandomBytesMaxSize int // GenerateRandomStringMinSize defines the minimum size which a generated string should be. GenerateRandomStringMinSize int // GenerateRandomStringMaxSize defines the maximum size which a generated string should be. GenerateRandomStringMaxSize int }
RandomValueGeneratorConfig defines the parameters for a RandomValueGenerator.
type ShrinkingValueMutator ¶ added in v0.1.1
type ShrinkingValueMutator struct {
// contains filtered or unexported fields
}
ShrinkingValueMutator represents a ValueMutator used to shrink function inputs and call arguments.
func NewShrinkingValueMutator ¶ added in v0.1.1
func NewShrinkingValueMutator(config *ShrinkingValueMutatorConfig, valueSet *ValueSet, randomProvider *rand.Rand) *ShrinkingValueMutator
NewShrinkingValueMutator creates a new ShrinkingValueMutator using a ValueSet to seed base-values for mutation.
func (*ShrinkingValueMutator) MutateAddress ¶ added in v0.1.1
func (g *ShrinkingValueMutator) MutateAddress(addr common.Address) common.Address
MutateAddress takes an address input and sometimes returns a mutated value based off the input. This type is not mutated by the ShrinkingValueMutator.
func (*ShrinkingValueMutator) MutateArray ¶ added in v0.1.1
func (g *ShrinkingValueMutator) MutateArray(value []any, fixedLength bool) []any
MutateArray takes a dynamic or fixed sized array as input, and returns a mutated value based off of the input. Returns the mutated value. If any element of the returned array is nil, the value generator will be called upon to generate it new. This type is not mutated by the ShrinkingValueMutator.
func (*ShrinkingValueMutator) MutateBool ¶ added in v0.1.1
func (g *ShrinkingValueMutator) MutateBool(bl bool) bool
MutateBool takes a boolean input and returns a mutated value based off the input. This type is not mutated by the ShrinkingValueMutator.
func (*ShrinkingValueMutator) MutateBytes ¶ added in v0.1.1
func (g *ShrinkingValueMutator) MutateBytes(b []byte) []byte
MutateBytes takes a dynamic-sized byte array input and returns a mutated value based off the input.
func (*ShrinkingValueMutator) MutateFixedBytes ¶ added in v0.1.1
func (g *ShrinkingValueMutator) MutateFixedBytes(b []byte) []byte
MutateFixedBytes takes a fixed-sized byte array input and returns a mutated value based off the input. This type is not mutated by the ShrinkingValueMutator.
func (*ShrinkingValueMutator) MutateInteger ¶ added in v0.1.1
MutateInteger takes an integer input and applies optional mutations to the provided value. Returns an optionally mutated copy of the input.
func (*ShrinkingValueMutator) MutateString ¶ added in v0.1.1
func (g *ShrinkingValueMutator) MutateString(s string) string
MutateString takes a string input and returns a mutated value based off the input.
type ShrinkingValueMutatorConfig ¶ added in v0.1.1
type ShrinkingValueMutatorConfig struct { // ShrinkValueProbability is the probability that any shrinkable value will be shrunk/mutated when a mutation // method is invoked. ShrinkValueProbability float32 }
ShrinkingValueMutatorConfig defines the operating parameters for a ShrinkingValueMutator.
type ValueGenerator ¶
type ValueGenerator interface { // GenerateAddress generates/selects an address to use when populating inputs. GenerateAddress() common.Address // GenerateArrayOfLength generates/selects an array length to use when populating inputs. GenerateArrayOfLength() int // GenerateBool generates/selects a bool to use when populating inputs. GenerateBool() bool // GenerateBytes generates/selects a dynamic-sized byte array to use when populating inputs. GenerateBytes() []byte // GenerateFixedBytes generates/selects a fixed-sized byte array to use when populating inputs. GenerateFixedBytes(length int) []byte // GenerateString generates/selects a dynamic-sized string to use when populating inputs. GenerateString() string // GenerateInteger generates/selects an integer to use when populating inputs. GenerateInteger(signed bool, bitLength int) *big.Int }
ValueGenerator represents an interface for a provider used to generate function inputs and call arguments for use in fuzzing campaigns.
type ValueMutator ¶ added in v0.1.1
type ValueMutator interface { // MutateAddress takes an address input and returns a mutated value based off the input. MutateAddress(addr common.Address) common.Address // MutateArray takes a dynamic or fixed sized array as input, and returns a mutated value based off of the input. // Returns the mutated value. If any element of the returned array is nil, the value generator will be called upon // to generate a new value in its place. MutateArray(value []any, fixedLength bool) []any // MutateBool takes a boolean input and returns a mutated value based off the input. MutateBool(bl bool) bool // MutateBytes takes a dynamic-sized byte array input and returns a mutated value based off the input. MutateBytes(b []byte) []byte // MutateFixedBytes takes a fixed-sized byte array input and returns a mutated value based off the input. MutateFixedBytes(b []byte) []byte // MutateString takes a string input and returns a mutated value based off the input. MutateString(s string) string // MutateInteger takes an integer input and returns a mutated value based off the input. MutateInteger(i *big.Int, signed bool, bitLength int) *big.Int }
ValueMutator represents an interface for a provider used to mutate function inputs and call arguments for use in fuzzing campaigns.
type ValueSet ¶
type ValueSet struct {
// contains filtered or unexported fields
}
ValueSet represents potential values of significance within the source code to be used in fuzz tests.
func NewValueSet ¶
func NewValueSet() *ValueSet
NewValueSet initializes a new ValueSet object for use with a Fuzzer.
func (*ValueSet) Add ¶ added in v1.0.0
Add adds one or more values. Note the values must be a primitive type (signed/unsigned integer, address, string, bytes, fixed bytes)
func (*ValueSet) AddAddress ¶
AddAddress adds an address item to the ValueSet.
func (*ValueSet) AddInteger ¶
AddInteger adds an integer item to the ValueSet.
func (*ValueSet) ContainsAddress ¶ added in v0.1.2
ContainsAddress checks if an address is contained in the ValueSet.
func (*ValueSet) ContainsBytes ¶ added in v0.1.2
ContainsBytes checks if a byte sequence is contained in the ValueSet.
func (*ValueSet) ContainsInteger ¶ added in v0.1.2
ContainsInteger checks if an integer is contained in the ValueSet.
func (*ValueSet) ContainsString ¶ added in v0.1.2
ContainsString checks if a string is contained in the ValueSet.
func (*ValueSet) RemoveAddress ¶
RemoveAddress removes an address item from the ValueSet.
func (*ValueSet) RemoveBytes ¶
RemoveBytes removes a byte sequence item from the ValueSet.
func (*ValueSet) RemoveInteger ¶
RemoveInteger removes an integer item from the ValueSet.
func (*ValueSet) RemoveString ¶
RemoveString removes a string item from the ValueSet.
func (*ValueSet) SeedFromAst ¶
SeedFromAst allows a ValueSet to be seeded from an AST interface.
func (*ValueSet) SeedFromSlither ¶ added in v1.0.0
func (vs *ValueSet) SeedFromSlither(slither *compilationTypes.SlitherResults)
SeedFromSlither allows a ValueSet to be seeded from the output of slither.