Last active
February 24, 2019 14:37
-
-
Save yakkomajuri/56bca8a725787c5ed28bd857612db0ef 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 Proxy { | |
modifier onlyOwner() { | |
address owner; | |
assembly { | |
owner := sload(0xfffffffffffffffffffffffffffffffffffffffe) | |
} | |
require(msg.sender == owner); | |
_; | |
} | |
constructor() public { | |
address owner = msg.sender; | |
assembly { | |
sstore(0xfffffffffffffffffffffffffffffffffffffffe, owner) | |
} | |
} | |
function setImplementation(address _implementation) public onlyOwner { | |
assembly { | |
sstore(0xffffffffffffffffffffffffffffffffffffffff, _implementation) | |
} | |
} | |
function () external payable { | |
address localImpl; | |
assembly { | |
localImpl := sload(0xffffffffffffffffffffffffffffffffffffffff) | |
} | |
assembly { | |
let ptr := mload(0x40) | |
calldatacopy(ptr, 0, calldatasize) | |
let result := delegatecall(gas, localImpl, ptr, calldatasize, 0, 0) | |
let size := returndatasize | |
returndatacopy(ptr, 0, size) | |
switch result | |
case 0 { revert(ptr, size) } | |
default { return(ptr, size) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment