-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathReentrancyProtection.sol
More file actions
28 lines (24 loc) · 963 Bytes
/
ReentrancyProtection.sol
File metadata and controls
28 lines (24 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.28;
// NOTE: This file has warning disabled due https://github.com/ethereum/solidity/issues/14359
// If perform any change on it, please ensure no other warnings appears
/// @title ReentrancyProtection
/// @notice Abstract contract that implements reentrancy protection using transient storage.
abstract contract ReentrancyProtection {
/// @notice Dispatched when there is a re-entrancy issue
error UnauthorizedSender();
address private transient _initiator;
/// @dev The method is protected for reentrancy issues.
modifier protected() {
if (_initiator == address(0)) {
// Single call re-entrancy lock
_initiator = msg.sender;
_;
_initiator = address(0);
} else {
// Multicall re-entrancy lock
require(msg.sender == _initiator, UnauthorizedSender());
_;
}
}
}