The RAACNft contract allows users to mint NFTs by paying in an ERC20 token. However, the contract lacks a mechanism for the owner to withdraw the accumulated ERC20 tokens. As a result, any ERC20 tokens sent to the contract during the minting process will be permanently locked, rendering them inaccessible to the contract owner.
Functionality of mint:
The mint function allows users to mint an NFT by transferring a specified amount of ERC20 tokens to the contract.
The function calculates the required price for the NFT using raac_hp.tokenToHousePrice(_tokenId).
If the user sends more tokens than required, the excess is refunded.
The ERC20 tokens transferred to the contract are stored in the contract's balance but cannot be withdrawn by the owner.
Impact:
Locked Funds: All ERC20 tokens transferred to the contract during the minting process will be permanently stuck in the contract, as there is no mechanism to withdraw them.
Economic Loss: The contract owner will be unable to access or utilize the accumulated tokens, leading to significant financial loss.
Example Scenario:
A user mints an NFT by transferring 100 ERC20 tokens to the contract.
The contract retains these tokens, but the owner has no way to withdraw them.
Over time, multiple users mint NFTs, and the contract accumulates a large balance of ERC20 tokens that are effectively lost.
Below is an example of how the mint function works and the lack of a withdrawal mechanism:
In this function:
The RAACNft receives ERC20 tokens but does not provide any mechanism for the owner to withdraw them.
The tokens remain in the contract's balance indefinitely.
To address this issue, implement a withdrawal mechanism that allows the contract owner to withdraw the accumulated ERC20 tokens. Below are the recommended solutions:
Add a Withdraw Function:
Implement a function that allows the contract owner to withdraw the ERC20 tokens to a specified address.
Example:
Restrict Access to Owner:
Ensure that only the contract owner can call the withdrawal function by using the onlyOwner modifier.
Example:
Emit an Event for Transparency:
Emit an event when tokens are withdrawn to provide transparency and allow tracking of withdrawals.
Example:
Consider Adding a Fee Mechanism:
If the contract is designed to take a fee from the minting process, ensure that the fee is explicitly tracked and can be withdrawn separately.
By implementing a secure withdrawal function restricted to the contract owner, this issue can be resolved, ensuring that the contract owner can access and utilize the accumulated tokens. This modification is critical for the contract's functionality and economic viability.
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.