argotorg / argotorg/solidity

ABI is different for functions defined in libraries as compared to contracts.

Open
#14,824 0 comments 1 reaction 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description

When compiling a function which takes an interface as an argument, if that function is defined in a contract, the ABI indicates that the `type` of that interface argument is `address` (additional information that it is a contract is stored in the `internalType` field). However, when the same function which takes an interface as an argument is defined in a library, the ABI indicates that the `type` of that interface argument is the name of the interface (and not `address`) -- the `internalType` field remains unchanged.

## Environment

- Compiler version: 0.8.24+commit.e11b9ed9.Darwin.appleclang
- Target EVM version (as per compiler settings): whatever default is (I believe `shanghai`)
- Framework/IDE (e.g. Truffle or Remix): N/A (compilinig command line)
- EVM execution environment / backend / blockchain client: N/A
- Operating system: macOS Monterey (version 12.3)

## Steps to Reproduce

Consider the following contract `Example`:

```solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.10;

import "./Library.sol";

contract Example {
function baz(InterfaceExample i) external pure returns (uint) {
return 0;
}
}
```

along with the following library implementation:

```solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.10;

interface InterfaceExample {}

library Library {
function bar(InterfaceExample i) external pure returns (uint) {
return 0;
}
}
```
When we run `solc Example.sol --combined-json abi` the following is output:

```
{"contracts":{"Example.sol:Example":{"abi":[{"inputs":[{"internalType":"contract InterfaceExample","name":"i","type":"address"}],"name":"baz","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]},"Library.sol:InterfaceExample":{"abi":[]},"Library.sol:Library":{"abi":[{"inputs":[{"internalType":"contract InterfaceExample","name":"i","type":"InterfaceExample"}],"name":"bar","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]}},"version":"0.8.24+commit.e11b9ed9.Darwin.appleclang"}
```

As shown in the above results, the type for the argument of `baz` in the contract is `{"internalType":"contract InterfaceExample","name":"i","type":"address"}` but the argument of `bar` in the library is `{"internalType":"contract InterfaceExample","name":"i","type":"InterfaceExample"}`.

Contributor guide

Open the contributing guide

Research direction

Reproduce the discrepancy with Example.sol and Library.sol using `solc Example.sol --combined-json abi`, then compare the `baz` and `bar` ABI inputs. Trace the compiler's ABI generation for functions in contracts and libraries; done means both interface arguments use the consistent ABI `type` while preserving the existing `internalType`.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.