Pieces Protocol

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

The `erc20ToNft` mapping stores incomplete information about the NFT it is pegged to

Summary

The divideNft function creates an ERC20 token for a selected NFT (nftAddress) and stores its association in the erc20ToNft mapping. However, this mapping only stores the nftAddress, which could represent an entire collection rather than a unique NFT. This results in incomplete and potentially misleading data, as NFTs are uniquely identified by both nftAddress and tokenId.

Vulnerability Details

In the divideNft function, the following line assigns data to the erc20ToNft mapping:

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

erc20ToNft[erc20] = nftAddress;

Here, only the nftAddress is stored, which may not uniquely identify the NFT. For example, in collections with multiple NFTs, this mapping would fail to specify the exact NFT associated with the created ERC20 token. Although this mapping is not currently used elsewhere in the contract, storing incomplete information is incorrect and could lead to confusion or potential issues in future implementations.

Impact

There is no direct functional impact, as the mapping is not used elsewhere in the contract. However, the inaccurate representation of data in the mapping could lead to confusion for developers or auditors, particularly if the mapping is used in future contract updates or extensions.

Tools Used

  • Manual code review

Recommendations

Update the mapping to store complete information about the NFT associated with the created ERC20 token. This can be achieved as follows:

  1. Define a new struct to represent the NFT's full details:

struct DividedNftInfo {
address nftAddress;
uint256 tokenId;
}
  1. Modify the erc20ToNft mapping to use the struct:

- mapping(address erc20 => address nft) erc20ToNft;
+ mapping(address erc20 => address DividedNftInfo) erc20ToNft;
  1. Update the divideNft function to store the complete information:

- erc20ToNft[erc20] = nftAddress;
+ erc20ToNft[erc20] = ERC20Info({nftAddress: nftAddress, tokenId: tokenId});
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.