Skip to content

Instantly share code, notes, and snippets.

@chriseth
Created January 24, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseth/fa38cb97d1986a89e540020946939c1f to your computer and use it in GitHub Desktop.
Save chriseth/fa38cb97d1986a89e540020946939c1f to your computer and use it in GitHub Desktop.
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