Getting different binary for the same Solidity source code compiling with solc and Remix

41 views Asked by At

I'm noticing a difference in the binary generated using the same solc compiler in local and with Remix.

Here's the source code:

pragma solidity 0.8.20;
contract HelloWorld {}

I compiled it in local using solc 0.8.20+commit.a1b79de6.Darwin.appleclang with the following command: solc --bin --evm-version=shanghai src/HelloWorld.sol

Then I compiled it using remix:

enter image description here

Using solc in local I get: 6080604052348015600e575f80fd5b50603e80601a5f395ff3fe60806040525f80fdfea26469706673582212207b2707958b214a2fbb3ee97873fd5450b38f093d306ca27f3ab234659b8a6f8064736f6c63430008140033

Using Remix: 6080604052348015600e575f80fd5b50603e80601a5f395ff3fe60806040525f80fdfea2646970667358221220d6df573e47185fc28b4a57d786409da70c81ef5acd34160533da68ef8405873c64736f6c63430008140033

At first sight the outputs look identical but they are different. I used the same compiler version, same evm version and no optimization, so I wonder what else could cause this difference?

1

There are 1 answers

1
Flavio On BEST ANSWER

Its problable that this difference is related with the part of the binary that cointains the metadata hash and not the code itself. See https://docs.soliditylang.org/en/latest/metadata.html

You can test use the flag --no-cbor-metadata or modify the settings of the compilier using these instructions:

// Metadata settings (optional)
"metadata": {
  // The CBOR metadata is appended at the end of the bytecode by default.
  // Setting this to false omits the metadata from the runtime and deploy time code.
  "appendCBOR": true,
  // Use only literal content and not URLs (false by default)
  "useLiteralContent": true,
  // Use the given hash method for the metadata hash that is appended to the bytecode.
  // The metadata hash can be removed from the bytecode via option "none".
  // The other options are "ipfs" and "bzzr1".
  // If the option is omitted, "ipfs" is used by default.
  "bytecodeHash": "ipfs"
},

Full detais can be found here https://docs.soliditylang.org/en/latest/using-the-compiler.html#compiler-input-and-output-json-description%7D