Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging "contract deployment tx returned a failed status: execution reverted module=fuzzer" #212

Closed
rappie opened this issue Aug 24, 2023 · 15 comments · Fixed by #216
Closed

Comments

@rappie
Copy link

rappie commented Aug 24, 2023

❯ medusa fuzz
⇾ Reading the configuration file at: ./medusa.json
⇾ Compiling targets with crytic-compile module=fuzzer
error Failed to initialize the test chain
‣ contract deployment tx returned a failed status: execution reverted module=fuzzer

How do I debug this? 🙂

@aviggiano
Copy link

I was having a similar bug, it seems like it is an issue with your constructor

Try commenting parts of the logic inside it until you figure out what's causing the revert

@rappie
Copy link
Author

rappie commented Aug 25, 2023

Thanks.

I think it is because my constructor needs a starting balance: #213

It would be nice to have a bit more verbose error reporting for reverts in the constructor 🙂

@aviggiano
Copy link

I think you maybe need to set it as constructor() payable?

@rappie
Copy link
Author

rappie commented Aug 25, 2023

Yes i have it as payable, it works in Echidna.

Gustavo Grieco confirmed there is no starting balance yet, so i'm quite confident this must be the reason, I just didn't fully narrow it down.

@anishnaik
Copy link
Collaborator

Hey guys, currently medusa does not support payable constructors. We will add this feature ASAP.

A decent workaround would be to have a func like this:

func getEther() public payable {
    address(this).transfer(1 ether);
}

At some point medusa will call this and your contract will have ether. You can then have a precondition in the fuzz tests to ensure that your contract has some balance to continue fuzz testing.

@anishnaik
Copy link
Collaborator

anishnaik commented Aug 30, 2023

@rappie + @aviggiano feel free to try out this branch for payable constructors:
https://github.com/crytic/medusa/tree/dev/merge-assertion-and-property-mode

The logic works as follows. The config file now holds a new config option called TargetContractsBalances. This option is an array where each index in the array maps to a contract in the TargetContracts array (note that TargetContracts used to originally be called deploymentOrder).

Here is an example:
Let's say that targetContracts is [a, b, c] and you want to send c 1 ether. Then your targetContractsBalances will be [0, 0, 1e18]. Similarly, if you want to send b 2 ether and c 1 ether then the array will be [0, 2e18, 1e18]

Hope that makes sense and please let me know if you guys have any issues with that branch.

@aviggiano
Copy link

@anishnaik thanks,
I'm still blocked by #211, but I'll try this feature out in other projects when I have opportunity

@anishnaik
Copy link
Collaborator

anishnaik commented Aug 30, 2023

@aviggiano yup we're still looking into that one. Our current theory is that it is because of the inlined bytecode that comes from the create3 library or that we are incorrectly handling create2 calls / metamorphic contracts when tracking coverage. Will try to triage that asap.

@aviggiano
Copy link

@anishnaik

FYI, regarding targetContractsBalances, I wasn't able to use e18 notation

		"targetContractsBalances": [
			"3e24"
		],

I was getting the following error:

[I] ➜ medusa fuzz
⇾ Reading the configuration file at: medusa.json
error Failed to run the fuzz command
‣ json: cannot unmarshal hex string without 0x prefix into Go struct field ProjectConfig.fuzzing of type *hexutil.Big

Then, when I converted the number to hex value, it worked

		"targetContractsBalances": [
			"0x27b46536c66c8e3000000"
		],

But I guess the other notation is better, so there might be a type conversion issue.

@anishnaik
Copy link
Collaborator

@aviggiano that's a good point - I will update the PR the accept arguments such as "3e24"

@anishnaik anishnaik added this to the OOM bug fix milestone Jan 31, 2024
@Renzo1
Copy link

Renzo1 commented Jun 11, 2024

I am using Recon to setup and test my contract, but I still run into this error. It's odd because, Recon implements the above in its config file by default. Everything compiles and runs on Echidna, but not medusa.

@mikerudenko
Copy link

have the same issue...

@ggrieco-tob
Copy link
Member

Let´s re-open this issue to investigate.

@ggrieco-tob ggrieco-tob reopened this Jan 17, 2025
@anishnaik
Copy link
Collaborator

anishnaik commented Jan 21, 2025

@mikerudenko can you describe what the issue is? There is discussion about a few types of issues in this thread so lmk specifically which part is causing problems :)

@anishnaik anishnaik removed this from the Release 0.1.3: OOM bug fix and some new features milestone Jan 28, 2025
@anishnaik anishnaik reopened this Jan 30, 2025
@anishnaik
Copy link
Collaborator

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants