Skip to content
Business logic Audit finding Intermediate

Earlier bidders get cut out of future NFT holdings by bidders specifying the same price.

Trust Follow with cccz

Originally disclosed on Code4rena

Submitted by Trust, also found by cccz

In GroupBuy module, users can call contribute to get a piece of the NFT pie. There are two stages in transforming the msg.value to holdings in the NFT.

  1. filling at any price(supply is not yet saturated)
uint256 fillAtAnyPriceQuantity = remainingSupply < _quantity ? remainingSupply : _quantity;
// Checks if quantity amount being filled is greater than 0
if (fillAtAnyPriceQuantity > 0) {
    // Inserts bid into end of queue
    bidPriorityQueues[_poolId].insert(msg.sender, _price, fillAtAnyPriceQuantity);
    // Increments total amount of filled quantities
    filledQuantities[_poolId] += fillAtAnyPriceQuantity;
}
  1. Trim out lower price offers to make room for current higher offer.
// Calculates unfilled quantity amount based on desired quantity and actual filled quantity amount
uint256 unfilledQuantity = _quantity - fillAtAnyPriceQuantity;
// Processes bids in queue to recalculate unfilled quantity amount
unfilledQuantity = processBidsInQueue(_poolId, unfilledQuantity, _price);

The while loop in processBidsInQueue will keep removing existing bids with lower price and create new queue entries for currently processed bid. When it reached a bid with a higher price than msg.sender’s price, it will break:

while (quantity > 0) {
    // Retrieves lowest bid in queue
    Bid storage lowestBid = bidPriorityQueues[_poolId].getMin();
    // Breaks out of while loop if given price is less than than lowest bid price
    if (_price < lowestBid.price) {
        break;
    }

The issue is that when _price == lowestBid.price, we don’t break and current bid will kick out older bid, as can be seen here:

// Decrements given quantity amount from lowest bid quantity
lowestBid.quantity -= quantity;
// Calculates partial contribution of bid by quantity amount and price
uint256 contribution = quantity * lowestBid.price;
// Decrements partial contribution amount of lowest bid from total and user contributions
totalContributions[_poolId] -= contribution;
userContributions[_poolId][lowestBid.owner] -= contribution;
// Increments pending balance of lowest bid owner
pendingBalances[lowestBid.owner] += contribution;
// Inserts new bid with given quantity amount into proper position of queue
bidPriorityQueues[_poolId].insert(msg.sender, _price, quantity);

The described behavior goes against what the docs describe will happen when two equal priced bids collide.

Impact

Earlier bidders get cut out of future NFT holdings by bidders specifying the same price.

Recommended Mitigation Steps

Change the < to <= in the if condition:

if (_price <= lowestBid.price) {
    break;
}

IllIllI (warden) commented:

@HickupHH3 @Trust the final code block in this submission comes from here, which falls under the case where the price is the same and the quantity is different. The readme states If two users place bids at the same price but with different quantities, the queue will pull from the bid with a higher quantity first, and as the submission shows, it’s pulling from the higher quantity first - doesn’t that mean this finding is invalid?

Trust (warden) commented:

I agree the example shown is accidentally the wrong block (if clause) and the misbehavior occurs in the else block:

            } else {
                // Calculates total contribution of bid by quantity amount and price
                uint256 contribution = lowestBid.quantity * lowestBid.price;

                // Decrements full contribution amount of lowest bid from total and user contributions
                totalContributions[_poolId] -= contribution;
                userContributions[_poolId][lowestBid.owner] -= contribution;
                // Increments pending balance of lowest bid owner
                pendingBalances[lowestBid.owner] += contribution;

                // Removes lowest bid in queue
                bidPriorityQueues[_poolId].delMin();
                // Inserts new bid with lowest bid quantity amount into proper position of queue
                bidPriorityQueues[_poolId].insert(msg.sender, _price, lowestBidQuantity);
                // Decrements lowest bid quantity from total quantity amount
                quantity -= lowestBidQuantity;

The issue described still manifests in this block.

stevennevins (Tessera) confirmed and mitigated

https://github.com/fractional-company/modular-fractional/pull/212

Status: Mitigation confirmed by gzeon and Lambda.


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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A medium-severity business logic bug in Tessera - Versus contest. Code4rena made it public on 18 April 2023. Found in the 2022-12-tessera audit contest (finding M-08), also found by 1 other warden.

About Business logic

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 Trust

View all

77 more disclosed reports, best first.

More from Tessera - Versus contest

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.