Skip to content
Smart contracts Audit finding Beginner

SupportsInterface does not return typeIERCRecei

The governor contract's supportsInterface function does not report support for the ERC721 receiver interface even though the contract implements it. A caller relying on that check would be told the contract cannot receive ERC721 tokens, contrary to its actual behaviour.

OxRizwan Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

31460 - [SC - Insight] supportsInterface does not return typeIERCRecei...

Submitted on May 19th 2024 at 21:40:50 UTC by @OxRizwan for Boost | Alchemix

Report ID: #31460

Report type: Smart Contract

Report severity: Insight

Target: https://immunefi.com

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Brief/Intro

supportsInterface() does not return type(IERC721Receiver).interfaceId

Vulnerability Details

AlchemixGovernor.sol contract has inherited L2Governor abstract as base contract. This base contract has supportsInterface() function which returns the supported interface id by Alchemix Governor contract. It should be noted that Alchemix governor contract supports both IERC721Receiver interface id and IERC1155Receiver interface id, however, the implementation of supportsInterface has only returned IERC1155Receiver and does not return the IERC721Receiver interface id and this can be seen as below:

Solidity
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
        // In addition to the current interfaceId, also support previous version of the interfaceId that did not
        // include the castVoteWithReasonAndParams() function as standard
        return
            interfaceId ==
            (type(IGovernor).interfaceId ^
                this.castVoteWithReasonAndParams.selector ^
                this.castVoteWithReasonAndParamsBySig.selector ^
                this.getVotesWithParams.selector) ||
            interfaceId == type(IGovernor).interfaceId ||
            interfaceId == type(IERC1155Receiver).interfaceId ||
            super.supportsInterface(interfaceId);
    }

Impact Details

supportsInterface() does not explicitely return the interfaceId == type(IERC721Receiver).interfaceId while calling it. The Alchemix governor supports the ERC721Receiver but the interface id does not return it so its a low severity issue

References

https://github.com/alchemix-finance/alchemix-v2-dao/blob/f1007439ad3a32e412468c4c42f62f676822dc1f/src/governance/L2Governor.sol#L130-L142

Recommendation to fix

Diff
    function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
        // In addition to the current interfaceId, also support previous version of the interfaceId that did not
        // include the castVoteWithReasonAndParams() function as standard
        return
            interfaceId ==
            (type(IGovernor).interfaceId ^
                this.castVoteWithReasonAndParams.selector ^
                this.castVoteWithReasonAndParamsBySig.selector ^
                this.getVotesWithParams.selector) ||
            interfaceId == type(IGovernor).interfaceId ||
+          interfaceId == type(IERC721Receiver).interfaceId ||
            interfaceId == type(IERC1155Receiver).interfaceId ||
            super.supportsInterface(interfaceId);
    }

Proof of Concept

The issue is simple to understand and very straight forward. It explains the interfaceId function unable to return the promised return i.e interfaceId == type(IERC721Receiver).interfaceId as true.

The issue is not complex so i believe it can be easily understood with above description and recommendation.

Thank you for your understanding.

The original report as published on Immunefi, by OxRizwan. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The supportsInterface override lists the ERC1155 receiver interface but omits the ERC721 receiver interface id from its return expression.

Impact

The contract fails to deliver a promised return value, which is a low severity correctness issue rather than a loss of funds.

What the attacker needed

None

The fix

The supportsInterface function should be fixed to also return true for the ERC721 receiver interface id.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Smart contracts can advertise which interfaces they support so other contracts can check before interacting. This governor contract can receive certain tokens but its advertisement leaves out one of the token standards, so a caller checking first would wrongly think it cannot. Nothing is stolen; the contract just gives a misleading answer.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by OxRizwan

View all

5 more disclosed reports, best first.

More from Alchemix

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.