Skip to main content

NonReentrancyMod

Prevent reentrant calls within diamond facets

Key Features
  • Provides enter() and exit() 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.
Module Usage

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

PropertyTypeDescription
NON_REENTRANT_SLOTbytes32Reentrancy 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

function enter() ;

exit

This locks the entry into a function

function exit() ;

Errors

Best Practices

Best Practice
  • 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

Shared Storage

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.

Was this helpful?
Last updated: