Description
Description
We (@chatziko, @MichaelXanth) ran into an optimizer issue that can be reproduced in the following minimal contract:
pragma solidity ^0.8.18;
contract Test {
function v1() public {}
function v2() public {}
function equalityTest() external returns(bool) {
return v1 == v2;
}
}
equalityTest()
returnsfalse
when the optimizer is disabled. However, with the old optimizer enabled, the equivalent functions v1
and v2
are merged into one, causing v1 == v2
to be true
. I am not sure whether there is a clear specification of function type comparison, but the two functions have distinct selectors so it makes sense to consider them as non-equal. In any case, the optimizer should not alter the contract's semantics.
This behaviour does not appear in the Yul optimizer.
Environment
- Compiler version: 0.8.18
- Also with the unreleased 0.8.19
- Target EVM version (as per compiler settings): istanbul
- Framework/IDE (e.g. Truffle or Remix): hardhat
Steps to Reproduce
Compile the above contract with and without the optimizer.
The produced bytecode can be compared below:
https://library.dedaub.com/decompile
Non-Optimized MD5: e1a4db0287ad6624f24ab4adbc61475b
Optimized MD5: 531e2a5364fdbc3e00c9733a4372d948