argotorg / argotorg/solidity

The old optimizer breaks internal function equality

Open
#13,969 8 comments 4 reactions 1 assignee Claimed by @nikola-matic View on GitHub
breaking change :warning: bug :bug: low effort medium impact must have eventually
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description

We (@chatziko, @MichaelXanth) ran into an optimizer issue that can be reproduced in the following minimal contract:
```solidity
pragma solidity ^0.8.18;

contract Test {
function v1() public {}
function v2() public {}

function equalityTest() external returns(bool) {
return v1 == v2;
}
}
```

`equalityTest()` returns`false` 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.