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.
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;
}
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.
@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?
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.