Skip to content

Instantly share code, notes, and snippets.

@ayinot
Created April 4, 2018 14:52
Show Gist options
  • Save ayinot/4f2aa3c528918ca3a57dbd3ec5f9cd26 to your computer and use it in GitHub Desktop.
Save ayinot/4f2aa3c528918ca3a57dbd3ec5f9cd26 to your computer and use it in GitHub Desktop.
Related to Contract Upgradation
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