truffle icon indicating copy to clipboard operation
truffle copied to clipboard

Truffle and Hardhat with same compiler options compile different bytecode

Open Aleione opened this issue 4 years ago • 13 comments

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

Aleione avatar Jan 03 '21 14:01 Aleione

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)

gnidan avatar Jan 04 '21 22:01 gnidan

Here the files with the two different bytecodes truffle.txt hardhat.txt

Aleione avatar Jan 05 '21 16:01 Aleione

Here another example for a library: truffle.txt hardhat.txt

Aleione avatar Jan 05 '21 16:01 Aleione

@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 avatar Jan 22 '21 16:01 eggplantzzz

@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 avatar Jan 23 '21 14:01 Aleione

@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!

eggplantzzz avatar Jan 27 '21 19:01 eggplantzzz

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.

haltman-at avatar Aug 04 '22 21:08 haltman-at

@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?

haltman-at avatar Aug 04 '22 22:08 haltman-at

@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!

haltman-at avatar Aug 04 '22 23:08 haltman-at

Oh hm, wonder if #5441 could be responsible here...?

haltman-at avatar Aug 16 '22 01:08 haltman-at

@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!

davidmurdoch avatar Sep 15 '22 17:09 davidmurdoch

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.

cliffoo avatar Oct 13 '22 17:10 cliffoo

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

gnidan avatar Mar 10 '23 19:03 gnidan