Skip to content

Commit

Permalink
Introduce --use-slither-force flag (#542)
Browse files Browse the repository at this point in the history
* introduce new flag and allow for cache to be overwritten

* Fix prettier
  • Loading branch information
anishnaik authored Jan 15, 2025
1 parent 58e98c7 commit 5b1f748
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
21 changes: 18 additions & 3 deletions cmd/fuzz_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ func addFuzzFlags() error {
// Exploration mode
fuzzCmd.Flags().Bool("explore", false, "enables exploration mode")

// Run slither on-the-fly
fuzzCmd.Flags().Bool("use-slither", false, "runs slither")
// Run slither while still trying to use the cache
fuzzCmd.Flags().Bool("use-slither", false, "runs slither and use the current cached results")

// Run slither and overwrite the cache
fuzzCmd.Flags().Bool("use-slither-force", false, "runs slither and overwrite the cached results")
return nil
}

Expand Down Expand Up @@ -196,7 +199,7 @@ func updateProjectConfigWithFuzzFlags(cmd *cobra.Command, projectConfig *config.
}
}

// Update configuration to run slither
// Update configuration to run slither while using current cache
if cmd.Flags().Changed("use-slither") {
useSlither, err := cmd.Flags().GetBool("use-slither")
if err != nil {
Expand All @@ -207,5 +210,17 @@ func updateProjectConfigWithFuzzFlags(cmd *cobra.Command, projectConfig *config.
}
}

// Update configuration to run slither and overwrite the current cache
if cmd.Flags().Changed("use-slither-force") {
useSlitherForce, err := cmd.Flags().GetBool("use-slither-force")
if err != nil {
return err
}
if useSlitherForce {
projectConfig.Slither.UseSlither = true
projectConfig.Slither.OverwriteCache = true
}
}

return nil
}
10 changes: 7 additions & 3 deletions compilation/types/slither.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ type SlitherConfig struct {
UseSlither bool `json:"useSlither"`
// CachePath determines the path where the slither cache file will be located
CachePath string `json:"cachePath"`
// OverwriteCache determines whether to overwrite the cache or not
// We will not serialize this value since it is something we want to control internally
OverwriteCache bool `json:"-"`
}

// NewDefaultSlitherConfig provides a default configuration to run slither. The default configuration enables the
// running of slither with the use of a cache.
func NewDefaultSlitherConfig() (*SlitherConfig, error) {
return &SlitherConfig{
UseSlither: true,
CachePath: "slither_results.json",
UseSlither: true,
CachePath: "slither_results.json",
OverwriteCache: false,
}, nil
}

Expand Down Expand Up @@ -53,7 +57,7 @@ func (s *SlitherConfig) RunSlither(target string) (*SlitherResults, error) {
var haveCachedResults bool
var out []byte
var err error
if s.CachePath != "" {
if s.CachePath != "" && !s.OverwriteCache {
// Check to see if the file exists in the first place.
// If not, we will re-run slither
if _, err = os.Stat(s.CachePath); os.IsNotExist(err) {
Expand Down
25 changes: 24 additions & 1 deletion docs/src/cli/fuzz.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ The `--deployer` flag allows you to update `medusa`'s contract deployer (equival
medusa fuzz --deployer "0x40000"
```

### `--use-slither`

The `--use-slither` flag allows you to run Slither on the codebase to extract valuable constants for mutation testing.
Equivalent to [`slither.useSlither`](../project_configuration/slither_config.md#useslither). Note
that if there are cached results (via [`slither.CachePath`](../project_configuration/slither_config.md#cachepath)) then
the cache will be used.

```shell
# Run slither and attempt to use cache, if available
medusa fuzz --use-slither
```

### `--use-slither-force`

The `--use-slither-force` flag is similar to `--use-slither` except the cache at `slither.CachePath` will be
overwritten.

```shell
# Run slither and overwrite the cache
medusa fuzz --use-slither-force
```

### `--fail-fast`

The `--fail-fast` flag enables fast failure (equivalent to
Expand Down Expand Up @@ -142,7 +164,8 @@ medusa fuzz --no-color

### `--explore`

The `--explore` flag enables exploration mode. This sets the [`StopOnFailedTest`](../project_configuration/testing_config.md#stoponfailedtest) and [`StopOnNoTests`](../project_configuration/testing_config.md#stoponnotests) fields to `false` and turns off assertion, property, and optimization testing.
The `--explore` flag enables exploration mode. This sets the [`StopOnFailedTest`](../project_configuration/testing_config.md#stoponfailedtest) and [`StopOnNoTests`](../project_configuration/testing_config.md#stoponnotests)
fields to `false` and turns off assertion, property, and optimization testing.

```shell
# Enable exploration mode
Expand Down

0 comments on commit 5b1f748

Please sign in to comment.