Fix library reference substitution and regular expression matching for both contracts and libraries #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR addresses two related issues in the
zodiac-core
package.Library Reference Replacement in Bytecode:
There was a critical issue where the
OZGovernor
contract, which depends on theMultisendEncoder
library, would fail to deploy because the contract bytecode saved a reference to the library but not its address. This caused deployment failures since the library's placeholder in the bytecode was not being correctly replaced by the actual deployed address.Regular Expression Mismatch in
sourcePathFromSourceCode
:Additionally, the
sourcePathFromSourceCode
function was returningnull
when attempting to resolve theMultisendEncoder
contract. Upon investigation, it was discovered thatMultisendEncoder
is actually defined as alibrary
, not acontract
, and the function's regular expression was only matchingcontract
definitions. This mismatch caused the function to fail when looking for libraries.Solutions:
Library Reference Replacement:
replaceLibraryReferences
function to handle replacing placeholders in the contract bytecode with the actual deployed addresses of libraries.OZGovernor
contract can now correctly link to theMultisendEncoder
library during deployment.Regular Expression Update in
sourcePathFromSourceCode
:sourcePathFromSourceCode
function to match bothcontract
andlibrary
definitions. This change allows the function to successfully resolve libraries as well as contracts.Old RegExp:
New RegExp:
Changes Introduced:
New
replaceLibraryReferences
Function:Integration into
getBuildArtifact
:replaceLibraryReferences
function was integrated intogetBuildArtifact
to ensure that any contract bytecode with library references is correctly resolved and linked before deployment.Regular Expression Fix:
sourcePathFromSourceCode
to match bothcontract
andlibrary
keywords, ensuring libraries likeMultisendEncoder
are properly detected in the source code.Library Address Resolution:
getCreate2Address
to calculate and retrieve the deployed address for libraries, ensuring that theOZGovernor
contract now correctly links withMultisendEncoder
.Testing:
OZGovernor
contract using the updated bytecode, ensuring library references were correctly replaced and the contract no longer fails during deployment.sourcePathFromSourceCode
function now resolves both contracts and libraries.