Provide a Simple Code Example of a Function Following the CEI Pattern.

A secure withdrawal function following CEI would first check the user's balance ( require(balance > 0) ), then set the user's balance to zero (Effects: balance = 0 ), and finally send the Ether to the user (Interactions: msg.sender.call{value: amount}("") ). The key is that the state change (setting balance to zero) happens before the external call, preventing re-entry from succeeding.

What Is the Difference between ‘Last Look’ and ‘Pre-Trade Credit Check’ in Derivatives Trading?
What Is the Checks-Effects-Interactions Pattern?
Are There Scenarios Where the Checks-Effects-Interactions Pattern Is Insufficient?
How Can an Underflow Be Exploited to Drain Funds from a Contract?
Why Do Complex Smart Contract Interactions Require a Higher Gas Limit?
How Do Modern Solidity Versions Recommend Handling Ether Transfers Instead of Using a Gas Stipend?
What Is the Checks-Effects-Interactions Pattern and How Does It Prevent Reentrancy?
Can the CEI Pattern Be Applied to Other Security Vulnerabilities besides Reentrancy?

Glossar