Checks-Effects-Interactions Pattern
The Checks-Effects-Interactions pattern is a fundamental coding standard in Solidity designed to prevent vulnerabilities by strictly ordering operations within a function. First, the function performs all necessary checks, such as verifying user balances or permissions.
Second, it applies the state changes, such as updating user balances or decreasing a total supply. Finally, it performs external interactions, such as sending Ether or calling other contracts.
By ensuring that state changes occur before external calls, the contract is protected against reentrancy attacks because the state is already updated if a malicious contract tries to call back. This architectural discipline is essential for the security of any protocol handling value or sensitive state.
It is the primary defense mechanism against logic errors that could otherwise lead to fund theft.