This repository has been archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
SafeGuard.sol
79 lines (72 loc) · 2.37 KB
/
SafeGuard.sol
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/access/Ownable.sol";
import "../core/BaseGuard.sol";
/**
* @title SafeGuard
* @author Amir M. Shirif
* @notice A Telcoin Laboratories Contract
* @notice Designed to protect against non-compliant votes
*/
contract SafeGuard is BaseGuard, Ownable {
error PreviouslyVetoed(bytes32 hash);
// Mapping of transaction hash to its veto status
mapping(bytes32 => bool) public transactionHashes;
uint256[] public nonces;
constructor() Ownable(_msgSender()) {}
/**
* @notice Allows the contract owner to veto a transaction by its hash
* @dev restricted to onlyOwner
* @param transactionHash Hash of the transaction to be vetoed
* @param nonce Nonce of the transaction
*/
function vetoTransaction(
bytes32 transactionHash,
uint256 nonce
) public onlyOwner {
// Revert if the transaction has already been vetoed
if (transactionHashes[transactionHash])
revert PreviouslyVetoed(transactionHash);
// Mark the transaction as vetoed
transactionHashes[transactionHash] = true;
// Add the nonce of the transaction to the nonces array
nonces.push(nonce);
}
/**
* @dev Checks if a transaction has been vetoed by its hash
* @param to Address of the recipient of the transaction
* @param value Value of the transaction
* @param data Data of the transaction
* @param operation Operation of the transaction
*/
function checkTransaction(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
uint256,
uint256,
uint256,
address,
address payable,
bytes memory,
address
) external view override {
// cycles through possible transactions
for (uint256 i = 0; i < nonces.length; i++) {
bytes32 transactionHash = IReality(_msgSender()).getTransactionHash(
to,
value,
data,
operation,
nonces[i]
);
require(
!transactionHashes[transactionHash],
"SafeGuard: transaction has been vetoed"
);
}
}
// not used
function checkAfterExecution(bytes32, bool) external view override {}
}