Skip to content

Instantly share code, notes, and snippets.

@XertroV

XertroV/ctfHelpers.sol

Last active Jun 17, 2018
Embed
What would you like to do?
Eth CTF Helpers
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