The buyOrder() function is vulnerable to front-running attacks where malicious sellers can monitor the mempool for incoming buy transactions and modify their order prices at the last moment, potentially extracting additional value from buyers.
The buyOrder(uint256 _orderId) function only requires an orderId parameter and executes the trade at whatever price is currently set in the order. This design allows sellers to modify their order prices via the amendSellOrder() function right before a buyer's transaction is mined.
Likelihood: High
This can happen on any buyOrder() call. As the mempool is publicly visible, and the orderbook is a public contract, anyone can see the orderbook and the orders.
Impact: High
Buyers may pay significantly more than the originally advertised price
Attackers can extract additional value through price and amout manipulation
Market participants lose trust in the order book's price discovery mechanism
Users cannot rely on displayed prices and values when placing orders
Potential for MEV extraction by sophisticated attackers
Attacker creates an attractive order
Attacker scans the mempool
User accepts the order and calls buyOrder()
Attacker adjusts the order with more gas(), frontrunning the user
User pays the new amount+price that the attacker decided
1. Price Commitment Mechanism
Implement a commitment-based system where buyers specify a maximum price and minimum amount they're willing to pay:
(optionally consider to ONLY allow to change the price and not amount, to make verification and buying easier)
2. Order Hash Verification
Use cryptographic commitments to prevent price modifications:
3. Remove the amendSellOrder function
If a user wants to modify the order, they can cancel and create a new order.
A malicious seller can front-run a buy order for their order, and decrease the amount of assets to be sold. If the price is unchanged, the buy transaction fulfills, but the buyer gets lesser amount than expected.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.