Pieces Protocol

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

Redundancy in code causes unnecessary double validations and extra gas usage

Description

1) The onlyNftOwner modifier checks if the msg.sender of a transaction is the owner of the NFT tokenId that is to be swapped for erc20 tokens. in TokenDivider::divideNft the modifier is redundant.

The onlyNftOwner modifier will execute twice, checking twice that msg.sender is the owner of the NFT.
If the check passes the first time, it will also pass the second time (unless the NFT ownership changes between the two checks, which is unlikely).
The function will consume more gas than necessary due to the redundant modifier execution.

function divideNft(address nftAddress, uint256 tokenId, uint256 amount) onlyNftOwner(nftAddress, tokenId) onlyNftOwner(nftAddress ,tokenId) external {[...]}

2) The TokenDivider::transferErcTokens function is used to exchange the erc20 tokens between users which were swapped for a NFT . It does some validation checks first before transferring and updating the balances state variable that stores the balance of an users erc20 holdings with respect to the token address.

The null address check validation for the receivers address is repeated twice, which is again unnecessary as it doesn't change the intended code logic being carried out. It just results in an extra redundant check costing up more gas.

if(to == address(0)) {//@audit L reduntant validation
revert TokenDivider__CantTransferToAddressZero();
}

Tools Used

Manual Review

Recommendations

Remove the redundancy

Updates

Lead Judging Commences

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