Checks-Effects-Interactions
Checks-effects-interactions is a foundational design pattern in smart contract development that mitigates the risk of reentrancy and other state-related vulnerabilities. It dictates that a function should first perform all necessary checks on inputs and conditions, then update the contract's internal state to reflect the changes, and finally perform external interactions like transferring tokens.
By updating the state before sending funds, the contract ensures that if a malicious party attempts to re-enter the function, the state already reflects the previous withdrawal, preventing further unauthorized transfers. This simple yet effective pattern is a primary defense mechanism for secure derivative protocol design.
It aligns the code's execution flow with the logical sequence of a transaction.