1

I'm compiling the following contract locally and on Remix and getting two different bytecode results.

Contract

pragma solidity ^0.4.25;

contract ReadBool {
    bool public flag;

    function read_bool() public constant returns (bool) {
        return flag;
    }
}

Locally

> solc --bin contracts/ReadBool.sol

======= contracts/ReadBool.sol:ReadBool =======
Binary:
608060405234801561001057600080fd5b5060fa8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632be22bbe14604e578063890eba6814607a575b600080fd5b348015605957600080fd5b50606060a6565b604051808215151515815260200191505060405180910390f35b348015608557600080fd5b50608c60bc565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900460ff16905090565b6000809054906101000a900460ff16815600a165627a7a723058201487d36b2d6b54937c8607b8e11137d95c71eea7bb91a53ab2e728dc2588a8ae0029

Remix

{
    "linkReferences": {},
    "object": "608060405234801561001057600080fd5b5060c38061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632be22bbe8114604d578063890eba68146073575b600080fd5b348015605857600080fd5b50605f6085565b604080519115158252519081900360200190f35b348015607e57600080fd5b50605f608e565b60005460ff1690565b60005460ff16815600a165627a7a7230582013c77650d8162dee4cfb9b7e0a0c09f6e030f3663d8d767d59a26863dcb40a840029",
    "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0xC3 DUP1 PUSH2 0x1F PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH1 0x48 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0x2BE22BBE DUP2 EQ PUSH1 0x4D JUMPI DUP1 PUSH4 0x890EBA68 EQ PUSH1 0x73 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH1 0x58 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x5F PUSH1 0x85 JUMP JUMPDEST PUSH1 0x40 DUP1 MLOAD SWAP2 ISZERO ISZERO DUP3 MSTORE MLOAD SWAP1 DUP2 SWAP1 SUB PUSH1 0x20 ADD SWAP1 RETURN JUMPDEST CALLVALUE DUP1 ISZERO PUSH1 0x7E JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x5F PUSH1 0x8E JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH1 0xFF AND SWAP1 JUMP JUMPDEST PUSH1 0x0 SLOAD PUSH1 0xFF AND DUP2 JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 SGT 0xc7 PUSH23 0x50D8162DEE4CFB9B7E0A0C09F6E030F3663D8D767D59A2 PUSH9 0x63DCB40A8400290000 ",
    "sourceMap": "26:133:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;26:133:0;;;;;;;"
}

You can notice the respective bytecodes differ significantly at the end.

Do you know what might be going on here?

More details

I have installed the Solidity compiler locally via

brew install solidity.

The version is:

> solc --version
solc, the solidity compiler commandline interface
Version: 0.4.25+commit.59dbf8f1.Darwin.appleclang

While on Remix, the version is apparently the same:

 0.4.25+commit.59dbf8f1
1

Remix compiles with optimization by default, while solc doesn't optimize by default, as well as there are different settings for optimization in solc

optimizer: {
  // disabled by default
  enabled: true,
  // Optimize for how many times you intend to run the code.
  // Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage.
  runs: 200
}

That is why bytecode can be different

UPDATED:

Equivalent commands are:

  1. Remix with enabled optimization
  2. solc --bin contract.sol --optimize --optimize-runs 200

There is one difference in result of execution of those two commands, Metadata Hash.

Metadata Hash is sensitive hash, even name of solidity file is matter. https://solidity.readthedocs.io/en/v0.4.21/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode

| improve this answer | |
  • Thanks a lot Aquila, unfortunately, I'm still not able to replicate the output from Remix by running the following command: solc --bin contracts/ReadBool.sol --optimize --optimize-runs 200. – Peteris Oct 16 '18 at 12:45
  • @Peteris one difference is metadata hash, I put more details about it in answer – Aquila Oct 16 '18 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.