In the OrderBook contract, the buyOrder function processes a buy order by transferring USDC from the buyer to the contract (for fees) and the seller (for the order price minus fees), then transferring the seller’s tokens to the buyer. It updates totalFees after these transfers to track accumulated protocol fees. Similarly, the withdrawFees function transfers accumulated USDC fees to the owner and then resets totalFees to zero.
In buyOrder, the state update totalFees += protocolFee occurs after safeTransferFrom calls for USDC transfers. In withdrawFees, the state update totalFees = 0 occurs after the iUSDC.safeTransfer call. This deviates from the Checks-Effects-Interactions pattern, which recommends updating state before external calls to minimize risks like reentrancy or state inconsistencies in complex scenarios. While SafeERC20 mitigates reentrancy risks and transaction atomicity ensures state reversion on failure, reordering these updates would enhance robustness and align with best practices.
Likelihood: low
The issue occurs during every execution of buyOrder and withdrawFees, as the state updates (totalFees += protocolFee and totalFees = 0) are consistently placed after external SafeERC20 calls, deviating from the Checks-Effects-Interactions pattern.
Impact: low
The current order of operations is safe due to SafeERC20 and transaction atomicity, but it increases the risk of state inconsistencies and might allow reentrancy-prone tokens or complex interactions, potentially leading to incorrect fee tracking.
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.