Skip to content

Instantly share code, notes, and snippets.

@KenKappler
Created December 1, 2017 10:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KenKappler/30d0c6a4b34782b9c353158d0f25bf8c to your computer and use it in GitHub Desktop.
Save KenKappler/30d0c6a4b34782b9c353158d0f25bf8c to your computer and use it in GitHub Desktop.
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