NFTBridge
60,000 USDC
View results
Submission Details
Severity: low
Invalid

Gas Optimization Opportunity in `TokenUtil.sol` by Reducing Redundant Static Calls in `supportsInterface`

Summary

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.

Vulnerability Details

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.

Impact

By optimizing the static calls, gas usage can be reduced, leading to significant cost savings - as much as 60k based on the ERC.

Recommendations

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.

Example Implementation:

bool supportsERC165 = ERC165Checker.supportsERC165(token);
if (supportsERC165) {
bool supportsERC721 = ERC165Checker.supportsERC165InterfaceUnchecked(token, type(IERC721).interfaceId);
bool supportsERC1155 = ERC165Checker.supportsERC165InterfaceUnchecked(token, type(IERC1155).interfaceId);
// Further logic...
}

This change will reduce unnecessary gas consumption while maintaining the functionality of the supportsInterface checks.

Updates

Lead Judging Commences

n0kto Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational / Gas

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.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.