Created
January 24, 2019 11:27
-
-
Save chriseth/fa38cb97d1986a89e540020946939c1f 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
uint salt = 0x123; | |
bool success; | |
// order matters! | |
bytes memory p = abi.encode(param1, ..., paramn); | |
bytes memory c = type(C).creationCode; | |
assembly { | |
function memCopyPadded(from, to, length) { | |
for { let i := 0 } lt(i, length) { i := add(i, 0x20) } { | |
mstore(to, mload(from)) | |
to := add(to, 0x20) | |
from := add(from, 0x20) | |
} | |
} | |
let codeLen := mload(c) | |
let paramLen := mload(p) | |
memCopyPadded(add(p, 0x20), add(add(c, 0x20), codeLen), paramlen) | |
success := create2(0, add(c, 0x20), add(codeLen, paramLen), salt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment