What Is the Checks-Effects-Interactions Pattern?

The Checks-Effects-Interactions (CEI) pattern is a smart contract coding standard designed to prevent reentrancy attacks. It dictates that a function should perform all necessary Checks (e.g. input validation, access control) first.

Then, it should execute all Effects (e.g. updating state variables like balances) internally. Finally, it should perform any Interactions (e.g. external calls to other contracts or sending Ether).

By updating the state before making external calls, the contract is protected from a recursive call-back.

What Is a Mutex in Traditional Programming, and How Does It Relate to a Reentrancy Guard?
Can a Reentrancy Attack Be Performed without a Fallback Function?
Why Must State Updates Occur before External Calls?
How Do Collateral Management Functions Introduce Reentrancy Risk in Options Contracts?
How Does a Storage Variable Update Relate to the “Effects” Stage of the CEI Pattern?
What Is Reentrancy and Why Is It a Critical Smart Contract Vulnerability?
What Is the Checks-Effects-Interactions Pattern and How Does It Prevent Reentrancy?
Are There Scenarios Where the Checks-Effects-Interactions Pattern Is Insufficient?

Glossar