Pieces Protocol

First Flight #32
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

There is a Redundant Zero Address Check in the `TokenDivider::transferErcTokens` Function

Summary

The transferErcTokens function contains a redundant check for the zero address (to == address(0)). This unnecessary validation not only adds unnecessary computation but also results in slightly increased gas consumption.

Vulnerability Details

The redundant check appears at line 195-197 (second instance):

https://github.com/Cyfrin/2025-01-pieces-protocol/blob/4ef5e96fced27334f2a62e388a8a377f97a7f8cb/src/TokenDivider.sol#L195-L197

if (to == address(0)) {
revert TokenDivider__CantTransferToAddressZero();
}

The to == address(0) condition is already validated earlier in the function in line 185-187:

https://github.com/Cyfrin/2025-01-pieces-protocol/blob/4ef5e96fced27334f2a62e388a8a377f97a7f8cb/src/TokenDivider.sol#L185-L187

if (to == address(0)) {
revert TokenDivider__CantTransferToAddressZero();
}

Impact

While the redundancy does not introduce functional errors, it negatively impacts the gas as it slightly increases the cost during computation. Again, redundant code in smart contracts should NEVER be tolerated.

Tools Used

  • Manual Code Review

Recommendations

Remove the redundant to == address(0) check. The revised function should look as follows:

function transferErcTokens(address nftAddress, address to, uint256 amount) external {
if (nftAddress == address(0)) {
revert TokenDivider__NftAddressIsZero();
}
if (to == address(0)) {
revert TokenDivider__CantTransferToAddressZero(); // Single check is sufficient here.
}
if (amount == 0) {
revert TokenDivider__AmountCantBeZero();
}
ERC20Info memory tokenInfo = nftToErc20Info[nftAddress];
// rest of the code ...
}
Updates

Lead Judging Commences

fishy Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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