Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Kill switch: Proof of concept #516

Closed
wants to merge 8 commits into from
Next Next commit
contracts: base kill switch implementation
facuspagnuolo committed Apr 28, 2019
commit 16e236def19c4a16e3e8ac7c0dd0020399c1c760
31 changes: 31 additions & 0 deletions contracts/kill_switch/base/IssuesRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pragma solidity 0.4.24;

import "../../apps/AragonApp.sol";


contract IssuesRegistry is AragonApp {
bytes32 constant public SET_ENTRY_SEVERITY_ROLE = keccak256("SET_ENTRY_SEVERITY_ROLE");

enum Severity { None, Low, Mid, High, Critical }

mapping (address => Severity) internal issuesSeverity;

event SeveritySet(address indexed entry, Severity severity, address sender);

function initialize() public onlyInit {
initialized();
}

function isSeverityFor(address entry) public view isInitialized returns (bool) {
return issuesSeverity[entry] != Severity.None;
}

function getSeverityFor(address entry) public view isInitialized returns (Severity) {
return issuesSeverity[entry];
}

function setSeverityFor(address entry, Severity severity) authP(SET_ENTRY_SEVERITY_ROLE, arr(entry, msg.sender)) public {
issuesSeverity[entry] = severity;
emit SeveritySet(entry, severity, msg.sender);
}
}
48 changes: 48 additions & 0 deletions contracts/kill_switch/base/KillSwitch.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
pragma solidity 0.4.24;

import "./IssuesRegistry.sol";


contract KillSwitch {
IssuesRegistry public issuesRegistry;

event IssuesRegistrySet(address issuesRegistry, address sender);

function isContractIgnored(address _contract) public view returns (bool);

function isSeverityIgnored(address _contract, IssuesRegistry.Severity _severity) public view returns (bool);

function shouldDenyCallingContract(address _base, address _instance, address _sender, bytes _data, uint256 _value) public returns (bool) {
// if the call should not be evaluated, then allow given call
if (!_shouldEvaluateCall(_base, _instance, _sender, _data, _value)) return false;

// if the contract issues are ignored, then allow given call
if (isContractIgnored(_base)) return false;

// if the issues registry has not been set, then allow given call
if (issuesRegistry == address(0)) return false;

// if the contract severity found is ignored, then allow given call
IssuesRegistry.Severity _severityFound = issuesRegistry.getSeverityFor(_base);
if (isSeverityIgnored(_base, _severityFound)) return false;

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

/**
* @dev This function allows different kill-switch implementations to provide a custom logic to tell whether a
* certain call should be denied or not. This is important to ensure recoverability. For example, custom
* implementations could override this function to provide a decision based on the msg.sender, timestamp,
* block information, among many other options.
* @return Always true by default.
*/
function _shouldEvaluateCall(address /*_base*/, address /*_instance*/, address /*_sender*/, bytes /*_data*/, uint256 /*_value*/) internal returns (bool) {
return true;
}

function _setIssuesRegistry(IssuesRegistry _issuesRegistry) internal {
issuesRegistry = _issuesRegistry;
emit IssuesRegistrySet(_issuesRegistry, msg.sender);
}
}