safeTransferMany() doesn’t actually use safe transfer
The safeTransferMany() function in BondNFT and GovNFT does not perform a safe transfer, so tokens can be sent to a contract that cannot receive ERC721 tokens, potentially locking them permanently. An attacker could exploit this by tricking a user into using the function, causing their NFT to be stuck.
Submitted by 0xA5DF, also found by 0xmuxyz, 8olidity, 0x4non, and HollaDieWaldfee
Both BondNFT and GovNFT are an ERC721 implementation, and they both also have a function named safeTransferMany() which its name implies is supposed to safe transfer many tokens at once. However the function doesn’t actually safe transfer.
Impact
Users might use this function, expecting it to verify that the receiver is an ERC721Receiver, but will get their funds stuck in a contract that doesn’t support ERC721.
Proof of Concept
I’ve added the following tests to the GovNFT tests.
1st test will succeed (tx will revert) since safeTransferFrom() does actually use safe transfer.
2nd will fail (tx won’t revert), since safeTransferMany() doesn’t actually use a safe transfer.
diff --git a/test/05.GovNFT.js b/test/05.GovNFT.js
index 711a649..d927320 100644
--- a/test/05.GovNFT.js
+++ b/test/05.GovNFT.js
@@ -98,6 +98,14 @@ describe("govnft", function () {
expect(await govnft.pending(owner.getAddress(), StableToken.address)).to.equal(1500);
expect(await govnft.pending(user.getAddress(), StableToken.address)).to.equal(500);
});
+
+ it("Safe transfer to non ERC721Receiver", async function () {
+
+ expect(govnft.connect(owner)['safeTransferFrom(address,address,uint256)'](owner.address,StableToken.address, 2)).to.be.revertedWith("ERC721: transfer to non ERC721Receiver implementer");
+ });
+ it("Safe transfer many to non ERC721Receiver", async function () {
+ await expect(govnft.connect(owner).safeTransferMany(StableToken.address, [2])).to.be.revertedWith("ERC721: transfer to non ERC721Receiver implementer");
+ });
it("Transferring an NFT with pending delisted rewards should not affect pending rewards", async function () {
await govnft.connect(owner).safeTransferMany(user.getAddress(), [2,3]);
expect(await govnft.balanceOf(owner.getAddress())).to.equal(0);
Output (I’ve shortened the output. following test will also fail, since the successful transfer will affect them):
✔ Safe transfer to contract
1) Safe transfer many to contract
11 passing (3s)
1 failing
1) govnft
Reward system related functions
Safe transfer many to contract:
AssertionError: Expected transaction to be reverted
+ expected - actual
-Transaction NOT reverted.
+Transaction reverted.
Recommended Mitigation Steps
Call _safeTransfer() instead of _transfer().
TriHaz (Tigris Trade) confirmed
Alex the Entreprenerd (judge) commented:
The Warden has shown a discrepancy between the intent of the code and the actual functionality when it comes to the
safeTransfer...function.Because this finding is reliant on understanding the intention of the Sponsor, and in this case they have confirmed, I believe that the finding is valid and of Medium Severity, because the function was intended to be using the safe checks, but wasn’t.
GainsGoblin (Tigris Trade) resolved:
Mitigation: https://github.com/code-423n4/2022-12-tigris/pull/2#issuecomment-1419175381
We decided that we do not want transfers to check that the receiver is implementing IERC721Receiver, so we renamed the functions.
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
The function uses _transfer() instead of _safeTransfer(), omitting the receiver check.
What the attacker needed
User calls safeTransferMany(); Recipient is a contract without ERC721Receiver
The fix
The project chose not to add the safe transfer check and instead renamed the functions to clarify they are not safe transfers.
How it was found
- Deploy or identify a contract that does not implement ERC721Receiver.
- Call safeTransferMany() on GovNFT or BondNFT with that contract as the recipient.
- Observe that the transaction does not revert, unlike safeTransferFrom().
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.
ERC721 tokens (NFTs) have a 'safe transfer' feature that checks if the receiving contract can handle NFTs; if not, the transfer is blocked to prevent the NFT from being lost forever. Here, a function named safeTransferMany() was supposed to do that check but didn't, so NFTs could be sent to contracts that can't receive them and become stuck.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.