Last active
June 17, 2018 02:38
-
-
Save XertroV/81f0f2f6a88d4664cb4d8172cb456ae6 to your computer and use it in GitHub Desktop.
Eth CTF Helpers
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.4.24; | |
contract _useful { | |
mapping (address => bool) public owners; | |
address[] deployed; | |
event Deployed(address d); | |
event SD(); | |
modifier oo { | |
require(owners[msg.sender]); | |
_; | |
} | |
constructor() public payable { | |
owners[msg.sender] = true; | |
} | |
function() payable public {} | |
function addOwner(address o) external oo { | |
owners[o] = true; | |
} | |
function deploy(bytes _code) public oo returns (address d) { | |
assembly { | |
d := create(0, add(_code, 0x20), mload(_code)) | |
if iszero(extcodesize(d)) { revert(0x00, 0x00) } | |
} | |
// bytes4 addOwnerSig = mkSig("addOwner(address)"); | |
// let's only deploy _useful contracts | |
_useful(d).addOwner(msg.sender); | |
deployed.push(d); | |
emit Deployed(d); | |
} | |
function destroy() external oo { | |
bytes4 dSig = mkSig("destroy()"); | |
for (uint i = 0; i < deployed.length; i++) { | |
deployed[i].call(dSig); | |
} | |
sd(); | |
} | |
function sd() public oo { | |
emit SD(); | |
selfdestruct(msg.sender); | |
} | |
function mkSig(string s) internal returns (bytes4) { | |
return bytes4(keccak256(abi.encodePacked(s))); | |
} | |
function amIOwner() external view returns (bool) { | |
return owners[msg.sender]; | |
} | |
} | |
contract Root is _useful { | |
function deployForBaseGame(address baseGame, bytes _code) external oo returns (address) { | |
address d = deploy(_code); | |
BaseGame(baseGame).addAuthorizedWallet(d); | |
} | |
} | |
contract BaseGame{ | |
uint256 public contractBalance; | |
function addAuthorizedWallet(address _wallet) external; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment