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.
Glossar
CEI Pattern
Principle ⎊ The CEI Pattern, standing for Checks-Effects-Interactions, is a fundamental security principle in smart contract development.
Reentrancy Prevention
Countermeasure ⎊ Reentrancy prevention involves implementing specific coding patterns within smart contracts to neutralize the risk of unauthorized recursive calls during state transitions.