Giter Club home page Giter Club logo

Comments (5)

r0qs avatar r0qs commented on May 25, 2024

Thanks for reporting, @chamitro, but I believe this is not a bug. The string expressions are indeed equivalent; the difference in the bytecode is due to metadata. If you compare the Yul code generated by both, they should be equal.

Please see the following warning in our documentation about contract metadata:

Since the bytecode of the resulting contract contains the metadata hash by default, any change to the metadata
might result in a change of the bytecode. This includes changes to a filename or path, and 
since the metadata includes a hash of all the sources used, a single whitespace change results 
in different metadata, and different bytecode.

For instance, the contracts below will generate different bytecode due to metadata divergence, although f() will produce the same output for both (i.e., ManofDevelopingIndia):

  • a.sol:
contract A {
    string private _name = "ManofDevelopingIndia";
    function f() public view returns (string memory) {
        return _name;
    }
}
  • b.sol
contract A {
    string private _name = "Man" "of" "Developing" "India";
    function f() public view returns (string memory) {
        return _name;
    }
}

You can check the generated Yul by doing

solc --ir a.sol > a.yul
solc --ir b.sol > b.yul
diff a.yul b.yul

You will see that only the metadata hash and some source locations will be different, like:

<         data ".metadata" hex"a2646970667358221220fef6372fd6d9f1584086e88f921cc5f73d7c76d9ff3f0f3913e4fb9b6805dad164736f6c63430008170033"
---
>         data ".metadata" hex"a2646970667358221220ee7e0fb2c94e6b02415895ae48c4229bfae8191cff9bf875a305caccc0d6116664736f6c63430008170033"

from solidity.

chamitro avatar chamitro commented on May 25, 2024

Thank you for the information! My question is that while the change is in the ManOfDevelopingIndia contract's source code, the bytecode of : IERC20, IDexRouter, IDexFactory and Context contracts is not changing, while the bytecode of Utils and SafeMath is changing. I was expecting that there wouldl be changes only in the ManOfDevelopingIndia contract.

from solidity.

max-clinch avatar max-clinch commented on May 25, 2024

Thank you for the information! My question is that while the change is in the ManOfDevelopingIndia contract's source code, the bytecode of : IERC20, IDexRouter, IDexFactory and Context contracts is not changing, while the bytecode of Utils and SafeMath is changing. I was expecting that there wouldl be changes only in the ManOfDevelopingIndia contract.

the behavior you're observing is a result of how Solidity handles metadata and bytecode generation. While the logical functionality of certain contracts remains unchanged, metadata changes can propagate to affect other parts of the bytecode.

from solidity.

chamitro avatar chamitro commented on May 25, 2024

Ok thank you for the informations!

from solidity.

r0qs avatar r0qs commented on May 25, 2024

Thank you for the information! My question is that while the change is in the ManOfDevelopingIndia contract's source code, the bytecode of : IERC20, IDexRouter, IDexFactory and Context contracts is not changing, while the bytecode of Utils and SafeMath is changing. I was expecting that there wouldl be changes only in the ManOfDevelopingIndia contract.

Hi @chamitro, as @max-clinch mentioned, such metadata changes can propagate when compiling multiple contracts together. If you execute the commands below, you should only observe changes in source locations and metadata information. Therefore, I don't believe this is a bug, and I will be closing this issue.

solc --ir standard.sol > 1.yul
solc --ir standard2.sol > 2.yul
diff 1.yul 2.yul

Please feel free to reopen if there are additional points to address. Pinging @cameel in case I misunderstood something and this is indeed a bug ;)

from solidity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.