The buyOrder() function is vulnerable to a frontrun attack because it has no mecanism to protect the user against it
An attacker could either :
buy the order before the user (no big deal)
amend his own order before the buying of the user (critical)
If the user has approved more USDC than the desired amount for the current order, the attacker could benefit from it and amend the order by either increase the USDC amount desired, and/or decrease the token amount (weth, wbtc, wsol) he gives in exchange.
Likelihood:
if an attacker frontun a purchase from a user on his order → always possible
Impact:
The loss of the user’s fund
The best solution is to implement a commit & reveal system, that allows the user to first announces that he want to buy the order, in a private way (nobody can see which order he wants to buy), and then buys the order. An attacker won’t be able to frontrun the second call since we will be able to verify that the order is in buying state.
Another solution is to give the user the ability to pass into the buyOrder function the amount he is willing to pay and to receive. It’s easier to implement, but not very secure since we let the responsability to the user to manage the security of the transaction.
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.