Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/github.com/rs/zerolo…
Browse files Browse the repository at this point in the history
…g-1.30.0
  • Loading branch information
Xenomega authored Aug 22, 2023
2 parents d99e5f7 + 928311f commit 09ded53
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 180 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ It provides parallelized fuzz testing of smart contracts through CLI, or its Go

### Precompiled binaries

To use `medusa`, first ensure you have [crytic-compile](https://github.com/crytic/crytic-compile) and a suitable compilation framework (e.g. `solc`, `hardhat`) installed on your machine.
To use `medusa`, ensure you have:

- [crytic-compile](https://github.com/crytic/crytic-compile) (`pip3 install crytic-compile`)
- a suitable compilation framework (e.g. `solc`, `hardhat`) installed on your machine. We recommend [solc-select](https://github.com/crytic/solc-select) to quickly switch between Solidity compiler versions.

You can then fetch the latest binaries for your platform from our [GitHub Releases](https://github.com/crytic/medusa/releases) page.

Expand Down
10 changes: 6 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/crytic/medusa/logging"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"io"
"os"
)

const version = "0.1.1"
Expand All @@ -18,11 +18,13 @@ var rootCmd = &cobra.Command{
}

// cmdLogger is the logger that will be used for the cmd package
var cmdLogger = logging.NewLogger(zerolog.InfoLevel, true, make([]io.Writer, 0)...)
var cmdLogger = logging.NewLogger(zerolog.InfoLevel)

// Execute provides an exportable function to invoke the CLI.
// Returns an error if one was encountered.
// Execute provides an exportable function to invoke the CLI. Returns an error if one was encountered.
func Execute() error {
// Add stdout as an unstructured, colorized output stream for the command logger
cmdLogger.AddWriter(os.Stdout, logging.UNSTRUCTURED, true)

rootCmd.CompletionOptions.DisableDefaultCmd = true
return rootCmd.Execute()
}
14 changes: 6 additions & 8 deletions fuzzing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"github.com/crytic/medusa/logging"
"github.com/crytic/medusa/logging/colors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/pkgerrors"
"io"
"math/big"
"math/rand"
"os"
"path/filepath"
"runtime"
"sort"
Expand Down Expand Up @@ -89,12 +88,11 @@ type Fuzzer struct {
// NewFuzzer returns an instance of a new Fuzzer provided a project configuration, or an error if one is encountered
// while initializing the code.
func NewFuzzer(config config.ProjectConfig) (*Fuzzer, error) {
// Create the global logger, set some global logging parameters, and enable terminal coloring
logging.GlobalLogger = logging.NewLogger(config.Logging.Level, true, make([]io.Writer, 0)...)
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
// Create the global logger and add stdout as an unstructured, colored output stream
logging.GlobalLogger = logging.NewLogger(config.Logging.Level)
logging.GlobalLogger.AddWriter(os.Stdout, logging.UNSTRUCTURED, true)

// If the log directory is a non-empty string, create a file for file logging
// If the log directory is a non-empty string, create a file for unstructured, un-colorized file logging
if config.Logging.LogDirectory != "" {
// Filename will be the "log-current_unix_timestamp.log"
filename := "log-" + strconv.FormatInt(time.Now().Unix(), 10) + ".log"
Expand All @@ -104,7 +102,7 @@ func NewFuzzer(config config.ProjectConfig) (*Fuzzer, error) {
logging.GlobalLogger.Error("Failed to create log file", err)
return nil, err
}
logging.GlobalLogger.AddWriter(file, logging.UNSTRUCTURED)
logging.GlobalLogger.AddWriter(file, logging.UNSTRUCTURED, false)
}

// Get the fuzzer's custom sub-logger
Expand Down
16 changes: 16 additions & 0 deletions logging/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package logging

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/pkgerrors"
)

// init will instantiate the global logger and set up some global parameters from the zerolog package.
func init() {
// Instantiate the global logger
GlobalLogger = NewLogger(zerolog.Disabled)

// Setup stack trace support and set the timestamp format to UNIX
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
}
Loading

0 comments on commit 09ded53

Please sign in to comment.