medusa icon indicating copy to clipboard operation
medusa copied to clipboard

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

Open mysteryon88 opened this issue 1 year ago • 4 comments

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\[email protected]\chain\config\config.go:32:55: undefined: vm.ConfigExtensions
..\..\..\go\pkg\mod\github.com\crytic\[email protected]\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
  1. Added a package go-ethereum
go get github.com/ethereum/[email protected]

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?

mysteryon88 avatar Aug 06 '24 15:08 mysteryon88

  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.

anishnaik avatar Aug 06 '24 15:08 anishnaik

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.

mysteryon88 avatar Aug 06 '24 15:08 mysteryon88

What was the error with go mod tidy?

anishnaik avatar Aug 08 '24 14:08 anishnaik

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

mysteryon88 avatar Aug 09 '24 09:08 mysteryon88

@anishnaik

Hi, after 4 months, came back to sweat the API, very cool, posted an example here.

I see that you want to replace CompilationConfig and PlatformConfig in the future. Was looking for a way to add arguments to the compiler but the only way I found is to manually edit the bytes, am I right or is there a better way?

And the dependency problem is still there, had to do replace and go get github.com/ethereum/go-ethereum again

mysteryon88 avatar Dec 09 '24 08:12 mysteryon88

Hey @mysteryon88 sorry for the delay in getting back to you! One way you could improve it is if you are using crytic-compile as your platform (which I am sure you are) you can type assert on the PlatformConfig. You can assert that it is of type CryticCompilationConfig. Once you convert it into that, you can set the CryticCompilationArgs.Args as you see fit.

And yea I'm sorry I haven't gotten to the dependency issue yet. We are actually planning on getting rid of the replace directive completely which should allow for a simple go get in the future.

anishnaik avatar Jan 28 '25 21:01 anishnaik

@mysteryon88 happy to announce that we finally got rid of the replace directive in medusa. This means that you can easily do go install of medusa now. Closing this issue. Feel free to re-open in case you have any other issues

anishnaik avatar Mar 26 '25 18:03 anishnaik