Skip to content
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

Different bytecodes for the same contracts #6487

Closed
sammyne opened this issue Apr 7, 2019 · 6 comments
Closed

Different bytecodes for the same contracts #6487

sammyne opened this issue Apr 7, 2019 · 6 comments
Assignees

Comments

@sammyne
Copy link

sammyne commented Apr 7, 2019

Description

Bug

Given the same contracts file but different path, compile with solc generate different bytecodes

Expectation

The same contract manifest should produce the same bytecodes

Environment

  • Compiler version: 0.5.7+commit.6da8b019.Linux.g++
  • Target EVM version (as per compiler settings): No
  • Framework/IDE (e.g. Truffle or Remix): No
  • EVM execution environment / backend / blockchain client: No
  • Operating system: Fedora 29

Steps to Reproduce

To ease the reproduction, I have make a repository as solidity-playground containing the relevant files below, and the steps for reproduce the problem found go as follows

  1. Clone the repository and change into the repository directory

    git clone https://github.com/sammyne/solidity-playground.git && cd solidity-playground
  2. In the root directory, compile the World contract described as contracts/World.sol with bytecodes output to current directory

    solc --bin --optimize contracts/World.sol -o .

    This should give us two files Hello.bin and World.bin containing bytecodes for the respective contracts

  3. Change into the contracts folder, and compile the World.sol with bytecodes output to that folder

    solc --bin --optimize World.sol -o .

    This should also give us two files Hello.bin and World.bin containing bytecodes for the respective contracts

  4. Comparison tells difference

    • Compare the Hello.bin and contracts/Hello.bin with diff would tell us difference
    • Compare the World.bin and contracts/World.bin with diff would tell us difference
@erak erak self-assigned this Apr 8, 2019
@erak
Copy link
Collaborator

erak commented Apr 8, 2019

@sammyne Thanks for your report. I'll have a look!

@chriseth
Copy link
Contributor

This is expected behaviour. The reason behind this is that depending on the paths used, import statements will behave differently. So the (relative) paths are exposed as the unique names of contracts when compiling. Since the bytecode contains the metadata information of contracts, this also affects the bytecode.

@rickbeeloo
Copy link

Same here, https://snowtrace.io/contractdiffchecker?a2=0x0804Dd62deb46F11cDf47997778527B067E0D054&a1=0xB43C0e6460DAE61280fd4e6E793ae43Ed72AFA57, only difference I saw is that one had optimization enabled and other one did not. Could this cause that?

@cameel
Copy link
Member

cameel commented Dec 14, 2021

These contracts are not identical. Parameters passed to the inherited constructor differ:

constructor() ERC20("WAVAXPrinter", "WAVAXP", 9) {

vs

constructor() ERC20("SonOfDAO", "SOD", 9) {

@rickbeeloo
Copy link

These contracts are not identical. Parameters passed to the inherited constructor differ:

constructor() ERC20("WAVAXPrinter", "WAVAXP", 9) {

vs

constructor() ERC20("SonOfDAO", "SOD", 9) {

Aah yeah sorry didn't mean it like that, I meant the overall bytecode is completely different while only the constructor is different in the human readable code

@cameel
Copy link
Member

cameel commented Dec 15, 2021

What specifically do you mean by "overall bytecode"? The compiler gives you separate bytecode for each contract it finds. So if constructor parameters are different, this particular contract will have different bytecode even if everything else in it is identical. Other contracts in the same compilation should have identical bytecode (if you ignore the metadata).

Please try to compile with --metadata-hash none (CLI) or metadata: {bytecodeHash: "none"} (Standard JSON). If you're still getting different bytecode with that and you're not on 0.6.12 and 0.7.0 (see #12281), please create a new issue and we'll look into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants