The function buyOrder() performs external calls (safeTransferFrom and safeTransfer) before updating state variables, which is dangerous. Although ERC20 tokens are generally safe, a malicious token (non-compliant ERC20) could re-enter the contract and exploit logic or steal funds.
These external token calls could reenter if the token is malicious or not ERC20-compliant, especially before order.isActive = false is set.
A malicious ERC20 token could exploit the lack of ReentrancyGuard by reentering into the contract during a token transfer (safeTransferFrom or safeTransfer) and invoking functions like buyOrder() or cancelSellOrder() again.
Deploy a malicious ERC20 token with a transfer or transferFrom hook that calls back into the OrderBook contract (e.g., calls buyOrder() again).
Create a sell order using this malicious token.
Call buyOrder() on the order.
During the execution of safeTransfer, the malicious token reenters and calls buyOrder() again before order.isActive is set to false.
Now both calls think the order is still active — the order can be filled twice.
Add the ReentrancyGuard modifier from OpenZeppelin and apply nonReentrant to:
buyOrder()
cancelSellOrder()
amendSellOrder()
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.