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 {

  }
}
13

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.

| improve this answer | |
  • 2
    Very interesting! Please mark your own answer as the correct answer :) – Mikko Ohtamaa Mar 3 '18 at 12:20
  • @MikkoOhtamaa I tried but it says I can accept my own answer in 2 days. Don’t know the reason. – medvedev1088 Mar 3 '18 at 12:24
  • 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... – Richard Horrocks Mar 3 '18 at 14:32
  • Just noticed this today. Great question and great answer! – LampShade Sep 17 '19 at 15:08

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.