Pieces Protocol

First Flight #32
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: high
Valid

User Can Transfer Tokens Directly to Contract, Causing Stuck NFTs and DoS

Description

The issue arises when a user intentionally / accidentally transfers their ERC20 tokens directly to the contract address instead of using the designated sellErc20 function. This action can result in those tokens becoming stuck in the contract, leading to a Denial of Service (DoS) scenario where the tokens cannot be retrieved or utilized as intended. Since the contract does not have a mechanism to handle such direct transfers, these tokens remain inaccessible.

This can also be an issue when a user refuses to cooperate and intentionally never releases their tokens to allow the proper functioning of the protocol or has accidentally sent their tokens to an unrecoverable address.

Impact

The NFT associated with the token remains locked in the contract forever

Tools Used

Manual Review

Recommendations

  • To handle the transfers directly to the contract address we can implement a function to handle tokens received by the contract by selling them to buyers for a fixed price (0.1 ether for example)

function buyTokensFromContract(address nft, uint256 tokenId) external payable {
address erc20 = nftToErc20Info[nft][tokenId];
uint256 contractTokenBalance = IERC20(erc20).balanceOf(address(this));
require(msg.value == 1e17 && contractTokenBalance > 0);
IERC20(erc20).transfer(msg.sender, contractTokenBalance);
}
  • To handle mishandled erc20 tokens we can create a privileged onlyOwner function to release a locked NFT to ensure the NFT doesn't remain locked in the contract forever and delete the erc20 token mapped to the NFT

Updates

Lead Judging Commences

fishy Lead Judge 7 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Transfer ERC20ToGenerateNftFraccion separately to the contract

Appeal created

riceee Submitter
7 months ago
fishy Lead Judge 7 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Transfer ERC20ToGenerateNftFraccion separately to the contract

Support

FAQs

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