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

fix(coverage): ensure contract hash to record coverage for is not zero #8698

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

grandizzy
Copy link
Collaborator

Motivation

  • for contracts that are not already created the hash in interpreter is 0x. This leads to recording coverage for 0x hash instead of contract hash (and if multiple contracts created in same test then only the first one will have constructor covered).

Solution

  • in coverage collector, if hash is 0 then recalculate it from contract bytecode

@grandizzy grandizzy marked this pull request as ready for review August 20, 2024 13:34
@grandizzy grandizzy enabled auto-merge (squash) August 20, 2024 13:34
@grandizzy grandizzy requested a review from klkvr August 20, 2024 13:41
@klkvr
Copy link
Member

klkvr commented Aug 20, 2024

hmm, wondering if this should be fixed in revm instead? cc @rakita

@grandizzy
Copy link
Collaborator Author

hmm, wondering if this should be fixed in revm instead? cc @rakita

yeah, I guess we could set init_code_hash to bytecode.hash_slow if it's 0 here: https://github.com/bluealloy/revm/blob/main/crates/revm/src/context/evm_context.rs#L295 but not sure about other side effects @rakita any insights highly appreciated! thank you!

@grandizzy grandizzy merged commit f808d08 into foundry-rs:master Aug 21, 2024
20 checks passed
@DaniPopes
Copy link
Member

oops sorry didnt see the comments, in any case a fix here is fine for now

@grandizzy
Copy link
Collaborator Author

oops sorry didnt see the comments, in any case a fix here is fine for now

yep, will follow up if fix in revm too. Thanks!

benwjhack pushed a commit to CompassLabs/foundry-test that referenced this pull request Sep 11, 2024
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.

3 participants