Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bmarwritescode opened this issue Jan 30, 2024 · 0 comments
Labels

Comments

@bmarwritescode
Copy link

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:

// 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:

// 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"}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant