Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Truffle and Hardhat with same compiler options compile different bytecode #3649

Open
Aleione opened this issue Jan 3, 2021 · 13 comments
Open

Comments

@Aleione
Copy link

Aleione commented Jan 3, 2021

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
@gnidan
Copy link
Contributor

gnidan commented Jan 4, 2021

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)

@Aleione
Copy link
Author

Aleione commented Jan 5, 2021

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

@Aleione
Copy link
Author

Aleione commented Jan 5, 2021

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

@eggplantzzz
Copy link
Contributor

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

@Aleione
Copy link
Author

Aleione commented Jan 23, 2021

@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

@eggplantzzz
Copy link
Contributor

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

@haltman-at
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Contributor

@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
Copy link
Contributor

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

@davidmurdoch
Copy link
Member

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

@cliffoo
Copy link
Contributor

cliffoo commented Oct 13, 2022

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 cliffoo closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2022
@gnidan
Copy link
Contributor

gnidan commented Mar 10, 2023

Re-opening this on the hunch that it's related to Truffle's solc defaults.

See #5441 and associated PR #5935

@gnidan gnidan reopened this Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants