buy() in LPDA.sol Can be Manipulated by Buyers
A buyer could front-run other buyers' transactions to buy the last NFTs one at a time, causing their transactions to revert and preventing them from completing their purchases. This allowed the attacker to secure a larger share of the NFTs while also reducing the seller's revenue.
RaymondFam Follow with Josiah
Originally disclosed on Code4rena
Submitted by RaymondFam, also found by Josiah
A buyer could plan on buying early at higher prices to make sure he would secure a portion (say 50%) of NFTs he desired. When the number of NFTs still available got smaller and that sale.endTime were yet to hit, he would then watch the mempool and repeatedly attempt to thwart the final group of buyers from successfully completing their respective transactions amidst the efforts to prolong the Dutch auction till sale.endTime was reached.
Proof of Concept
Assuming this particular edition pertained to a 100 NFT collection that would at most last for 60 minutes, and Bob planned on minting 10 of them. At the beginning of the Dutch auction, he would first mint 5 NFTs at higher prices no doubt. At 50th minute, sale.currentId == 95. Alice, upon seeing this, made up her mind and proceeded to buy the remaining NFTs. Bob, seeing this transaction queuing in the mempool, invoked buy() to mint 1 NFT by sending in higher amount of gas to front run Alice. Needless to say, Alice’s transaction was going to revert on line 68 because newId == 101:
68: require(newId <= temp.finalId, "TOO MANY");
Noticing the number of NFTs still available had become 4, Alice attempted to mint the remaining 4 NFTs this time. Bob, upon seeing the similar queue in the mempool again, front ran Alice with another mint of 1 NFT.
These steps were repeatedly carried out until Bob managed to get all NFTs he wanted where the last one was minted right after sale.endTime hit. At this point, every successful buyer was happy to get the biggest refund possible ensuring that each NFT was only paid for the lowest price. This intended goal, on the contrary, was achieved at the expense of the seller getting the lowest amount of revenue and that the front run buyers minting nothing.
Recommended Mitigation Steps
Consider refactoring the affected code line as follows:
- require(newId <= temp.finalId, "TOO MANY");
+ if(newId > temp.finalId) {
+ uint256 diff = newId - temp.finalId;
+ newId = temp.finalId;
+ amountSold -= diff;
+ amount -= diff;
+ }
stevennevins (Escher) confirmed
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 buy function does not handle the case where a purchase would exceed the final ID; instead it reverts, allowing an attacker to block others by front-running.
Impact
The attacker could secure a larger portion of NFTs and the seller received the lowest possible revenue, while other buyers' transactions reverted.
What the attacker needed
A Dutch auction with a limited number of NFTs; Attacker has enough funds to mint at higher prices; Attacker can monitor the mempool and send transactions with…
The fix
The code should be changed to cap the number of NFTs minted when the new ID exceeds the final ID, rather than reverting.
How it was found
- At the start of the auction, the attacker mints some NFTs at higher prices.
- When few NFTs remain, the attacker watches the mempool for other buyers' transactions.
- The attacker front-runs those transactions by calling buy() with a higher gas price to mint one NFT.
- The other buyers' transactions revert because the new ID would exceed the final ID.
- The attacker repeats this until they have minted all desired NFTs.
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.
In a Dutch auction, the price of an item drops over time. This report shows that a buyer could watch other people's pending purchases and pay extra to get their own purchase processed first. By doing this repeatedly, they could stop others from buying and grab more items for themselves, which also meant the seller earned less money.
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.