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.
Glossar
CEI Pattern
Principle ⎊ The CEI Pattern, standing for Checks-Effects-Interactions, is a fundamental security principle in smart contract development.
Vulnerable Code Structure
Structure ⎊ Vulnerable Code Structure refers to architectural or organizational deficiencies within a smart contract's codebase that create latent security weaknesses, even if individual functions appear correct.
Nonreentrant Modifier
Vulnerability ⎊ A nonreentrant modifier, within the context of smart contract security in cryptocurrency, addresses a specific class of attack where a malicious actor exploits recursive calls to alter contract state unexpectedly.