Sellers may lose NFTs when orders are matched with matchOrders()
The order-matching function checked the buyer's constraint against the seller's constraint instead of checking the number of items actually being matched against the seller's maximum. An attacker could therefore match a seller's order with more NFTs than the seller had authorised, causing the seller to sell extra NFTs.
Submitted by KIntern, also found by csanuragjain, GimelSec, kenzo, and unforgiven
Function matchOrders uses custom constraints to make the matching more flexible, allow seller/buyer to specify maximum/minimum number of NFTs they want to sell/buy. This function first does some checks and then execute matching.
But in function areNumItemsValid(), there is a wrong checking will lead to wrong logic in matchOrders() function.
Instead of checking if numConstructedItems <= sell.constraints[0] or not, function areNumItemsValid() check if buy.constraints[0] <= sell.constraints[0]. It will lead to the scenario that numConstructedItems > sell.constraints[0] and make the seller sell more number of nfts than he/she allow.
Proof of Concept
Consider the scenario
- Alice create a sell order to sell maximum 2 in her 3 BAYC with ids
[1, 2, 3] - Bob create a buy order to buy mimimum any 2 BAYC with id in list
[1, 2, 3] - Match executor call
matchOrders()to match Alice’s order and Bob’s one with parameterconstructs = [1, 2, 3] - Function
matchOrderswill transfer all NFT inconstructlist (3 NFTs1, 2, 3) from seller to buyer even though seller only want to sell maximum 2 NFTs.
For more information, please check this PoC. https://gist.github.com/minhquanym/a95c8652de8431c5d1d24aa4076a1878
Tools Used
Hardhat, Chai
Recommended Mitigation Steps
Replace check buy.constraints[0] <= sell.constraints[0] with numConstructedItems <= sell.constraints[0]
nneverlander (Infinity) confirmed
HardlyDifficult (judge) commented:
Seller’s may specify a max number of NFTs to sell, but in the scenario outlined by the warden that requirement is not enforced - leading to the sale of more NFTs than authorized.
Accepting this as a High risk report.
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
The validation function compared the buyer's constraint to the seller's constraint rather than comparing the number of constructed items to the seller's constraint.
Impact
A seller could be forced to sell more NFTs than they authorised, losing NFTs they did not intend to part with.
What the attacker needed
A seller order with a maximum item constraint; a matching buy order; ability to call matchOrders
The fix
The check should compare the number of constructed items against the seller's constraint instead of comparing the buyer's constraint to the seller's constraint.
How it was found
- Alice creates a sell order for a maximum of two NFTs from a set of three.
- Bob creates a buy order for a minimum of two NFTs from the same set.
- The match executor calls matchOrders with all three NFTs in the constructs list.
- All three NFTs are transferred from Alice to Bob despite Alice's maximum of two.
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 seller can set a limit on how many of their NFTs they are willing to sell in one order. The matching code was supposed to check that the number of NFTs being matched did not exceed that limit, but it compared the wrong numbers instead. As a result, someone could match the order in a way that sells more NFTs than the seller agreed to.
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.