Created
February 23, 2019 21:42
-
-
Save yakkomajuri/fc37dbb30ce8c7172883a7a6524e1b1b 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
pragma solidity^0.5.0; | |
contract Registry { | |
function getImplementation(address _user) public view returns (address) {} | |
} | |
contract ProxyStorage { | |
Registry registryAddress; | |
} | |
contract Proxy is ProxyStorage { | |
bytes32 private constant default_location = keccak256(abi.encodePacked("location")); | |
function initialize(address _registry) public { | |
bytes32 loc = default_location; | |
assembly { | |
sstore(loc, _registry) | |
} | |
} | |
function() external payable { | |
address registry; | |
bytes32 loc = default_location; | |
assembly { | |
registry := sload(loc) | |
} | |
registryAddress = Registry(registry); | |
address localImpl = registryAddress.getImplementation(msg.sender); | |
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) } | |
} | |
} | |
} | |
contract ScoreStorage { | |
uint public score; | |
} | |
contract Score is ProxyStorage, ScoreStorage { | |
function setScore(uint _score) public { | |
score = _score; | |
} | |
} | |
contract ScoreV2 is ProxyStorage, ScoreStorage { | |
function setScore(uint _score) public { | |
score = _score + 1; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment