foundry-rs / foundry-rs/foundry

feat(`improvement`): identify contracts by hash, not bytecode

Open
#9,443 1 comment 0 reactions 0 assignees View on GitHub
A-internals Cmd-forge-coverage T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### Component

Forge

### Describe the feature you would like

We already collect coverage hitmaps by bytecode hash, we can use this to avoid the hacky heuristics of finding a matching artifact using the bytecode itself.

- In this loop, the key is the bytecode hash, which is currently ignored: https://github.com/foundry-rs/foundry/blob/7a23a5cf851b991bfd2fde32d4f088319bbc1183/crates/forge/bin/cmd/coverage.rs#L253
- We try to find a match using bytecodes with `ContractsByArtifact::find_by*` https://github.com/foundry-rs/foundry/blob/7a23a5cf851b991bfd2fde32d4f088319bbc1183/crates/forge/bin/cmd/coverage.rs#L254-L260

This also applies to all the other callsites of these functions, except for the `getArtifactPathBy[Deployed]Code` cheatcodes, where we would have to compute the hash ourselves.

By computing the hashes of the bytecodes and looking up the artifacts by code hash, we will be able to get rid of the `find_by*code` functions altogether.

cc @klkvr @grandizzy

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.