The supportsInterface
function in TokenUtil.sol
uses OpenZeppelin's ERC165Checker
library, which performs three static calls each time it is used. This can be optimized by reducing the number of static calls from six to four when checking both ERC721 and ERC1155 support.
Currently, the supportsInterface
function performs three static calls each time it's invoked: two to verify ERC165 support and one to check the specific interface. When this function is called twice (for ERC721 and ERC1155), a total of six static calls are made. This redundancy can be optimized by first checking for ERC165 support and then using supportsERC165InterfaceUnchecked
for each interface.
By optimizing the static calls, gas usage can be reduced, leading to significant cost savings - as much as 60k based on the ERC.
Refactor the code to first check if the contract supports ERC165 using supportsERC165
. Once verified, use supportsERC165InterfaceUnchecked
to check for ERC721 and ERC1155 support. This reduces the total number of static calls from six to four, improving gas efficiency.
This change will reduce unnecessary gas consumption while maintaining the functionality of the supportsInterface
checks.
Please, do not suppose impacts, think about the real impact of the bug and check the CodeHawks documentation to confirm: https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity A PoC always helps to understand the real impact possible.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.