Skip to main content

How Does the Nonreentrant Modifier Implement the CEI Principle?

The nonReentrant modifier implements the CEI principle by using a mutex lock (a state variable). At the start of the function (Checks), it verifies the lock is not set.

It then sets the lock (Effects). The function's logic, including the external call (Interaction), executes.

Crucially, the lock is only released at the end of the function. This ensures that any re-entry attempt will find the lock set and revert, enforcing the order of operations.

How Do Solidity Modifiers like Nonreentrant Implement the CEI Principle?
How Does a Storage Variable Update Relate to the “Effects” Stage of the CEI Pattern?
What Is a Mutex Lock and How Is It an Alternative Reentrancy Prevention Mechanism?
Why Is Updating State before an External Call the Critical Part of the CEI Pattern?