Created
April 10, 2018 03:37
-
-
Save ayinot/ef7920287782981e6b29a4011aa7e6d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pragma solidity ^0.4.18; | |
import "./Ownable.sol"; | |
contract Proxy is Ownable { | |
event Upgraded(address indexed implementation); | |
address internal _implementation; | |
function implementation() public view returns (address) { | |
return _implementation; | |
} | |
function upgradeTo(address impl) public onlyOwner { | |
require(_implementation != impl); | |
_implementation = impl; | |
Upgraded(impl); | |
} | |
function () payable public { | |
address _impl = implementation(); | |
require(_impl != address(0)); | |
bytes memory data = msg.data; | |
assembly { | |
let result := delegatecall(gas, _impl, add(data, 0x20), mload(data), 0, 0) | |
let size := returndatasize | |
let ptr := mload(0x40) | |
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