Skip to main content

How Does the Checks-Effects-Interactions Pattern Prevent Reentrancy Attacks?

The Checks-Effects-Interactions pattern is a security best practice for writing smart contracts. It dictates that the contract should first perform all necessary checks (e.g. verifying permissions), then apply all effects to its internal state (e.g. updating balances), and only then interact with external contracts.

By updating the state before making an external call, the contract prevents a malicious actor from re-entering the function in a vulnerable state. This ensures that even if the external contract calls back, the internal state is already updated, and the conditions for the attack are no longer met.

Why Is Updating State before an External Call the Critical Part of the CEI Pattern?
How Can Reentrancy Attacks Be Prevented in Smart Contracts?
What Is a Common Vulnerability Found in Smart Contract Code?
What Role Does the CALL Opcode Play in Enabling Reentrancy?