Last active
November 19, 2018 08:14
-
-
Save shingonu/37193174f94c5f2e9ba4e5762d953015 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
| // handle access control/permission | |
| contract ProxyStorage { | |
| address public implementation; | |
| } | |
| contract Proxy is ProxyStorage { | |
| constructor(address _impl) public { | |
| // check that its valid before setting the address | |
| implementation = _impl; | |
| } | |
| function setImplementation(address _impl) public { | |
| implementation = _impl; | |
| } | |
| function () public { | |
| address localImpl = implementation; | |
| //solium-disable-next-line security/no-inline-assembly | |
| 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 { | |
| uint256 public score; | |
| } | |
| contract Score is ProxyStorage, ScoreStorage { | |
| function setScore(uint256 _score) public { | |
| score = _score; | |
| } | |
| } | |
| // V2 (proper) | |
| contract ScoreV2 is ProxyStorage, ScoreStorage { | |
| function setScore(uint256 _score) public { | |
| score = _score + 1; | |
| } | |
| } | |
| // V3 (not proper) | |
| contract ScoreStorage { | |
| address lastPersonToSetTheScore; // overwrite 'score' variable storage slot | |
| } | |
| contract ScoreV3 is ProxyStorage, ScoreStorage { | |
| function setScore() public { | |
| lastPersonToSetTheScore = msg.sender; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment