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.

Why Must State Updates Occur before External Calls?
What Is a Common Vulnerability Found in Smart Contract Code?
Provide a Simple Code Example of a Function Following the CEI Pattern.
How Does the Checks-Effects-Interactions Pattern Prevent Reentrancy Attacks?
Can the CEI Pattern Prevent All Types of Reentrancy?
What Is the Defense against a Read-Only Reentrancy Attack?
Why Is Updating State before an External Call the Critical Part of the CEI Pattern?
How Do Collateral Management Functions Introduce Reentrancy Risk in Options Contracts?

Glossar