pragma solidity >=0.4.22 <0.6.0; // Machine.sol /// @title A widget contract Machine { // This is our contract that does stuff. We'll be committing to deploying this contract in the future. // At this point, this only exists to be compiled for our init code constructor() public { // etc } function legit() public view returns(address) { return address(this); } } // init_code: // 0x608060405234801561001057600080fd5b5060cc8061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806331cb3e48146044575b600080fd5b348015604f57600080fd5b5060566098565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6000309050905600a165627a7a72305820b5da6748da14469d9ab06edb0aae0afcfa83c840ab2c3f3cf8ef4bbb8376e02d0029 // code hash: // 0x974da18f7b7c5b584a422ae1dbb06c643ab2705d0fdd2c88206076bc699e2bb6 // Deployer.sol /// @title A generic code deployer contract Deployer { // emits this any time a contract is created event NewContract(address addr); function deploy(bytes code) public returns(address) { address newContract; assembly { newContract := create(0, add(code, 0x20), mload(code)) let codeSize := extcodesize(newContract) if eq(codeSize, 0) { revert(0, 0) } } emit NewContract(newContract); return newContract; } function codeHash(bytes code) public pure returns (bytes32) { return keccak256(code); } } // MachineCommitment.sol /// @title A commitment to make a widget contract MachineCommitment { bytes4 constant _methodSig = bytes4(keccak256("deploy(bytes)")); address deployer; bytes32 codeHash; constructor(address _deployer, bytes32 _codeHash) public { codeHash = _codeHash; deployer = _deployer; } function commit(bytes code) public { // require that this be the committed code. require(keccak256(code) == codeHash); require(deployer.delegatecall(_methodSig, abi.encode(code))); selfdestruct(msg.sender); } }
0.4.22