-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(linking): deep-merge link_references from creation and deployed bytecode #11759
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
base: master
Are you sure you want to change the base?
fix(linking): deep-merge link_references from creation and deployed bytecode #11759
Conversation
Is there a test case we could add for this that would fail before? @klkvr thoughts? |
Yes, added a test case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, left a suggestion for driveby clean up
also need to commit the test files and investigate whether the linking tests are actually testing anything
|
||
#[test] | ||
fn link_samefile_union() { | ||
link_test("../../testdata/default/linking/samefile_union", |linker| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you didn't commit the linking/samefile_union
but the test is still passing somehow 🤔
crates/linking/src/lib.rs
Outdated
let mut references: BTreeMap<String, BTreeMap<String, Vec<Offsets>>> = BTreeMap::new(); | ||
if let Some(bytecode) = &contract.bytecode { | ||
references.extend(bytecode.link_references.clone()); | ||
for (file, libs) in &bytecode.link_references { | ||
let entry = references.entry(file.clone()).or_default(); | ||
for (name, offsets) in libs { | ||
entry.entry(name.clone()).or_default().extend(offsets.clone()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the issue is that we were not supposed to use extend
here bc it would make second cycle's values overwrite the file keys
this does make sense
it seems that we accumulate offsets
in this map for no reason, do you mind also getting rid of this and changing references
to BTreeMap<String, BTreeSet<String>>
so that it's a bit easier to reason about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the issue is that we were not supposed to use
extend
here bc it would make second cycle's values overwrite the file keysthis does make sense
it seems that we accumulate
offsets
in this map for no reason, do you mind also getting rid of this and changingreferences
toBTreeMap<String, BTreeSet<String>>
so that it's a bit easier to reason about?
done, also added a test if artifacts are missing and committed samefile_union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs rebase and ci fixes
554024c
to
50d62f7
Compare
test / nextest / test unit (x86_64-pc-windows-msvc) (pull_request) I'm sorry but i can't fix this, i can't just test it on my computer, it's not that powerful, and I think making noise here is not the best idea.. |
crates/linking/src/lib.rs
Outdated
), | ||
( | ||
"default/linking/duplicate/Duplicate.t.sol:C", | ||
"default/linking/duplicate/Duplicate.t.sol:C".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please undo these changes, you accepted the wrong side when merging master
7625f36
to
514142f
Compare
Before: Dependencies were built by shallow-merging link_references maps via extend. When both creation and deployed bytecode contained references under the same file key but with different library names, the latter overwrote the former, dropping dependencies.
After: We deep-merge the inner maps per file, unioning library names and offsets from both sources. This matches how we link and validate both bytecode objects and aligns with forge inspect ... libraries (union semantics). Prevents missing libs when a file has libraries used exclusively in constructor vs runtime.