Created
August 27, 2023 01:50
-
-
Save thurendous/5bc89ca471022d4df990c281c775d16c to your computer and use it in GitHub Desktop.
try to create a contract in byte code
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
// MIT | |
pragma solidity ^0.8.13; | |
// Runtime code | |
// Creation code | |
// Factory code | |
contract Factory { | |
event Log(address addr); | |
function deploy() external { | |
bytes memory bytecode = hex"69602a60005260206000f3600052600a6016f3"; | |
address addr; | |
assembly { | |
addr := create(0, add(bytecode, 0x20), 0x13) | |
} | |
require(addr != address(0), "deploy failed"); | |
emit Log(addr); | |
} | |
} | |
interface IContract { | |
function getMeaningOfLif2e() external view returns (uint); | |
} | |
/* | |
return(p, s) - end execution and return data from memory p to p + s | |
mstore(p, v) - store v at memory p to p + 32 | |
PUSH1 0x2a | |
PUSH1 0 | |
MSTORE | |
Return 32 bytes from memory | |
PUSH 0x20 | |
PUSH1 0 | |
RETURN | |
Run time code - return 42 | |
602a60005260206000f3 | |
Creation code | |
Store run time code to memory | |
602a60005260206000f3 | |
PUSH10 602a60005260206000f3 | |
PUSH1 0 | |
MSTORE | |
0x000000....00000602a60005260206000f3 | |
Return 10 bytes from memory starting at offset 22 | |
PUSH 0x0a | |
PUSH1 0x16 (22) | |
RETURN | |
69602a6000526020 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment