Created
December 1, 2017 10:11
-
-
Save KenKappler/30d0c6a4b34782b9c353158d0f25bf8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Dispatcher { | |
address public dest; | |
address owner; | |
modifier only_owner(){ | |
if(msg.sender == owner){ | |
_; | |
} else { | |
revert(); | |
} | |
} | |
function Dispatcher(address _target) public { | |
owner = msg.sender; | |
dest = _target; | |
_target.delegatecall(bytes4(keccak256("initialize()"))); | |
} | |
function initialize() public{ | |
// Should only be called by on target contracts, not on the dispatcher | |
revert(); | |
} | |
function() public{ | |
var target = dest; | |
assembly { | |
calldatacopy(0x0, 0x0, calldatasize) | |
let a := delegatecall(sub(gas, 10000), target, 0, calldatasize, 0, 0) | |
returndatacopy(0, 0, returndatasize) | |
return(0, returndatasize) | |
} | |
} | |
function replace(address _target) | |
public | |
only_owner | |
{ | |
dest = _target; | |
_target.delegatecall(bytes4(keccak256("initialize()"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment