9

Why are these 2 smart contracts, which differ only in the comments, result in different bytecode:

1st

pragma solidity 0.4.20;

contract Test {

  // test
  function test() pure public {

  }
}

2nd

pragma solidity 0.4.20;

contract Test {

  // test2
  function test() pure public {

  }
}

1 Answer 1

18

The Solidity compiler appends the metadata file hash at the end of the bytecode http://solidity.readthedocs.io/en/develop/metadata.html

Metadata file is a json file that contains hashes of source files so changing comments changes the metadata file hash.

3
  • 2
    Very interesting! Please mark your own answer as the correct answer :) Commented Mar 3, 2018 at 12:20
  • 2
    It's a time lock imposed to give other people time to answer the question :-) There were also arguments that it prevents the OP from gaming the system, although I'm not really sure how they would given there's no rep involved... Commented Mar 3, 2018 at 14:32
  • Just noticed this today. Great question and great answer!
    – LampShade
    Commented Sep 17, 2019 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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