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.
- 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:
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
Recommendation to fix
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.
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.