Skip to content

Commit d27ca68

Browse files
committed
fix(linking): deep-merge link_references from creation and deployed bytecode
1 parent f653eda commit d27ca68

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/linking/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,27 @@ impl<'a> Linker<'a> {
105105
) -> Result<(), LinkerError> {
106106
let contract = self.contracts.get(target).ok_or(LinkerError::MissingTargetArtifact)?;
107107

108+
// Deep-merge link references from creation and deployed bytecode.
109+
// This ensures we don't lose libraries when both bytecode objects reference
110+
// libraries under the same source file key but with different library names.
108111
let mut references = BTreeMap::new();
109112
if let Some(bytecode) = &contract.bytecode {
110-
references.extend(bytecode.link_references.clone());
113+
for (file, libs) in &bytecode.link_references {
114+
let entry = references.entry(file.clone()).or_insert_with(BTreeMap::new);
115+
for (name, offsets) in libs {
116+
entry.entry(name.clone()).or_insert_with(Vec::new).extend(offsets.clone());
117+
}
118+
}
111119
}
112120
if let Some(deployed_bytecode) = &contract.deployed_bytecode
113121
&& let Some(bytecode) = &deployed_bytecode.bytecode
114122
{
115-
references.extend(bytecode.link_references.clone());
123+
for (file, libs) in &bytecode.link_references {
124+
let entry = references.entry(file.clone()).or_insert_with(BTreeMap::new);
125+
for (name, offsets) in libs {
126+
entry.entry(name.clone()).or_insert_with(Vec::new).extend(offsets.clone());
127+
}
128+
}
116129
}
117130

118131
for (file, libs) in &references {

0 commit comments

Comments
 (0)