argotorg / argotorg/solidity

Unreachable code warning for internal function called by an abstract contract

Open
#15,426 2 comments 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

During compilation of a UUPSUpgradeable contract we receive the following 'Unreachable code' warning:
```
--> @openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:94:9:
|
94 | _upgradeToAndCallUUPS(newImplementation, data);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The unreachable function is a private function that is called within an abstract contract so it doesn't apply to the bug where a pure internal function is called by an abstract contract.

## Environment

- Compiler version: 0.8.20
- Target EVM version (as per compiler settings): paris
- Framework/IDE (e.g. Truffle or Remix):
- Operating system: MacOS

## Steps to Reproduce

Create a simple upgradable contract that is `UUPSUpgradeable` and try to compile it.
Use the following version of Openzeppelin packages
```
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0",
```
```solidity
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;

import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

error DisabledFunction();

contract test is UUPSUpgradeable, Ownable2StepUpgradeable {
//// @notice Upgrades the contract to a new implementation.
function _authorizeUpgrade(address) internal view override onlyOwner {
revert DisabledFunction();
}
}
```
The following warning should be produced

Screenshot 2024-09-11 at 09 33 08

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided UUPSUpgradeable example with Solidity 0.8.20 and confirm the unreachable-code warning at @openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol:94. Trace how the compiler analyzes the private function called from the abstract contract. Done means this valid pattern no longer produces the warning, with relevant compiler coverage updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
blockchain, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.