truffle
truffle copied to clipboard
Truffle and Hardhat with same compiler options compile different bytecode
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
Hey, thanks for reporting this! Can you create a gist with a diff that shows where the bytecodes differ? It might help us see at a glance why this is happening (if you happen to still have both sets of bytecodes handy)
Here the files with the two different bytecodes truffle.txt hardhat.txt
Here another example for a library: truffle.txt hardhat.txt
@Aleione I went to try and reproduce using the steps above but it seems there is no feature/uma-integration-part-2 branch. Did you delete it?
@eggplantzzz yes, it was merged in dev branch. This is the link of dev branch with smart contracts: https://gitlab.com/jarvis-network/apps/exchange/mono-repo/-/tree/dev/libs/contracts/contracts
@Aleione just a quick question: do you know whether you are comparing the same type of bytecode? In the Truffle artifact you will find at least 2 bytecode-related fields: bytecode and deployedBytecode. The first one is the "create bytecode" and the second is the "call bytecode" (the bytecode found on chain after deployment). Can you confirm that you are comparing the same type of bytecode? We'll try and reproduce your results using the project linked to above. Thanks!
Hm, it can't be that -- all of these start with the delegatecall guard; that's only used in deployed bytecode for libraries. So these can't be constructor bytecode.
@Aleione I'm trying to reproduce this problem, but I can't seem to clone the repo; I'm getting a permission denied error. How can I clone your repo?
@Aleione OK, I just downloaded it as a zip file instead. Problem is, neither yarn truffle compile nor yarn hardhat compile seem to do anything. Do I need to use an older commit or something? Thank you!
Oh hm, wonder if #5441 could be responsible here...?
@Aleione are you still available to help @haltman-at with his question from above? We'd love to figure out what the cause is.
Problem is, neither yarn truffle compile nor yarn hardhat compile seem to do anything. Do I need to use an older commit or something? Thank you!
Closing for issue maintenance. @Aleione When you have the repro steps and if you're still running into this problem please feel free to re-open! Thanks.
Re-opening this on the hunch that it's related to Truffle's solc defaults.
See https://github.com/trufflesuite/truffle/issues/5441 and associated PR https://github.com/trufflesuite/truffle/pull/5935