Created
June 29, 2018 15:03
-
-
Save wadealexc/b270d51f6db70ebf8f0661c24f6d379f 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.4.23; | |
contract SafeExecution { | |
address public owner; | |
modifier noOwner() { | |
require(owner == 0, 'level already completed'); | |
_; | |
} | |
bytes4 internal constant SET = bytes4(keccak256('Set(uint256)')); | |
function execute(address _target) public noOwner { | |
require(_target.delegatecall(abi.encodeWithSelector(this.execute.selector)) == false, 'unsafe execution'); | |
(bytes4 sel, uint val) = getRet(); | |
require(sel == SET); | |
function () func; | |
assembly { func := val } | |
func(); | |
} | |
function getRet() internal pure returns (bytes4 sel, uint val) { | |
assembly { | |
if iszero(eq(returndatasize, 0x24)) { revert(0, 0) } | |
let ptr := mload(0x40) | |
returndatacopy(ptr, 0, 0x24) | |
sel := and(mload(ptr), 0xffffffff00000000000000000000000000000000000000000000000000000000) | |
val := mload(add(0x04, ptr)) | |
} | |
} | |
function setOwnerExt() external { if (false) setOwner(); } | |
function setOwner() private { owner = msg.sender; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment