TokenDivider::divideNft
Overwrites previous NFT Division data due to missing pre-check.
In TokenDivider::divideNft
, there is no verification to ensure that the NFT provided as a parameter has not been previously "divided" within the protocol.
The mapping TokenDivider::nftToErc20Info
associates an NFT with a single set of information (ERC20 address and tokenId). If TokenDivider::divideNft
is called repeatedly for the same NFT, the existing information will be overwritten. This would result in the loss of reference to previously created ERC20 contracts, making it difficult or impossible to correctly claim the NFT or manage fractions associated with those older contracts.
Data related to previously linked ERC20 contracts to the NFT would be overwritten. Users would lose the ability to claim NFTs and manage their fractions.
Two different users own NFTs from the same ERC721 contract, but with different IDs.
User 1 calls the function TokenDivider::divideNft
with their NFT of ID 0. The TokenDivider contract transfers this NFT to itself, creates a new fractional ERC20 token to represent it, and stores the information of this NFT–ERC20 pair in the internal mapping TokenDivider::nftToErc20Info
.
At this point, the mapping associates User 1's NFT with a specific ERC20 contract, recording details such as the address of the created ERC20 contract and the original tokenId.
Later, User 2 calls TokenDivider::divideNft
with their NFT of ID 1. Since the contract does not check if another NFT from the same ERC721 contract has already been divided, the TokenDivider
repeats the process: it transfers the NFT of ID 1, generates a new ERC20 token, and overwrites the existing entry in TokenDivider::nftToErc20Info
.
As a result of this overwrite, the information previously stored for User 1's NFT (ID 0) is replaced by the data related to User 2's NFT (ID 1).
This overwrite leads to data loss and potential inconsistencies in the management of fractional tokens.
Place the following into TokenDividerTest.t.sol
Foundry for testing and verification
Manual code review
In TokenDivider::divideNft
, introduce a check to see if the NFT has already been divided. For example, create a new bool field in the TokenDivider::ERC20Info struct
. Then, in the TokenDivider::divideNft
function, check if nftToErc20Info[nftAddress].isDidivided
is true
. If so, revert the transaction to prevent overwriting existing data.
It is also recommended that in the TokenDivider::claimNft
, when modifying state values, set the TokenDivider::tokenInfo.isDivided
to false
. This should allow the NFT to be divided again immediately after the claim is completed.
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.