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.