crytic / crytic/crytic-compile
Feature: Add `linkReferences` as part of the `standard` and `solc` export formats
- Dominant language
- Python
- Stars
- 197
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
Library linking is a complex problem due to the various methods that exist for placeholder logic across the various compilation platforms and solidity versions. The common thread that exists across most compilation platforms (e.g. hardhat, brownie, foundry) is that they use solc's standard JSON input/output methodology for multi-source compilation. As part of the standard JSON output, there is an object called `linkReferences`. See [here](https://docs.soliditylang.org/en/v0.8.17/using-the-compiler.html#output-description). An example `linkReferences` object:
```
"linkReferences": {
"libraryFile.sol": {
// Byte offsets into the bytecode.
// Linking replaces the 20 bytes located there.
"Library1": [
{ "start": 0, "length": 20 },
{ "start": 200, "length": 20 }
]
}
}
```
The `linkReferences` tells you (a) what libraries does a given contract / library depend on and (b) where the placeholders are for the library's address. These are the two pieces necessary for manually linking libraries. This would solve issues like https://github.com/crytic/echidna/issues/836 and also simplify CC's logic with identifying the `LibraryName -> Placeholder` mapping.
Thus, CC can grab this information from a given compilation framework and add it to the `solc` and `standard` export formats.
Contributor guide
Assessment
This issue has not been assessed yet.