The OrderBook contract allows buyers to execute orders without slippage protection, which could lead to unexpected price disparities in volatile markets.
In traditional order book systems, especially those dealing with volatile assets like cryptocurrencies, slippage protection is crucial to ensure that trades execute at prices close to what users expect. The current implementation of the buyOrder function lacks any mechanism for slippage protection, meaning buyers are forced to accept the exact price set by the seller when the order was created, regardless of market conditions at the time of execution. This becomes problematic in volatile markets where token prices can change rapidly. A buyer might initiate a transaction to purchase an order, but by the time the transaction is mined, the market price of the token could have changed significantly. Without slippage protection, the buyer has no way to specify a maximum price they are willing to pay, potentially leading to trades executing at unfavourable prices.
A seller creates a sell order with a specific price in USDC.
Market conditions change, causing the actual value of the token to differ from the order price.
A buyer decides to purchase the order, but has no mechanism to specify a maximum slippage they are willing to accept.
If market conditions are unfavourable, the buyer might end up paying significantly more than the current market value.
Impact: Medium - Buyers could execute trades at unfavourable prices, but the exact price is known before execution.
Likelihood: Medium - Market conditions frequently change rapidly in cryptocurrency markets, making price disparities common.
OrderBook.sol
Implement a slippage protection mechanism in the buyOrder function that allows buyers to specify a maximum price they are willing to pay. This will prevent trades from executing at unfavourable prices due to market volatility.
The proposed fix adds a new function buyOrderWithSlippage that includes a parameter for the maximum price the buyer is willing to pay. The function checks that the order's price does not exceed this maximum before executing the trade. This allows buyers to protect themselves from unfavourable price movements.
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.