-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Multiple compiler versions leads to overwrite the artifacts/contracts files #1384
Comments
Hey @montyly, Artifacts aren't being overwritten, but we emit one version for each of them. This is like this by design, as otherwise users would have to be thinking about which version they want to use for testing, deployment, etc. A solidity file can be included multiple compilation jobs, and hence multiple build info files. To figure out which was the one that was used for emitting its artifacts, you have to look for the I'm not sure which kind of analysis crytic runs, but it may require some adaptions to work with this multiple versions and compilation jobs per project model. If you tell me more about your needs I can help you understand how it can be done. |
Thanks, @alcuadrado for the details. I am not sure to understand why there are not being overwritten. If by reading But we ended up not using the Regarding our usage, I think there are two cases here: either the codebase requires multiple compilation units (ex: two solidity versions), or it does not require it, and from my understanding hardhat does it for optimization (so you don't need to recompile everything every time). For the first case, we are working on its support in our tools. For the second case, it is more complex. We need to analyze the AST of each contract, and the AST contains unique IDs such that you should analyze the contracts within the same compilation unit context (even if the compiler version is the same). For example, one of these IDs is for the "linearizedBaseContracts":
[
4,
20
], This returns the inherited contracts, in the expected order. Each number matches an Would it be possible to have a command-line flag to disable the split into multiple compilation units optimization? This would ease a lot the integrations of hardhat in our tools (and probably other ones too). A command-line flag would be less intrusive than an option in the config file, so that we can run hardhat within the context of our tools, without messing with the target's configuration. |
Hey @montyly, I'm re-visiting old issues and I'm not sure what to do about this one. Some clarifications about our compilation pipeline: First, this is not an optimization, it's more of a design decision to have a simpler model. The bytecode that ends up in an artifact for a given contract is generated with a single version, and we have some rules to decide which one is used. In fact, there's no way to emit bytecode with different compilers for the same contract. Second, this is (or should be!) deterministic. So for a given configuration of set of files, each file will always be compiled with the same version. It's true that in your example the contract
This is correct, unless you inspect the I think I'm going to close this issue, on the grounds that this is working as intended. But I would very much like to continue discussing this, so if you have any other comments or ideas on what we could do to make your life easier, please let us know. |
Hi,
If a project has multiple compiler versions, the compilation artifacts generated in
artifacts/contracts
can be incomplete. This is because there is one file per contract/path, but multiple compiler versions will lead to a collision in the artifacts. This can prevent the correct analysis from third parties tools (such as Slither / Echidna)For example, for a project with these three files:
contracts/0.6.sol
contracts/0.8.sol
contracts/test.sol
:And this configuration:
Both
artifacts/contracts/test.sol/A.json
andartifacts/contracts/test.sol/A.dbg.json
will be generated only once, while the contractA
will generate a different bytecode with solidity 0.6.7 and 0.8.0. In my tests both files are the 0.8.0 version, but I am assuming this might be random.Note that the files in
artifacts/build-info
don't have this issue.The text was updated successfully, but these errors were encountered: