-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathReentrencyTransactionGuard.sol
More file actions
51 lines (44 loc) · 1.4 KB
/
ReentrencyTransactionGuard.sol
File metadata and controls
51 lines (44 loc) · 1.4 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import "../../common/Enum.sol";
import "../../base/GuardManager.sol";
import "../../GnosisSafe.sol";
contract ReentrencyTransactionGuard is Guard {
bytes32 internal constant GUARD_STORAGE_SLOT = keccak256("reentrentry_guard.guard.struct");
struct GuardValue {
bool active;
}
// solhint-disable-next-line payable-fallback
fallback() external {
// We don't revert on fallback to avoid issues in case of a Safe upgrade
// E.g. The expected check method might change and then the Safe would be locked.
}
function getGuard() internal pure returns (GuardValue storage guard) {
bytes32 slot = GUARD_STORAGE_SLOT;
// solhint-disable-next-line no-inline-assembly
assembly {
guard.slot := slot
}
}
function checkTransaction(
address,
uint256,
bytes memory,
Enum.Operation,
uint256,
uint256,
uint256,
address,
// solhint-disable-next-line no-unused-vars
address payable,
bytes memory,
address
) external override {
GuardValue storage guard = getGuard();
require(!guard.active, "Reentrency detected");
guard.active = true;
}
function checkAfterExecution(bytes32, bool) external override {
getGuard().active = false;
}
}