In the original transferErcTokens function, the state is updated before confirming the success of the external transfer. This can lead to inconsistencies in the contract’s state if the external transfer fails after state changes are applied, which is a violation of the CEI (Checks-Effects-Interactions) pattern.
The state changes (updating balances) occur before the external transfer is confirmed.
If the external transfer fails (due to insufficient funds, transaction reversion, etc.), the contract's state will already be modified, leading to inconsistent or incorrect balances.
This creates a potential risk for funds being lost or misallocated due to the mismatch between the internal state and external contract state.
Inconsistent State: If the external token transfer fails after updating the state, the internal balances may not match the true token holdings.
Security Risk: Attackers could exploit this inconsistency by manipulating balances, leading to incorrect fund allocations or even the possibility of a reentrancy attack in certain cases.
Manual code review
Follow CEI Pattern: Ensure that state changes are made only after the success of the external transfer.
Revised Function: Update the function to:
Perform checks first (input validation, balance checks).
Perform external interaction (transfer tokens) next.
Update the state and emit events only if the external interaction is successful.
By adopting this pattern, the contract ensures that its state remains consistent, and external interactions will not cause unwanted side effects or vulnerabilities.
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.