The withdrawFees
function transfers accumulated protocol fees (totalFees
) to the owner-specified address.
The function first performs an external call (iUSDC.safeTransfer
) before updating internal state (totalFees = 0
).
This is a violation of the "Checks-Effects-Interactions" pattern, a best practice in Solidity that prevents reentrancy and state inconsistency risks.
If the safeTransfer
call fails or reverts, totalFees
remains unchanged — which is acceptable. But if the transfer succeeds but a reentrancy or subsequent failure occurs, it could result in unintended behavior or double-withdrawals in more complex versions of the function.
File | Function | Lines | Note |
---|---|---|---|
./src/OrderBook.sol |
withdrawFees |
L298–L313 | External call before state mutation |
The function is admin-only, reducing attack surface.
However, fee withdrawals are routine operations, and a failure in safeTransfer()
(e.g. token misbehavior, non-standard return) could cause issues.
If the code evolves to include hooks, modifiers, or other logic after the transfer, risks would increase.
Currently low risk of exploitation due to simplicity, but:
Breaks Solidity best practices.
Can cause inconsistent contract state in the event of failed or malicious token transfers.
Future changes (e.g. multi-token support, callbacks) could make this a reentrancy vector.
Reorder operations to follow Checks-Effects-Interactions pattern:
Document best-practice adherence
Add comments to clarify why state change is done before transfer.
Future-Proofing
If supporting multiple tokens or callbacks later, this change reduces risk of reentrancy or inconsistencies.
`withdrawFees()` function performs an external transfer using `iUSDC.safeTransfer()` before resetting totalFees. This breaks the `Checks-Effects-Interactions (CEI)` pattern and can lead to incorrect internal state if the transfer fails for any reason.
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.