Skip to content

Create2 improvements #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nventuro opened this issue Mar 2, 2020 · 7 comments · Fixed by #2117
Closed

Create2 improvements #2106

nventuro opened this issue Mar 2, 2020 · 7 comments · Fixed by #2117
Milestone

Comments

@nventuro
Copy link
Contributor

nventuro commented Mar 2, 2020

Motivated by @MicahZoltu's comments on the forum:

  • Consider adding support for including value in the create2 call.
  • Consider require(bytecode.length > 0, "useful error message") rather than just letting the creation fail with 0 bytes and a non-helpful message.
@nventuro nventuro added this to the v3.0 milestone Mar 2, 2020
@corydickson
Copy link
Contributor

By adding support for including value do you mean to make deploy a payable function where msg.sender deposits funds into the contract address generated?

@nventuro
Copy link
Contributor Author

I'm actually not sure, from the EIP it doesn't look like its possible to include value in the contract construction. It could certainly be sent after the fact, but I wouldn't add a new function just for that.

@MicahZoltu perhaps you could clarify your request?

@corydickson
Copy link
Contributor

That would make a lot more sense as it answers my followup Q of how would that be done!

@MicahZoltu
Copy link
Contributor

MicahZoltu commented Mar 13, 2020

From the CREATE2 EIP:

Behaves identically to CREATE, except using keccak256( 0xff ++ address ++ salt ++ keccak256(init_code))[12:] instead of the usual sender-and-nonce-hash as the address where the contract is initialized at.

Solidity inline assembly for create/create2 from Solidity docs:

instruction explanation
create(v, p, n) create new contract with code mem[p…(p+n)) and send v wei and return the new address
create2(v, p, n, s) create new contract with code mem[p…(p+n)) at address keccak256(0xff . this . s . keccak256(mem[p…(p+n))) and send v wei and return the new address, where 0xff is a 1 byte value, this is the current contract’s address as a 20 byte value and s is a big-endian 256-bit value

Note that v is value to be sent to the newly constructed contract as part of the constructor call. I am pretty sure (though someone should verify) that this means that the constructor will have msg.value set. Someone should verify that the constructor has access to the ETH, and it isn't actually sent to the contract first.

@MicahZoltu
Copy link
Contributor

@corydickson
Copy link
Contributor

@MicahZoltu Thank you for documenting it further here

@nventuro
Copy link
Contributor Author

Ah silly me, I should've paid more attention. That parameter is even present (and hard-coded to 0) in our current implementation. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants