Description:
The tokenDivider contract uses a mapping to store the ERC20 contract address for each
NFT contract. but with only the ERC721 contract address as key
If multiple NFTs from the same ERC721 contract are divided, the last NFT divided will override the previous ones,
Unfortunately, the claimNft
function uses the nftToErc20Info[nftAddress]
to retrieve the ERC20 contract address for the NFT
if a buyer bought all the fraction tokens of the first NFT, then nftToErc20Info[nftAddress]
got override by the second NFT,
the buyer will not be able to claim the NFT
Impact:
If override happens it can break claimNft
logic, also it is impossible to track the ERC20 fraction contract address for the previous NFTs.
Proof of Concept:
add the following in test/unit/TokenDividerTest.t.sol
and run the test forge test --mt testBreakClaimNft
, tokenDivider.getErc20InfoFromNft(address(erc721Mock)).erc20Address will be different after dividing the second NFT.
Recommended Mitigation:
change mapping(address nft => ERC20Info) nftToErc20Info
to mapping(address nft -> mapping(uint256 tokenId => address)) nftToErc20Info
to store the ERC20 contract address for each NFT tokenId.
User need to provide both NFT contract address and tokenId to get the ERC20 contract address.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.