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

Change the new operator to use CREATE2 #2136

Open
chriseth opened this Issue Apr 20, 2017 · 9 comments

Comments

5 participants
@chriseth
Copy link
Contributor

chriseth commented Apr 20, 2017

This might require keeping a nonce or other measure to make the creation bytecode unique if new is used multpile times on the same contract.

See https://eips.ethereum.org/EIPS/eip-1014

@chriseth chriseth added the accepted label Apr 20, 2017

@VoR0220

This comment has been minimized.

Copy link
Contributor

VoR0220 commented Apr 20, 2017

Can you elaborate on this?

@axic axic changed the title Change the new operator to use CREATE_P2SH Change the new operator to use CREATE2 Apr 28, 2017

@axic axic added the feature label Sep 18, 2017

@axic axic added this to Inbox in Backlog (non-breaking) via automation Aug 1, 2018

@axic axic removed the accepted label Aug 1, 2018

@axic

This comment has been minimized.

Copy link
Member

axic commented Aug 1, 2018

Would that counter be shared across the contract for all creates, specific to the create in a certain code location or specific to creating a specific contract?

@AlexeyAkhunov

This comment has been minimized.

Copy link

AlexeyAkhunov commented Dec 6, 2018

I have written up this: https://ethereum-magicians.org/t/solidity-compiler-magicians-wanted-to-make-create2-usage-easier/2137

Yesterday I made this ERC20 contract (which is supposed to work under State rent when holders pay for storing their tokens): work: https://github.com/ledgerwatch/eth_state/blob/master/erc20/TokenContract.sol

As you can see in the code, Solidity provides create2 assembly function, but working with it is cumbersome. It would be much easier if there were 2 new features in Solidity:

  1. new2 operator. Similar to new, but also accept salt parameter, and uses CREARE opcode. So in my Factory I would have written Holder holder = new2(Holder, _owner) without having to put the byte code of the Holder contract inside the function
  2. Function create2_address, which allows computing address of CREATE2 contract. I would have used it twice, first in Token.getHolderContract function: address payable holder_address = create2_address(factory, a, Holder), and second in Holder.setOwner function: require(create2_address(factor, _owner, Holder) == address(this))

It would be great to have (at least in a branch) a version of Solidity (derived from the current) supporting these two things. That would make further development of contracts like that much easier.

@chriseth

This comment has been minimized.

Copy link
Contributor

chriseth commented Dec 6, 2018

The new2 function you suggest could be rather tricky to implement. What might be easier and could be almost as helpful to you would be something like Holder.creationCode and Holder.runtimeCode - read-only properties of type bytes memory. What do you think?

@AlexeyAkhunov

This comment has been minimized.

Copy link

AlexeyAkhunov commented Dec 6, 2018

What might be easier and could be almost as helpful to you would be something like Holder.creationCode and Holder.runtimeCode - read-only properties of type bytes memory. What do you think?

Yes, that would definitely be helpful. And also the code hash, of course, because it can be computed at compile time

@chriseth

This comment has been minimized.

Copy link
Contributor

chriseth commented Dec 13, 2018

The optimizer might take care of improving the hash computation, let's see.

@chriseth chriseth changed the title Change the new operator to use CREATE2 Provide access to a contract's creation and runtime code Dec 13, 2018

@chriseth chriseth changed the title Provide access to a contract's creation and runtime code Change the new operator to use CREATE2 Dec 13, 2018

@chriseth

This comment has been minimized.

Copy link
Contributor

chriseth commented Dec 13, 2018

Created an issue #5647

@jochem-brouwer

This comment has been minimized.

Copy link

jochem-brouwer commented Jan 7, 2019

@chriseth Your bytes memory Holder.runtimeCode sounds dangerous. It is possible to create contracts which dump different runtime code than what you might expect. This involves using the return opcode in the constructor via assembly by hence pushing different bytes to the deployed code than what solidity expects it will deploy.

@chriseth

This comment has been minimized.

Copy link
Contributor

chriseth commented Jan 7, 2019

Let's not discuss in two different issues -> #5647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment