A user loses funds when he modifies only price of listings
When a user modifies only the price of a listing (leaving duration unchanged), the protocol charges tax for the full listing duration instead of the remaining time, causing the user to pay more tax than normal.
0xHappy Follow with Ironsidesec, Ruhum and 8 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/340
Found by
0xHappy, Ironsidesec, Ruhum, ZeroTrust, blockchain555, dany.armstrong90, dimulski, super_jack, t.aksoy, ydlee, zarkk01
Summary
When user modifies only price of listings, the protocol applies more taxes than normal.
Vulnerability Detail
Listings.sol#modifiyListings() function is as follows.
function modifyListings(address _collection, ModifyListing[] calldata _modifyListings, bool _payTaxWithEscrow) public nonReentrant lockerNotPaused returns (uint taxRequired_, uint refund_) {
uint fees;
for (uint i; i < _modifyListings.length; ++i) {
// Store the listing
ModifyListing memory params = _modifyListings[i];
Listing storage listing = _listings[_collection][params.tokenId];
// We can only modify liquid listings
if (getListingType(listing) != Enums.ListingType.LIQUID) revert InvalidListingType();
// Ensure the caller is the owner of the listing
if (listing.owner != msg.sender) revert CallerIsNotOwner(listing.owner);
// Check if we have no changes, as we can continue our loop early
if (params.duration == 0 && params.floorMultiple == listing.floorMultiple) {
continue;
}
// Collect tax on the existing listing
323 (uint _fees, uint _refund) = _resolveListingTax(listing, _collection, false);
emit ListingFeeCaptured(_collection, params.tokenId, _fees);
fees += _fees;
refund_ += _refund;
// Check if we are altering the duration of the listing
330 if (params.duration != 0) {
// Ensure that the requested duration falls within our listing range
if (params.duration < MIN_LIQUID_DURATION) revert ListingDurationBelowMin(params.duration, MIN_LIQUID_DURATION);
if (params.duration > MAX_LIQUID_DURATION) revert ListingDurationExceedsMax(params.duration, MAX_LIQUID_DURATION);
emit ListingExtended(_collection, params.tokenId, listing.duration, params.duration);
listing.created = uint40(block.timestamp);
listing.duration = params.duration;
}
// Check if the floor multiple price has been updated
342 if (params.floorMultiple != listing.floorMultiple) {
// If we are creating a listing, and not performing an instant liquidation (which
// would be done via `deposit`), then we need to ensure that the `floorMultiple` is
// greater than 1.
if (params.floorMultiple <= MIN_FLOOR_MULTIPLE) revert FloorMultipleMustBeAbove100(params.floorMultiple);
if (params.floorMultiple > MAX_FLOOR_MULTIPLE) revert FloorMultipleExceedsMax(params.floorMultiple, MAX_FLOOR_MULTIPLE);
emit ListingFloorMultipleUpdated(_collection, params.tokenId, listing.floorMultiple, params.floorMultiple);
listing.floorMultiple = params.floorMultiple;
}
// Get the amount of tax required for the newly extended listing
355 taxRequired_ += getListingTaxRequired(listing, _collection);
}
// cache
ICollectionToken collectionToken = locker.collectionToken(_collection);
// If our tax refund does not cover the full amount of tax required, then we will need to make an
// additional tax payment.
if (taxRequired_ > refund_) {
unchecked {
payTaxWithEscrow(address(collectionToken), taxRequired_ - refund_, _payTaxWithEscrow);
}
refund_ = 0;
} else {
unchecked {
refund_ -= taxRequired_;
}
}
// Check if we have fees to be paid from the listings
if (fees != 0) {
collectionToken.approve(address(locker.implementation()), fees);
locker.implementation().depositFees(_collection, 0, fees);
}
// If there is tax to refund after paying the new tax, then allocate it to the user via escrow
if (refund_ != 0) {
_deposit(msg.sender, address(collectionToken), refund_);
}
}
It calculates refund amount on L323 through _resolveListingTax().
function _resolveListingTax(Listing memory _listing, address _collection, bool _action) private returns (uint fees_, uint refund_) {
// If we have been passed a Floor item as the listing, then no tax should be handled
if (_listing.owner == address(0)) {
return (fees_, refund_);
}
// Get the amount of tax in total that will have been paid for this listing
uint taxPaid = getListingTaxRequired(_listing, _collection);
if (taxPaid == 0) {
return (fees_, refund_);
}
// Get the amount of tax to be refunded. If the listing has already ended
// then no refund will be offered.
if (block.timestamp < _listing.created + _listing.duration) {
933 refund_ = (_listing.duration - (block.timestamp - _listing.created)) * taxPaid / _listing.duration;
}
...
}
As we can see on L933, refund amount is calculated according to remained time.
If a user modifies with params.duration == 0, listing.created is not updated.
But on L355, the protocol applies full tax for whole duration.
This is wrong.
Impact
The protocol applies more tax than normal.
Code Snippet
Tool used
Manual Review
Recommendation
Listings.sol#modifiyListings() function has to be modified as follows.
function modifyListings(address _collection, ModifyListing[] calldata _modifyListings, bool _payTaxWithEscrow) public nonReentrant lockerNotPaused returns (uint taxRequired_, uint refund_) {
uint fees;
for (uint i; i < _modifyListings.length; ++i) {
// Store the listing
ModifyListing memory params = _modifyListings[i];
Listing storage listing = _listings[_collection][params.tokenId];
...
// Check if we are altering the duration of the listing
if (params.duration != 0) {
// Ensure that the requested duration falls within our listing range
if (params.duration < MIN_LIQUID_DURATION) revert ListingDurationBelowMin(params.duration, MIN_LIQUID_DURATION);
if (params.duration > MAX_LIQUID_DURATION) revert ListingDurationExceedsMax(params.duration, MAX_LIQUID_DURATION);
emit ListingExtended(_collection, params.tokenId, listing.duration, params.duration);
- listing.created = uint40(block.timestamp);
listing.duration = params.duration;
}
+ listing.created = uint40(block.timestamp);
// Check if the floor multiple price has been updated
if (params.floorMultiple != listing.floorMultiple) {
// If we are creating a listing, and not performing an instant liquidation (which
// would be done via `deposit`), then we need to ensure that the `floorMultiple` is
// greater than 1.
if (params.floorMultiple <= MIN_FLOOR_MULTIPLE) revert FloorMultipleMustBeAbove100(params.floorMultiple);
if (params.floorMultiple > MAX_FLOOR_MULTIPLE) revert FloorMultipleExceedsMax(params.floorMultiple, MAX_FLOOR_MULTIPLE);
emit ListingFloorMultipleUpdated(_collection, params.tokenId, listing.floorMultiple, params.floorMultiple);
listing.floorMultiple = params.floorMultiple;
}
// Get the amount of tax required for the newly extended listing
taxRequired_ += getListingTaxRequired(listing, _collection);
}
...
}
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 code updates the listing's creation timestamp only when the duration is changed, but always calculates tax for the full duration when only the price is modified.
Impact
The protocol applies more tax than normal, causing users to lose funds.
What the attacker needed
User has a liquid listing; user modifies only the price
The fix
The fix should update the listing's creation timestamp whenever any modification occurs, not only when duration changes.
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.
This is a smart contract bug in a listing system. When someone changes the price of an item they have listed, the code mistakenly charges tax for the whole listing period again, rather than just the time left. So the user loses extra money in tax.
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.