Checks-Effects-Interactions
Pattern in OrderBook::withdrawFees()
May Pose Future RiskUnder normal behavior, the OrderBook::withdrawFees()
function allows the contract owner to withdraw accumulated protocol fees in USDC. The function performs access control via onlyOwner
and emits a FeesWithdrawn
event after the withdrawal.
However, this function performs an external call (iUSDC.safeTransfer
) before updating internal state (totalFees = 0
), violating the recommended Checks-Effects-Interactions
(CEI) pattern. Although no immediate vulnerability exists due to USDC being a standard ERC20 token, this pattern can introduce fragility and risk if:
The USDC token is replaced with a non-standard token (e.g., ERC777 or malicious ERC20)
The function is extended or reused in an upgradable architecture
Ownership is transferred to a contract with unknown logic
Likelihood:
Moderate likelihood under upgradable design or token change
May affect maintainability and extensibility
Impact:
Increased risk of reentrancy in future integrations
Unexpected behavior if token uses non-standard logic
Reduces auditability and developer confidence
Even though not exploitable today, here's a non-exploitable simulation to illustrate the CEI violation:
However, in practice:
USDC doesn’t execute external calls on transfer or safeTransfer
So fallback or reentrancy from withdrawFees() using USDC is impossible
Apply the CEI pattern to eliminate unnecessary external call risks:
This change ensures the internal state is updated before any external call, minimizing reentrancy and edge-case risks in future versions.
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.