Skip to content

Commit 75c8a1d

Browse files
committed
kill-switch: cleanup models leaving only app level
1 parent 341c6c8 commit 75c8a1d

27 files changed

+787
-1650
lines changed

contracts/factory/DAOFactory.sol

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity 0.4.24;
33
import "../kernel/IKernel.sol";
44
import "../kernel/Kernel.sol";
55
import "../kernel/KernelProxy.sol";
6-
import "../kill_switch/kernel/KernelKillSwitch.sol";
76

87
import "../acl/IACL.sol";
98
import "../acl/ACL.sol";
@@ -54,26 +53,6 @@ contract DAOFactory {
5453
return dao;
5554
}
5655

57-
/**
58-
* @notice Create a new DAO with `_root` set as the initial admin and `_issuesRegistry` as the source of truth for kill-switch purpose
59-
* @param _root Address that will be granted control to setup DAO permissions
60-
* @param _issuesRegistry Address of the registry of issues that will be used in case of critical situations by the kernel kill switch
61-
* @return Newly created DAO
62-
*/
63-
function newDAOWithKillSwitch(address _root, IssuesRegistry _issuesRegistry) public returns (KernelKillSwitch) {
64-
KernelKillSwitch dao = KernelKillSwitch(new KernelProxy(baseKernel));
65-
66-
if (address(regFactory) == address(0)) {
67-
dao.initialize(_issuesRegistry, baseACL, _root);
68-
} else {
69-
dao.initialize(_issuesRegistry, baseACL, address(this));
70-
_setupNewDaoPermissions(_root, Kernel(dao));
71-
}
72-
73-
emit DeployDAO(address(dao));
74-
return dao;
75-
}
76-
7756
function _setupNewDaoPermissions(address _root, Kernel _dao) internal {
7857
ACL acl = ACL(_dao.acl());
7958
bytes32 permRole = acl.CREATE_PERMISSIONS_ROLE();

contracts/kill_switch/base/IssuesRegistry.sol renamed to contracts/kill_switch/IssuesRegistry.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pragma solidity 0.4.24;
22

3-
import "../../apps/AragonApp.sol";
3+
import "../apps/AragonApp.sol";
44

55

66
contract IssuesRegistry is AragonApp {
Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,56 @@ pragma solidity 0.4.24;
33
import "./IssuesRegistry.sol";
44

55

6-
contract KillSwitch {
6+
contract KillSwitch is AragonApp {
7+
bytes32 constant public SET_ISSUES_REGISTRY_ROLE = keccak256("SET_ISSUES_REGISTRY_ROLE");
78
bytes32 constant public SET_CONTRACT_ACTION_ROLE = keccak256("SET_CONTRACT_ACTION_ROLE");
9+
bytes32 constant public SET_LOWEST_ALLOWED_SEVERITY_ROLE = keccak256("SET_LOWEST_ALLOWED_SEVERITY_ROLE");
810

911
enum ContractAction { Check, Ignore, Deny }
1012

1113
IssuesRegistry public issuesRegistry;
1214
mapping (address => ContractAction) internal contractActions;
15+
mapping (address => IssuesRegistry.Severity) internal lowestAllowedSeverityByContract;
1316

1417
event IssuesRegistrySet(address issuesRegistry, address sender);
1518
event ContractActionSet(address contractAddress, ContractAction action);
19+
event LowestAllowedSeveritySet(address indexed _contract, IssuesRegistry.Severity severity);
1620

17-
function setContractAction(address _contract, ContractAction _action) external;
21+
function initialize(IssuesRegistry _issuesRegistry) external onlyInit {
22+
initialized();
23+
_setIssuesRegistry(_issuesRegistry);
24+
}
25+
26+
function setContractAction(address _contract, ContractAction _action)
27+
external
28+
authP(SET_CONTRACT_ACTION_ROLE, arr(_contract, msg.sender))
29+
{
30+
contractActions[_contract] = _action;
31+
emit ContractActionSet(_contract, _action);
32+
}
33+
34+
function setLowestAllowedSeverity(address _contract, IssuesRegistry.Severity _severity)
35+
external
36+
authP(SET_LOWEST_ALLOWED_SEVERITY_ROLE, arr(_contract, msg.sender))
37+
{
38+
lowestAllowedSeverityByContract[_contract] = _severity;
39+
emit LowestAllowedSeveritySet(_contract, _severity);
40+
}
41+
42+
function setIssuesRegistry(IssuesRegistry _issuesRegistry)
43+
external
44+
authP(SET_ISSUES_REGISTRY_ROLE, arr(msg.sender))
45+
{
46+
_setIssuesRegistry(_issuesRegistry);
47+
}
1848

1949
function getContractAction(address _contract) public view returns (ContractAction) {
2050
return contractActions[_contract];
2151
}
2252

23-
function isSeverityIgnored(address _contract, IssuesRegistry.Severity _severity) public view returns (bool);
53+
function getLowestAllowedSeverity(address _contract) public view returns (IssuesRegistry.Severity) {
54+
return lowestAllowedSeverityByContract[_contract];
55+
}
2456

2557
function isContractIgnored(address _contract) public view returns (bool) {
2658
return getContractAction(_contract) == ContractAction.Ignore;
@@ -30,6 +62,12 @@ contract KillSwitch {
3062
return getContractAction(_contract) == ContractAction.Deny;
3163
}
3264

65+
function isSeverityIgnored(address _contract) public view returns (bool) {
66+
IssuesRegistry.Severity severityFound = issuesRegistry.getSeverityFor(_contract);
67+
IssuesRegistry.Severity lowestAllowedSeverity = getLowestAllowedSeverity(_contract);
68+
return lowestAllowedSeverity >= severityFound;
69+
}
70+
3371
function shouldDenyCallingContract(address _base, address _instance, address _sender, bytes _data, uint256 _value) public returns (bool) {
3472
// if the call should not be evaluated, then allow given call
3573
if (!_shouldEvaluateCall(_base, _instance, _sender, _data, _value)) {
@@ -52,15 +90,19 @@ contract KillSwitch {
5290
}
5391

5492
// if the contract severity found is ignored, then allow given call
55-
IssuesRegistry.Severity _severityFound = issuesRegistry.getSeverityFor(_base);
56-
if (isSeverityIgnored(_base, _severityFound)) {
93+
if (isSeverityIgnored(_base)) {
5794
return false;
5895
}
5996

6097
// if none of the conditions above were met, then deny given call
6198
return true;
6299
}
63100

101+
function _setIssuesRegistry(IssuesRegistry _issuesRegistry) internal {
102+
issuesRegistry = _issuesRegistry;
103+
emit IssuesRegistrySet(_issuesRegistry, msg.sender);
104+
}
105+
64106
/**
65107
* @dev This function allows different kill-switch implementations to provide a custom logic to tell whether a
66108
* certain call should be denied or not. This is important to ensure recoverability. For example, custom
@@ -71,14 +113,4 @@ contract KillSwitch {
71113
function _shouldEvaluateCall(address, address, address, bytes, uint256) internal returns (bool) {
72114
return true;
73115
}
74-
75-
function _setIssuesRegistry(IssuesRegistry _issuesRegistry) internal {
76-
issuesRegistry = _issuesRegistry;
77-
emit IssuesRegistrySet(_issuesRegistry, msg.sender);
78-
}
79-
80-
function _setContractAction(address _contract, ContractAction _action) internal {
81-
contractActions[_contract] = _action;
82-
emit ContractActionSet(_contract, _action);
83-
}
84116
}

contracts/kill_switch/app/KillSwitchedApp.sol renamed to contracts/kill_switch/KillSwitchedApp.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
pragma solidity 0.4.24;
22

3-
import "./AppKillSwitch.sol";
4-
import "../../apps/AragonApp.sol";
3+
import "./KillSwitch.sol";
4+
import "../apps/AragonApp.sol";
55

66

77
contract KillSwitchedApp is AragonApp {
88
string private constant ERROR_CONTRACT_CALL_NOT_ALLOWED = "APP_CONTRACT_CALL_NOT_ALLOWED";
99

10-
AppKillSwitch internal appKillSwitch;
10+
KillSwitch internal killSwitch;
1111

1212
modifier killSwitched {
13-
bool _isCallAllowed = !appKillSwitch.shouldDenyCallingContract(_baseApp(), address(this), msg.sender, msg.data, msg.value);
13+
bool _isCallAllowed = !killSwitch.shouldDenyCallingContract(_baseApp(), address(this), msg.sender, msg.data, msg.value);
1414
require(_isCallAllowed, ERROR_CONTRACT_CALL_NOT_ALLOWED);
1515
_;
1616
}
1717

18-
function initialize(AppKillSwitch _appKillSwitch) public onlyInit {
18+
function initialize(KillSwitch _killSwitch) public onlyInit {
1919
initialized();
20-
appKillSwitch = _appKillSwitch;
20+
killSwitch = _killSwitch;
2121
}
2222

2323
function _baseApp() internal view returns (address) {

contracts/kill_switch/app/AppBinaryKillSwitch.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

contracts/kill_switch/app/AppKillSwitch.sol

Lines changed: 0 additions & 15 deletions
This file was deleted.

contracts/kill_switch/app/AppSeveritiesKillSwitch.sol

Lines changed: 0 additions & 21 deletions
This file was deleted.

contracts/kill_switch/base/BinaryKillSwitch.sol

Lines changed: 0 additions & 11 deletions
This file was deleted.

contracts/kill_switch/base/SeveritiesKillSwitch.sol

Lines changed: 0 additions & 25 deletions
This file was deleted.

contracts/kill_switch/kernel/KernelBinaryKillSwitch.sol

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)