Pieces Protocol

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

Unnecessary if statement in transferErcTokens

Summary

The transferErcTokens function is used to move ERC20 pieces between users. In the beginning it validates the nftAddress, to and amount arguments passed to the function. It then takes the ERC20Info for the specific NFT token and does the same address(0) check for the to address, which we had few lines of code above. This is unnecessary, since between the last check, nothing could've updated the to address.

Code

function transferErcTokens(address nftAddress, address to, uint256 amount) external {
if (nftAddress == address(0)) {
revert TokenDivider__NftAddressIsZero();
}
if (to == address(0)) {
revert TokenDivider__CantTransferToAddressZero();
}
if (amount == 0) {
revert TokenDivider__AmountCantBeZero();
}
ERC20Info memory tokenInfo = nftToErc20Info[nftAddress];
if (to == address(0)) {
//@audit L duplicated check
revert TokenDivider__CantTransferToAddressZero();
}
if (balances[msg.sender][tokenInfo.erc20Address] < amount) {
revert TokenDivider__NotEnoughErc20Balance();
}
balances[msg.sender][tokenInfo.erc20Address] -= amount;
balances[to][tokenInfo.erc20Address] += amount;
emit TokensTransfered(amount, tokenInfo.erc20Address);
IERC20(tokenInfo.erc20Address).transferFrom(msg.sender, to, amount);
}

Tools Used

Manual review

Recommendations

Remove the second duplicate if check

Updates

Lead Judging Commences

fishy Lead Judge 5 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.