Skip to content

The old optimizer breaks internal function equality #13969

Open
@chatziko

Description

@chatziko

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

Metadata

Metadata

Assignees

Labels

breaking change ⚠️bug 🐛low effortThere is not much implementation work to be done. The task is very easy or tiny.medium impactDefault level of impactmust have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions