[Tomo-M3] Use safeMint instead of mint for ERC721
The staking contract uses `_mint` instead of `_safeMint` when minting a proof-of-staking NFT to `msg.sender`. If `msg.sender` is a contract that cannot handle ERC721 tokens, the NFT could become stuck in that contract.
Source: https://github.com/sherlock-audit/2022-11-frankendao-judging/issues/65
Found by
Tomo
Summary
Use safeMint instead of mint for ERC721
Vulnerability Detail
The msg.sender will be minted as a proof of staking NFT when _stakeToken() is called.
However, if msg.sender is a contract address that does not support ERC721, the NFT can be frozen in the contract.
As per the documentation of EIP-721:
A wallet/broker/auction application MUST implement the wallet interface if it will accept safe transfers.
Ref: https://eips.ethereum.org/EIPS/eip-721
As per the documentation of ERC721.sol by Openzeppelin
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
Impact
Users possibly lose their NFTs
Code Snippet
https://github.com/sherlock-audit/2022-11-frankendao/blob/main/src/Staking.sol#L411
_mint(msg.sender, _tokenId);
Tool used
Manual Review
Recommendation
Use safeMint instead of mint to check received address support for ERC721 implementation.
Discussion
zobront
I might consider this a duplicate of #55 but not sure how this is usually judged. We will be changing this function based on other issues to not allow "approved" spenders, so msg.sender will be the owner of the FrankenPunk, which ensures they are able to hold NFTs.
zobront
Fixed: https://github.com/Solidity-Guild/FrankenDAO/pull/14
I didn't need to add safeMint, as I made a change for another issue that removed the ability to non holder to unstake, which means they have the ability to hold NFTs.
jack-the-pug
Fix confirmed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the contract used `_mint` instead of `_safeMint`, so it did not verify that the receiving address could handle ERC721 tokens.
Impact
Users could possibly lose their NFTs if the receiving contract cannot handle ERC721 tokens.
What the attacker needed
Msg.sender is a contract; contract does not support ERC721
The fix
The issue was fixed by changing the unstaking logic so that only the NFT owner can unstake, ensuring the receiver can hold NFTs, rather than by adding `safeMint`.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a contract creates a new NFT, it can use a basic mint function that does not check whether the receiver can handle NFTs. If the receiver is a smart contract that lacks the required interface, the NFT may be locked forever. Using a safe mint function asks the receiver if it can accept the NFT before completing the transfer.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.