Files
asle/contracts/src/libraries/LibReentrancyGuard.sol
defiQUG 507d9a35b1 Add initial project structure and documentation files
- Created .gitignore to exclude sensitive files and directories.
- Added API documentation in API_DOCUMENTATION.md.
- Included deployment instructions in DEPLOYMENT.md.
- Established project structure documentation in PROJECT_STRUCTURE.md.
- Updated README.md with project status and team information.
- Added recommendations and status tracking documents.
- Introduced testing guidelines in TESTING.md.
- Set up CI workflow in .github/workflows/ci.yml.
- Created Dockerfile for backend and frontend setups.
- Added various service and utility files for backend functionality.
- Implemented frontend components and pages for user interface.
- Included mobile app structure and services.
- Established scripts for deployment across multiple chains.
2025-12-03 21:22:31 -08:00

59 lines
1.7 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title LibReentrancyGuard
* @notice Diamond-compatible reentrancy guard using Diamond storage pattern
* @dev Provides reentrancy protection for Diamond facets
*/
library LibReentrancyGuard {
bytes32 constant REENTRANCY_GUARD_STORAGE_POSITION = keccak256("asle.reentrancyguard.storage");
struct ReentrancyGuardStorage {
uint256 status; // 1 = locked, 2 = unlocked
}
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
function reentrancyGuardStorage() internal pure returns (ReentrancyGuardStorage storage rgs) {
bytes32 position = REENTRANCY_GUARD_STORAGE_POSITION;
assembly {
rgs.slot := position
}
}
/**
* @notice Initialize reentrancy guard
*/
function initialize() internal {
ReentrancyGuardStorage storage rgs = reentrancyGuardStorage();
require(rgs.status == 0, "LibReentrancyGuard: already initialized");
rgs.status = _NOT_ENTERED;
}
/**
* @notice Enter a non-reentrant function
*/
function enter() internal {
ReentrancyGuardStorage storage rgs = reentrancyGuardStorage();
// Initialize if not already done
if (rgs.status == 0) {
rgs.status = _NOT_ENTERED;
}
require(rgs.status != _ENTERED, "LibReentrancyGuard: reentrant call");
rgs.status = _ENTERED;
}
/**
* @notice Exit a non-reentrant function
*/
function exit() internal {
ReentrancyGuardStorage storage rgs = reentrancyGuardStorage();
rgs.status = _NOT_ENTERED;
}
}