-
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
Hardhat and Truffle with same compiler options compile different bytecode #1147
Comments
Hey @Aleione, Truffle and Hardhat use different artifacts structures. Hardhat's artifacts are mostly compatible with Truffle, but there's no strong guarantee of full compatibility. How are you comparing them? |
I compare the two artifacts for a same contracts. I extract the deployed bytecode field from the artifacts and i compare the two bytecodes. And there are some differences. I have compared using both git diff and winMerge |
@Aleione where is the source for the |
Can you post them here? |
Here the source for getHardhatConfig: https://gitlab.com/jarvis-network/apps/exchange/UMAprotocol/-/blob/jarvis-dev/for-publish/0.3.x/packages/common/src/HardhatConfig.js Here an example of bytecode mismatch: |
@Aleione Are you sure you're using the same compiler version in both cases? One difference that immediately stands out when you look at these files is that the output from Hardhat one has new-style linker references (which look like this: Are you perhaps comparing with some older build output from Truffle? The bytecode is not stable between solc versions (even the minor releases). If you want to reproduce the bytecode, you have to use the same exact compiler version. |
@cameel The compiler version, runs, optimizer and EVM version are the same. You can check in build folder (truffle) and artifact folder (hardhat) this infos, and check that are the same. The difference in library links are independent from the mismatch. You can see the mismatch also in TICHelper contract that does not include any reference with external libraries. |
@Aleione Did you try disabling the bytecode hash? Here's how I do it in my template: |
This unfortunately seems to be a bug in the compiler. Recently we got two issues with enough input that we could actually reproduce and investigate the problem (ethereum/solidity#12281, ethereum/solidity#12415) and it turns out that 0.6.12 and 0.7.0 can output different bytecode with the same metadata. The problem only occurs if the sets of files you're compiling are not identical in both cases. When using a framework like Truffle or Hardhat this usually means that to reproduce the bytecode you need to include all the input files from your project, not just those that are actually used by the contract you want to reproduce. For example omitting |
Thanks for the update, @cameel. Is this bug also present if you don't use the optimizer? |
I think it isn't. I have only seen it happen with optimizer enabled. The differences in the bytecode all seem to come from different decisions made by the optimizer. Probably because things are sorted differently and processed in a different order. |
That matches with our experience and this other issue. I'm also seen the same happen when the name of top-level/entry-point files change. For example, if you have a file |
Hardhat has a workaround for the solc versions affected by this bug, so I'm closing this. |
Issue
In the same repository i have set config file for truffle and hardhat. Compiler options (version, evm version, optimizer and runs) are the same. If i compare bytecode between truffle build folder and hardhat artifacts folder, for the same solidity contract, they are different. In this way we can not verify some contract with hardhat/etherscan since it can not detect the code deployed using truffle migration (since hardhat does not support migration). Other problem can be for developers that will use CREATE2 opcode in their solidity code.
Steps to Reproduce
You can reproduce it in this way:
clone code at this link: https://gitlab.com/jarvis-network/apps/exchange/mono-repo
move in branch: feature/uma-integration-part-2
yarn install
cd libs/contracts
yarn truffle compile
yarn hardhat compile
Expected Behavior
Same bytecode in artifacts folder (Truffle and Hardhat) for all contracts
Actual Results
There are differences in bytecode in some contracts (Ex. TICHelper, TICFactory, PerpetualLiquidatblePoolParty, PerpetualPoolPartyLib, PoolFactory, PoolLib)
Environment
Operating System: Ubuntu 18.04.5 LTS
Truffle version (truffle version): 5.1.49
node version (node --version): 14.9.0
yarn version (yarn --version): 1.22.4
The text was updated successfully, but these errors were encountered: