recovery alpha + ens based recoverer

This commit is contained in:
Ricardo Guilherme Schmidt 2017-12-01 04:45:26 -02:00
parent ef4580ab55
commit 241047951a
8 changed files with 67 additions and 19 deletions

View File

@ -9,16 +9,26 @@ import "./BasicSystemStorage.sol";
* @dev Abstract recoverer contract that should be crafted to alter `address system` storage * @dev Abstract recoverer contract that should be crafted to alter `address system` storage
* in delegated logic contracts. * in delegated logic contracts.
*/ */
contract AnstractRecoverer is BasicSystemStorage { contract AbstractRecoverer is BasicSystemStorage {
/** /**
* @dev will be callable in emergency state of RecorverableSystem * @dev will be callable in emergency state of RecorverableSystem
*/ */
function recoverSystem(address newSystem) public { function recoverSystem(address newSystem) public {
require(msg.sender == consensusContract()); require(msg.sender == consensusContract());
require(isOk(newSystem));
system = newSystem; system = newSystem;
} }
/**
* @dev checks if `_a` contains code
*/
function isOk(address _a) internal constant returns(bool r) {
assembly{
r := gt(extcodesize(_a), 0)
}
}
/** /**
* @dev returns the consesus contract, can be a multisig or other DAO * @dev returns the consesus contract, can be a multisig or other DAO
* should be implemented by a child contract * should be implemented by a child contract

View File

@ -8,9 +8,7 @@ pragma solidity ^0.4.17;
* avoid overwriting wrong storage pointers * avoid overwriting wrong storage pointers
*/ */
contract BasicSystemStorage { contract BasicSystemStorage {
/// protected zone start (RecorverableSystem vars) address public system;
address system; address public recover;
address recover; address public watchdog;
address watchdog;
/// protected zone end
} }

View File

@ -11,14 +11,14 @@ contract DelegatedCall {
* @dev delegates the call of this function * @dev delegates the call of this function
*/ */
modifier delegated { modifier delegated {
require(_target().delegatecall(msg.data)); //require successfull delegate call to remote `_target()` //require successfull delegate call to remote `_target()`
require(_target().delegatecall(msg.data));
assembly { assembly {
let outSize := returndatasize let outSize := returndatasize
let outDataPtr := mload(0x40) //load memory let outDataPtr := mload(0x40) //load memory
returndatacopy(outDataPtr, 0, outSize) //copy last return into pointer returndatacopy(outDataPtr, 0, outSize) //copy last return into pointer
return(outDataPtr, outSize) return(outDataPtr, outSize)
} }
assert(false); //should never reach here
_; //never will execute local logic _; //never will execute local logic
} }

View File

@ -0,0 +1,24 @@
pragma solidity ^0.4.17;
import "./AbstractRecoverer.sol";
import "../ens/ENS.sol";
/**
* @title ENSRecoverer
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @dev Common abstract recoverer resolved from ens.
*/
contract ENSRecoverer is AbstractRecoverer {
/**
* @dev resolves consensusContract from ens.
*/
function consensusContract() public constant returns(address) {
bytes32 node = ensNode();
return ensRoot().resolver(node).addr(node);
}
function ensNode() public constant returns(bytes32);
function ensRoot() public constant returns(ENS);
}

View File

@ -17,14 +17,6 @@ contract KillableModel is BasicSystemStorage {
watchdog = _watchdog; watchdog = _watchdog;
} }
function changeWatchdog(address newWatchDog) public {
require(msg.sender == watchdog);
watchdog = newWatchDog;
}
/**
* @dev Should be only possible to call this at Model. Never set watchdog var at instances.
*/
function emergencyStop() public { function emergencyStop() public {
require(msg.sender == watchdog); require(msg.sender == watchdog);
selfdestruct(watchdog); selfdestruct(watchdog);

View File

@ -9,8 +9,13 @@ import "./DelegatedCall.sol";
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
* @dev Contract that recovers from dead system to recoverer. * @dev Contract that recovers from dead system to recoverer.
*/ */
contract RecoverableSystem is BasicSystemStorage, DelegatedCall { contract RecoverableSystem is BasicSystemStorage, DelegatedCall {
/**
* @dev Requires at least valid _recoverer, that can elect the first system.
* @param _system the first system
* @param _recover the recoverer contract
*/
function RecoverableSystem(address _system, address _recover) public { function RecoverableSystem(address _system, address _recover) public {
require(isOk(_recover)); require(isOk(_recover));
system = _system; system = _system;
@ -20,12 +25,12 @@ contract RecoverableSystem is BasicSystemStorage, DelegatedCall {
/** /**
* @dev delegatecall everything (but declared functions) to `_target()` * @dev delegatecall everything (but declared functions) to `_target()`
*/ */
function () public delegated { function () external payable delegated {
//all goes to system (or recover) //all goes to system (or recover)
} }
/** /**
* @dev checks if system contains code * @dev checks if system is not in recovery mode
*/ */
function isOk() public constant returns(bool a) { function isOk() public constant returns(bool a) {
return isOk(system); return isOk(system);

14
contracts/ens/ENS.sol Normal file
View File

@ -0,0 +1,14 @@
pragma solidity ^0.4.17;
import "./Resolver.sol";
contract ENS {
function owner(bytes32 node) public constant returns (address);
function resolver(bytes32 node) public constant returns (Resolver);
function ttl(bytes32 node) public constant returns (uint64);
function setOwner(bytes32 node, address owner) public;
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public;
function setResolver(bytes32 node, address resolver) public;
function setTTL(bytes32 node, uint64 ttl) public;
}

View File

@ -0,0 +1,5 @@
pragma solidity ^0.4.17;
contract Resolver {
function addr(bytes32 node) public constant returns (address);
}