OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Broken CEI Pattern Allows Potential State Inconsistency

Broken CEI Pattern Allows Potential State Inconsistency

Description

  • Normally, when withdrawing collected fees, the function should first update the contract’s internal state before making any external token transfers. This ensures the contract remains consistent even if the external call fails.

  • In this case, the 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.

function withdrawFees(address _to) external onlyOwner {
if (totalFees == 0) {
revert InvalidAmount();
}
if (_to == address(0)) {
revert InvalidAddress();
}
@> iUSDC.safeTransfer(_to, totalFees);
@> totalFees = 0;
emit FeesWithdrawn(_to);
}

Risk

Likelihood - Medium:

  • This issue can appear if the external token contract (iUSDC) fails or reverts during transfer, such as in cases of misconfiguration, insufficient allowance, paused tokens, or non-standard ERC20 behavior.

Impact:

  • Even though iUSDC may work as expected now, skipping the CEI pattern increases the chance of bugs during future changes

Recommended Mitigation

- iUSDC.safeTransfer(_to, totalFees);
-
- totalFees = 0;
+ uint256 fees = totalFees;
+ totalFees = 0;
+
+ iUSDC.safeTransfer(_to, fees);
Updates

Lead Judging Commences

yeahchibyke Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

CEI pattern not followed in `withdrawFees()` function

`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.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.