When relisting a floor item listing, listingCount is not increased, causing listingCount can be underflowed
The relist function for floor item listings does not increase the listingCount, so when such a listing is cancelled, the count is decremented and can underflow to a huge number. This prevents the collection shutdown execute function from working because it checks that listingCount is zero.
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/574
Found by
araj, g, utsav, zraxx
Summary
https://github.com/sherlock-audit/2024-08-flayer/blob/main/flayer/src/contracts/Listings.sol#L625-L672
The relist function is used to refill the parameters of any token listings, including floor item listing. For a loor item listing, users can change its owner from address(0) to their own address without paying any fees, and set its type to DUTCH or LIQUID. However, this operation does not change listingCount. So, when all the listing is filled, the listingCount will be underflowed to a large num(close to uint256.max) instead of 0. Later, in the function CollectionShutdown.sol#execute, it will be reverted as listings.listingCount(_collection) != 0.
Root Cause
In Listings.sol#relist, when relist for a floor item listing, listingCount is not incresed, causing listingCount can be underflowed.
Internal pre-conditions
- The
_collectionis initialized. - There are floor item listings in the
_collection.
External pre-conditions
No response
Attack Path
- The attacker call
relistfor a floor item listing. - The attacker immediately calls cancelListings to cancel it, in order to refund the tax. At the same time, listingCount is decreased. As a result, the listingCount cannot correctly reflect the number of listings contained in _collection.
Impact
listingCount cannot correctly reflect the number of listings contained in _collection.
CollectionShutdown.sol#execute will be DOSed.
PoC
No response
Mitigation
Avoid relisting floor item listings OR Increase listingCount by one.
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
Impact
The listingCount becomes incorrect and can underflow, causing CollectionShutdown.execute to be DOSed because it requires listingCount to be zero.
What the attacker needed
The collection is initialized; There are floor item listings in the collection
The fix
The fix is to either avoid relisting floor item listings or increase listingCount by one during relist.
How it was found
- The attacker calls relist for a floor item listing.
- The attacker immediately calls cancelListings to cancel it, which decreases listingCount.
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.
A smart contract keeps a count of how many listings exist for a collection. When you relist a special 'floor item' listing, the count is not increased, but when you cancel it, the count is decreased. This makes the count wrap around to a very large number, which stops a shutdown feature from working.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.