crytic / medusa

Parallelized, coverage-guided, mutational Solidity smart contract fuzzing, powered by go-ethereum
https://secure-contracts.com/program-analysis/medusa/docs/src/
GNU Affero General Public License v3.0
306 stars 41 forks source link

Problem with go-API `undefined: vm.ConfigExtensions` #429

Open mysteryon88 opened 3 months ago

mysteryon88 commented 3 months ago

There is nothing in the documentation about the API, but there is on the Wiki page. I decided to test it, but ran into a problem with imports, I'm not very good at go, but I hope it will help developers and others.

Using v0.1.6

First create a folder, project, etc.

go mod init main

go get github.com/crytic/medusa

Then I took the code from the Wiki

package main

import (
    "fmt"

    "github.com/crytic/medusa/fuzzing"
    "github.com/crytic/medusa/fuzzing/config"
)

func main() {
    projectConfig, err := config.GetDefaultProjectConfig("crytic-compile")
    if err != nil {
        return
    }
    err = projectConfig.Compilation.SetTarget("contract.sol")
    if err != nil {
        return
    }

    projectConfig.Fuzzing.Workers = 20

    fmt.Println(projectConfig)

    fuzzer, err := fuzzing.NewFuzzer(*projectConfig)
    if err != nil {
        return
    }

    // Start the fuzzer
    err = fuzzer.Start()
    if err != nil {
        return
    }

    // Fetch test cases results
    testCases := fuzzer.TestCases()

    fmt.Println(testCases)

}

After starting up, the error:

..\..\..\go\pkg\mod\github.com\crytic\medusa@v0.1.6\chain\config\config.go:32:55: undefined: vm.ConfigExtensions
..\..\..\go\pkg\mod\github.com\crytic\medusa@v0.1.6\chain\config\config.go:40:13: undefined: vm.ConfigExtensions

How fixed:

  1. Added a line to my go.mod:
    replace github.com/ethereum/go-ethereum => github.com/crytic/medusa-geth v0.0.0-20240708141007-2f7f9258289f
  2. Added a package go-ethereum
    go get github.com/ethereum/go-ethereum@v1.14.6

I re-run the code and everything works fine, which is very satisfying)

  1. Why does this happen?
  2. Is there an easier way to use the API?
anishnaik commented 3 months ago
  1. I'm not exactly sure but it seems like there was an issue with the dependencies of medusa (the most important one being medusa-geth). You may have had to run go mod tidy after installing medusa and that may have worked.
  2. Unfortunately, right now our API is pretty low-level. Our goal is for it to be a lot more high-level and extensible but it may take some time for it to get there. Also, just FYI, the documentation for the API is pretty outdated so (unfortunately) your best bet is to check out the code directly to see how to interact with medusa. This is why we haven't added the docs to the mdbook.

P.S. You are the first person ever to use the low-level API which makes me very happy :) Any feedback would be greatly appreciated.

mysteryon88 commented 3 months ago

Yes, I tried go mod tidy, but it didn't work. At one point I even tried to manually install medusa-geth, via git clone, but it turned out the same as if I went into medusa and inside the package called go mod tidy I've only managed to run it so far, I haven't dealt with hooks and events yet.

anishnaik commented 3 months ago

What was the error with go mod tidy?

mysteryon88 commented 3 months ago

There was no error, just the imports didn't work on the bottom line. That is, I entered a command and nothing happened.