Comments (5)
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.
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.
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.
Ok thank you for the informations!
from solidity.
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)
- Incorrect `parameterSlots` and `returnSlots` for some methods in `functionDebugData`
- Stack too deep errors with via-IR for some compilation routines
- Enable function overloading resolution when importing specific libraries or free functions via `using for` HOT 1
- `StackCompressor` goes into infinite loop after `SSATransform` on inline assembly with very long chains of dependent assignments HOT 2
- Add blobhash inside the `tx` context: blobhash(uint index) --> tx.blobhash(uint index) HOT 4
- SMTChecker: Use SMT-LIB interface instead of solvers' APIs
- Lack of proper heuristics in the Function Specializer can lead to large contract sizes HOT 5
- build solidity error HOT 3
- When compiling with the `via-ir` option, calldata out-of-bounds causes the transaction to revert HOT 1
- Support for Compiling Solidity to LLVM IR to Facilitate zkVM Adoption?
- Switch default EVM version to Cancun
- Performance issues of `solc --abi --via-ir` HOT 6
- Verifying blobhash causes failure to obtain gasLimit HOT 2
- Security vulnerability: Why do % and MOD result in different outputs despite being technically the same function? HOT 2
- SMT logic error for a conditional with empty tuple types
- Code Deduplication Creates Wrong Source Mappings
- `memory-safe` Assembly Worsens Optimizations HOT 2
- Reduce default font weight for readability HOT 2
- Providing an empty string to `--yul-optimizations` without enabling yul optimization triggers uncaught exception HOT 1
- Version the `list.json` file for build information
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solidity.