Skip to content

Implement getCode cheatcode#593

Merged
anishnaik merged 19 commits intocrytic:masterfrom
0xZRA:dev/add-vm-getcode-cheatcode
Mar 24, 2025
Merged

Implement getCode cheatcode#593
anishnaik merged 19 commits intocrytic:masterfrom
0xZRA:dev/add-vm-getcode-cheatcode

Conversation

@0xZRA
Copy link
Copy Markdown
Contributor

@0xZRA 0xZRA commented Mar 10, 2025

This PR will close #576

@0xZRA
Copy link
Copy Markdown
Contributor Author

0xZRA commented Mar 10, 2025

This is still WIP
@anishnaik Looking for early feedback. I settled on ContractBytecodes or CompiledContracts to avoid adding the logic for opening the file + looking for the bytecode in the handler (but still be able to connect compiled contract with the tracer). Using CompiledContracts will provide contract context access for future cheatcode implementations but I don't know if it's truly needed at this time. I additionally tried the following strategies but didn't get successful results:

  • Added Fuzzer field to TestChain struct:
    • Set the reference when creating the chain
    • Access Fuzzer's contract definitions through this reference
    • Issue: Creates import cycle between packages (test_chain.go <-> fuzzer.go)
  • Use fuzzer context passed to TestChain
    • Store and retrieve Fuzzer through context
    • Issue: probably not best use of the context

On a separate note, fuzzing.fuzzer_test.TestCheatCodes fails on the master branch on my machine

@0xZRA 0xZRA marked this pull request as ready for review March 10, 2025 21:29
@anishnaik
Copy link
Copy Markdown
Collaborator

Hey @0xZRA sorry for the delay - will provide feedback today :)


require(deployedHash == referenceHash, "Retrieved bytecode doesn't match reference");
}
} No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to add a newline here

@anishnaik
Copy link
Copy Markdown
Collaborator

@0xZRA before reviewing the PR i want to make sure we satisfy the issue. It is possible that the creator of the issue does in fact want the versioning support as well. If they do then you may need to add support for that as well.

@0xZRA
Copy link
Copy Markdown
Contributor Author

0xZRA commented Mar 20, 2025

@0xZRA before reviewing the PR i want to make sure we satisfy the issue. It is possible that the creator of the issue does in fact want the versioning support as well. If they do then you may need to add support for that as well.

@anishnaik For sure, makes sense to me

Copy link
Copy Markdown
Collaborator

@anishnaik anishnaik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major feedback outside of the optimization I mentioned :) Appreciate all the work!

@0xZRA
Copy link
Copy Markdown
Contributor Author

0xZRA commented Mar 21, 2025

No major feedback outside of the optimization I mentioned :) Appreciate all the work!

I should be able to wrap this up within next few days

@0xZRA 0xZRA changed the title [WIP] Implement getCode cheatcode Implement getCode cheatcode Mar 23, 2025
@0xZRA
Copy link
Copy Markdown
Contributor Author

0xZRA commented Mar 23, 2025

@anishnaik I'm concerned that without being able to run the tests locally, there's no way for me to confirm if the proposed code is functioning correctly. Other than that, the changes are ready for your review

@anishnaik
Copy link
Copy Markdown
Collaborator

Hey @0xZRA I'm going to push the patch for the bug in the master branch right now. Then you will be able to pull it down and make sure all the tests pass locally. Btw you should still be able to specifically test your unit test instead of running the whole test suite. That should help you validate the expected behavior.

@anishnaik
Copy link
Copy Markdown
Collaborator

Btw I know why your test is failing - your test contract's name has to be TestContract.

@0xZRA
Copy link
Copy Markdown
Contributor Author

0xZRA commented Mar 24, 2025

Btw I know why your test is failing - your test contract's name has to be TestContract.

Thank you, it worked!

@anishnaik
Copy link
Copy Markdown
Collaborator

@0xZRA can you fix the compilation issues in the test?

@anishnaik anishnaik merged commit 1bfb878 into crytic:master Mar 24, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add vm.getCode cheatcode

2 participants