What Is the Checks-Effects-Interactions Pattern and How Does It Prevent Reentrancy?
The Checks-Effects-Interactions pattern (CEI) is a security best practice for writing smart contracts. It dictates that all input validation (Checks) should happen first, followed by state changes (Effects), and finally, any interaction with external contracts (Interactions).
By updating the state (Effects) before the external call (Interactions), the contract prevents reentrancy, as the balance is zeroed out before the malicious re-entry attempt.