Skip to content

Instantly share code, notes, and snippets.

@tinchoabbate
Created July 2, 2019 22:53
Show Gist options
  • Save tinchoabbate/14aa747aae7c3e18e17fabc1ee1af785 to your computer and use it in GitHub Desktop.
Save tinchoabbate/14aa747aae7c3e18e17fabc1ee1af785 to your computer and use it in GitHub Desktop.
Simple proxy contract
pragma solidity ^0.5.0;
contract Proxy {
address public proxyOwner;
address public implementation;
constructor(address implementation) public {
proxyOwner = msg.sender;
_setImplementation(implementation);
}
modifier onlyProxyOwner() {
require(msg.sender == proxyOwner);
_;
}
function upgrade(address implementation) external onlyProxyOwner {
_setImplementation(implementation);
}
function _setImplementation(address imp) private {
implementation = imp;
}
function () payable external {
address impl = implementation;
assembly {
calldatacopy(0, 0, calldatasize)
let result := delegatecall(gas, impl, 0, calldatasize, 0, 0)
returndatacopy(0, 0, returndatasize)
switch result
case 0 { revert(0, returndatasize) }
default { return(0, returndatasize) }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment