Duplicated error definitions in the ABI
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Description
If the same error is defined in different files within the inheritance/use chain, it ends up twice in the ABI despite having the same selector.
The generated bytecode seems fine as I couldn't find the selector being duplicated in it.
## Environment
- Compiler version: 0.8.20
- Target EVM version (as per compiler settings): London
- Framework/IDE (e.g. Truffle or Remix): Foundry
- EVM execution environment / backend / blockchain client: N/A
- Operating system: MacOS
## Steps to Reproduce
```solidity
pragma solidity 0.8.20;
library A {
error CustomError();
function iCustomError() internal pure {
revert CustomError();
}
}
library B {
error CustomError();
function iCustomError() internal pure {
revert CustomError();
}
}
contract SolidityBug {
function foo() public pure {
A.iCustomError();
}
function bar() public pure {
B.iCustomError();
}
}
```
will generate
```json
"abi": [
{
"inputs": [],
"name": "CustomError",
"type": "error"
},
{
"inputs": [],
"name": "CustomError",
"type": "error"
},
{
"inputs": [],
"name": "bar",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "foo",
"outputs": [],
"stateMutability": "pure",
"type": "function"
}
]
```
I know this seems silly, but the real world example on how this can happen is the following. Here the `AddressEmptyCode` error will be defined in both OZ libs, and it'll end up twice in the ABI. (need to use the latest master from OZ)
```solidity
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract SolidityBug is UUPSUpgradeable
{
function _authorizeUpgrade(address newImplementation) internal override {}
function useSafeERC20(IERC20 token, address to, uint256 amount) external {
SafeERC20.safeTransferFrom(token, msg.sender, to, amount);
}
}
```
Contributor guide
Research direction
Start by reproducing the Solidity 0.8.20 example and tracing ABI generation for error declarations from the two libraries. Identify the compiler entry point and existing ABI tests involved, then add a regression test showing that identical error selectors appear only once in the generated ABI.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100