crytic / crytic/medusa

Code quality improvements for `fuzzing/valuegeneration`

Open
#809 1 comment 0 reactions 0 assignees View on GitHub
code-quality low-priority
Dominant language
Go
Stars
486
Forks
92
Avg merge
4d 6h
Merged PRs (30d)
5

Description

- It's a bit clunky to have RandomValueGenerator implement ValueMutator, since that's not its purpose. Right now all its Mutate functions are dummy functions that return the input. Do we need to implement this at all; can we just remove these methods?
- It's a bit clunky to have MutationalValueGenerator implement ValueGenerator, since that's not its purpose. Right now its Generate methods call mutate on a blank value, basically just repeating the work of RandomValueGenerator. Do we need to implement this at all? Can we just remove these methods and use RandomValueGenerator instead?
- EncodeJSONArgumentsToMap, EncodeJSONArgumentsToSlice, EncodeABIArgumentsToString, and so on should probably be somewhere else
- MutationalValueGenerator.MutateArray does nothing and has a big TODO in it: `TODO: Apply array structure mutations (swap, insert, delete)`
- I think the parentheses [here](https://github.com/crytic/medusa/blob/master/fuzzing/valuegeneration/generator_mutational.go#L109C2-L109C134) are wrong: `mutationCount := g.randomProvider.Intn(((g.config.MaxMutationRounds - g.config.MinMutationRounds) + 1) + g.config.MinMutationRounds)`

Contributor guide

Open the contributing guide

Research direction

Start in fuzzing/valuegeneration, especially generator_mutational.go and the RandomValueGenerator and MutationalValueGenerator implementations. Trace the generator and mutator interfaces, the argument-encoding helpers, and the mutation-count calculation before deciding which responsibilities can be removed or relocated. Done means the responsibilities are separated cleanly, the mutation-count expression is corrected, and the array-mutation TODO is either implemented or explicitly resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing-qa
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.