In the current implementation of the divideNft function, the ERC20 contract is created and tokens are minted before verifying whether the NFT transfer to the contract succeeds. This order of operations creates an issue because if the NFT transfer fails, the transaction reverts, undoing state changes in the main contract, but the creation of the ERC20 contract cannot be undone.
The current code creates and mints the ERC20 contract before transferring the NFT:
If the NFT transfer fails, the revert statement undoes the state changes in the divideNft function, but the ERC20 contract remains deployed on the blockchain, leading to potential unintended consequences:
Wasted gas for the user.
Accumulation of unused or orphaned ERC20 contracts.
Increased difficulty in managing or cleaning up the blockchain state.
This issue can lead to inefficiencies, confusion for users, and potential vulnerabilities stemming from unintended ERC20 contract deployments.
Manual code review.
To prevent this issue, reorder the function so the NFT transfer is completed and verified before creating the ERC20 contract:
This approach ensures that the ERC20 contract is only created if the NFT transfer succeeds, preventing unnecessary gas expenditure and the creation of orphaned ERC20 contracts.
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.