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

contracts-bedock: remove redundant ierc165 check #5541

Merged
merged 6 commits into from
Apr 26, 2023

Conversation

tynes
Copy link
Contributor

@tynes tynes commented Apr 26, 2023

Description

Building on top of #5521

The supportsInterface function in the OptimismMintableERC721 contract includes redundant codes with type(IERC165).interfaceId.

OptimismMintableERC721.sol#L134-L146

    function supportsInterface(bytes4 _interfaceId)
        public
        view
        override(ERC721Enumerable, IERC165)
        returns (bool)
    {
        bytes4 iface1 = type(IERC165).interfaceId;
        bytes4 iface2 = type(IOptimismMintableERC721).interfaceId;
        return
            _interfaceId == iface1 ||
            _interfaceId == iface2 ||
            super.supportsInterface(_interfaceId);
    }

bytes4 iface1 = type(IERC165).interfaceId; and _interfaceId == iface1 are unnecessary. It's because OptimismMintableERC721 inherits ERC165 and super.supportsInterface(_interfaceId); is being used.

OpenZeppelin ERC721Enumerable.sol#L30-L32

    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
        return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
    }

OpenZeppelin ERC721.sol#L52-L57

    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

OpenZeppelin ERC165.sol#L26-L28

    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }

Therefore, the unnecessary codes can be safely removed without affecting the functionality of the contract.

NOTE: this change costs

  • 0.3% more gas for test_finalizeBridgeERC721_alreadyExists_reverts (29128 -> 29218)
  • 0.04% more gas for test_finalizeBridgeERC721_succeeds (168970 -> 169045)
  • 0.63% less gas for test_createOptimismMintableERC721_succeeds (2336687 -> 2321842)

If this redundant type(IERC165).interfaceId check is intended,
adding comment would be helpful for developers as the code can be more straightforward with comment.

Tests

This PR includes supportsInterface test for the following interfaces:

  • IOptimismMintableERC721
  • IERC721Enumerable
  • IERC721
  • IERC165

@tynes tynes requested a review from a team as a code owner April 26, 2023 15:06
@tynes tynes requested a review from clabby April 26, 2023 15:06
@changeset-bot
Copy link

changeset-bot bot commented Apr 26, 2023

⚠️ No Changeset found

Latest commit: d34abfc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Apr 26, 2023

Deploy Preview for opstack-docs canceled.

Name Link
🔨 Latest commit d34abfc
🔍 Latest deploy log https://app.netlify.com/sites/opstack-docs/deploys/64494069199f7b00089e9df0

@tynes tynes changed the title Refactor/rm redundant ierc165 contracts-bedock: remove redundant ierc165 check Apr 26, 2023
@maurelian maurelian merged commit ef8589a into develop Apr 26, 2023
@maurelian maurelian deleted the refactor/rm-redundant-ierc165 branch April 26, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants