Created
February 16, 2019 19:37
-
-
Save snario/1e1f99dc2fd5f163647c07d9fae49ccc 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.5; | |
/// @title Proxy - Generic proxy contract allows to execute all transactions applying the code of a master contract. | |
/// @author Stefan George - <[email protected]> | |
contract Proxy { | |
// masterCopy always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated. | |
address masterCopy; | |
/// @dev Constructor function sets address of master copy contract. | |
/// @param _masterCopy Master copy address. | |
constructor(address _masterCopy) | |
public | |
{ | |
require(_masterCopy != address(0), "Invalid master copy address provided"); | |
masterCopy = _masterCopy; | |
} | |
/// @dev Fallback function forwards all transactions and returns all received return data. | |
function () | |
external | |
payable | |
{ | |
// solium-disable-next-line security/no-inline-assembly | |
assembly { | |
let masterCopy := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff) | |
calldatacopy(0, 0, calldatasize()) | |
let success := delegatecall(gas, masterCopy, 0, calldatasize(), 0, 0) | |
returndatacopy(0, 0, returndatasize()) | |
if eq(success, 0) { revert(0, returndatasize()) } | |
return(0, returndatasize()) | |
} | |
} | |
function implementation() | |
public | |
view | |
returns (address) | |
{ | |
return masterCopy; | |
} | |
function proxyType() | |
public | |
pure | |
returns (uint256) | |
{ | |
return 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment