Solidity (compiler) magicians wanted to make CREATE2 usage easier

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.

EDIT: Also linked this to: https://github.com/ethereum/solidity/issues/2136

2 Likes

Check this out! Should at least make your life a little bit easier! :smiley: (It is a contract exposing all functions as public but it can of course be rewritten as a library/contract where all functions are internal/private)

1 Like

Thank you very much! Not exactly what I wanted, but a good start! :slight_smile:

Recently I also needed to implement the same thing
You can preserve a bit more of the new semantics by doing: new(salt) C(args...) that will create the contract C using args as arguments with create2.
The address could be accessed with C.create2Address(salt)