mirror of
https://github.com/status-im/contracts.git
synced 2025-02-24 12:38:49 +00:00
recovery alpha + ens based recoverer
This commit is contained in:
parent
ef4580ab55
commit
241047951a
@ -9,16 +9,26 @@ import "./BasicSystemStorage.sol";
|
||||
* @dev Abstract recoverer contract that should be crafted to alter `address system` storage
|
||||
* in delegated logic contracts.
|
||||
*/
|
||||
contract AnstractRecoverer is BasicSystemStorage {
|
||||
contract AbstractRecoverer is BasicSystemStorage {
|
||||
|
||||
/**
|
||||
* @dev will be callable in emergency state of RecorverableSystem
|
||||
*/
|
||||
function recoverSystem(address newSystem) public {
|
||||
require(msg.sender == consensusContract());
|
||||
require(isOk(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
|
||||
* should be implemented by a child contract
|
||||
|
@ -8,9 +8,7 @@ pragma solidity ^0.4.17;
|
||||
* avoid overwriting wrong storage pointers
|
||||
*/
|
||||
contract BasicSystemStorage {
|
||||
/// protected zone start (RecorverableSystem vars)
|
||||
address system;
|
||||
address recover;
|
||||
address watchdog;
|
||||
/// protected zone end
|
||||
address public system;
|
||||
address public recover;
|
||||
address public watchdog;
|
||||
}
|
@ -11,14 +11,14 @@ contract DelegatedCall {
|
||||
* @dev delegates the call of this function
|
||||
*/
|
||||
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 {
|
||||
let outSize := returndatasize
|
||||
let outDataPtr := mload(0x40) //load memory
|
||||
returndatacopy(outDataPtr, 0, outSize) //copy last return into pointer
|
||||
return(outDataPtr, outSize)
|
||||
}
|
||||
assert(false); //should never reach here
|
||||
_; //never will execute local logic
|
||||
}
|
||||
|
||||
|
24
contracts/deploy/ENSRecoverer.sol
Normal file
24
contracts/deploy/ENSRecoverer.sol
Normal 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);
|
||||
|
||||
}
|
@ -17,14 +17,6 @@ contract KillableModel is BasicSystemStorage {
|
||||
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 {
|
||||
require(msg.sender == watchdog);
|
||||
selfdestruct(watchdog);
|
||||
|
@ -11,6 +11,11 @@ import "./DelegatedCall.sol";
|
||||
*/
|
||||
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 {
|
||||
require(isOk(_recover));
|
||||
system = _system;
|
||||
@ -20,12 +25,12 @@ contract RecoverableSystem is BasicSystemStorage, DelegatedCall {
|
||||
/**
|
||||
* @dev delegatecall everything (but declared functions) to `_target()`
|
||||
*/
|
||||
function () public delegated {
|
||||
function () external payable delegated {
|
||||
//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) {
|
||||
return isOk(system);
|
||||
|
14
contracts/ens/ENS.sol
Normal file
14
contracts/ens/ENS.sol
Normal 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;
|
||||
}
|
5
contracts/ens/Resolver.sol
Normal file
5
contracts/ens/Resolver.sol
Normal file
@ -0,0 +1,5 @@
|
||||
pragma solidity ^0.4.17;
|
||||
|
||||
contract Resolver {
|
||||
function addr(bytes32 node) public constant returns (address);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user