NonReentrancyMod
Prevent reentrant calls within diamond facets
- Provides
enter()andexit()internal functions for reentrancy protection. - Emits a
Reentrancy()error if a reentrant call is detected. - Designed for use as an internal library within diamond facets.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This library provides functions to prevent reentrant calls within diamond facets. By importing and using its internal functions, facets can enforce non-reentrant execution flows, enhancing contract security. This prevents unexpected state changes and exploits that rely on recursive function calls.
Storage
State Variables
| Property | Type | Description |
|---|---|---|
NON_REENTRANT_SLOT | bytes32 | Reentrancy guard storage slot (Value: keccak256("compose.nonreentrant")) |
Functions
enter
How to use as a library in user facets How to use as a modifier in user facets This unlocks the entry into a function
exit
This locks the entry into a function
Errors
Best Practices
- Call
enter()at the beginning of any function that should be protected against reentrancy. - Call
exit()at the end of the protected function before returning control. - Ensure the
Reentrancy()error is handled appropriately in calling facets or the diamond proxy.
Integration Notes
This library utilizes standard Solidity function calls and does not interact directly with diamond storage. Its reentrancy guard state is managed internally within the calling facet's execution context. Changes to the reentrancy guard are local to the function call and do not affect other facets or diamond storage.