Pieces Protocol

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

[L-3] Missing Cleanup of `nftToErc20Info `Mapping in `claimNft` Function

Summary

In the claimNft function, after an NFT is successfully claimed, the related entry in the nftToErc20Info mapping is not deleted. This can lead to unnecessary storage usage and potential confusion, as the NFT address will still be present in the mapping even though it has been claimed.

Impact

  • Gas Inefficiency: Unused storage in the mapping consumes unnecessary gas.

  • Potential Misuse: Future function calls could reference outdated data, leading to unintended behavior.

  • Data Redundancy: Retaining stale records may create confusion when querying contract data.

Recommendation

Modify the claimNft function to delete the mapping entry after successful NFT transfer.

Suggested Code Fix

function claimNft(address nftAddress) external {
if (nftAddress == address(0)) {
revert TokenDivider__NftAddressIsZero();
}
ERC20Info storage tokenInfo = nftToErc20Info[nftAddress];
if (balances[msg.sender][tokenInfo.erc20Address] < erc20ToMintedAmount[tokenInfo.erc20Address]) {
revert TokenDivider__NotEnoughErc20Balance();
}
ERC20ToGenerateNftFraccion(tokenInfo.erc20Address).burnFrom(msg.sender, erc20ToMintedAmount[tokenInfo.erc20Address]);
balances[msg.sender][tokenInfo.erc20Address] = 0;
erc20ToMintedAmount[tokenInfo.erc20Address] = 0;
+ delete nftToErc20Info[nftAddress]; // Cleanup after successful claim
emit NftClaimed(nftAddress);
IERC721(nftAddress).safeTransferFrom(address(this), msg.sender, tokenInfo.tokenId);
}

References

Updates

Lead Judging Commences

fishy Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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