ERC-2470: Singleton Factory

I submitted a fix to the eth_estimateGas on go-ethereum https://github.com/ethereum/go-ethereum/pull/21751

@rmeissner so this is what you suggest?

contract ERC2470 {

    fallback() external payable {
        deploy(msg.data, 0);
    }

    function deploy(bytes memory _initCode, bytes32 _salt)
        public
        payable
        returns (address payable createdContract)
    {
        assembly {
            createdContract := create2(callvalue(), add(_initCode, 0x20), mload(_initCode), _salt)
        }
        require(createdContract != address(0), "ERC2470: CREATE2 failed");
    }

}

Anything else you want to add?

This seems wrong, because with “payable” creations some contracts might deploy something different, however this can already be achieved by using other transaction parameters like gas limit or gas price.

So I might allow this and just add to security considerations that when a contract accepts value at creation, it should also work when msg.value is zero, or execute the same procedure regardless of value in constructor.

1 Like

So, the 100 gas bid for this contract feels “high”, but in practice isn’t high enough :(. In fact, it is below the minimum gas bid for Avalanche, and so this contract cannot be deployed to their C-chain at all. It is sadly too late to fix this EIP over this, but I’m going to assert the bid should have been 500, with the argument that geth actually used to (and sort of still does?) have a maximum gas suggestion limit of 500, which makes this that schilling point for “a lot of gas”.

(This also happens to be greater than the weirdly-hardcoded gas limit on Avalanche C-chain, which is 470. FWIW, I do not consider Avalanche’s design here reasonable, and have an issue filed at https://github.com/ava-labs/coreth/issues/40; but, even so, I am still sad that EIP2470 went with what feels like an arbitrary 100 instead of seeing the existing 500 limit, particularly as the gas bid on Ethereum itself was up towards 500 for quite a bit of time this year.)

What I’m currently intending to do is to deploy a variant of EIP2470 to all of the chains I’m working with that uses the exact same transaction as the one in EIP2470 but with 500 instead of 100 as the gas bid (as I figure that that is the schilling point for such a contract, given the further existence of EIP2470; this is of course throwing away the 00s optimization, but it isn’t even clear to me what that was gaining us, as the non-0s in that address don’t cost anything, right?).

That said, I actually ended up coming to this thread because of a link I found in that issue that was filed about gas cost estimation, so I’m guessing that I should probably deploy that deterministic-deployment-proxy project instead, if it is in fact fixing that issue. (Sadly, I see it is also using 100 Gwei. Is there something I’m missing for why 100 Gwei is considered firmly “enough a-lot-of-gas that the idea that a currency would need more would be preposterous”?)

What we should have used? gasPrice at 1000 Gwei?

In ETH chain, currently there are times where you could deploy it.

The reason 100 was choosen is because 1820 used it, and 1820 probably choosed it because the normal gas prices at that time were like 10gwei.

What we should have used? gasPrice at 1000 Gwei?

I made an explicit argument–seemingly ignored ;P–that the schelling point (which to me is a very useful way of analyzing this question) is “500 Gwei” due to what as-far-as-I-know continues to be a soft cap (and which certainly used to be a pretty hard cap) in geth at that value (and, in the few months since my writing that, I’ve only become more convinced of this based on actually seeing the weird behavior that happens as the network pushes up towards 500 Gwei).

Do you have any idea on how to let this fee open?

I can update the EIP to use 500 gwei for the final interation, but I am not sure if there wont be another new chain or new situation where 500 gwei wont work :confused:

Do you have any idea on how to let this fee open?

FWIW, I (at least) don’t: techniques surrounding hacks on top of CREATE and CREATE2 seem to fundamentally require predicting the future, as the gas bid has to be signed. I don’t think this is quite “hopeless” to do “pretty well”, as if the price of gas is going up typically the price of the coin will go up as well, seeing that the primarily utility of the coin is to pay for gas; and I think that the common standard of 10^18 decimals combined with psychological price points surrounding new coin launches caps the low end of gas fees somewhat.

But it is of course still easy to come up with mechanisms and scenarios where any “reasonable price”–which is maybe at least vaguely important to consider: Orchid paid thousands of dollars to deploy the aforementioned Gnosis contract on RSK, as the coin on their chain is Bitcoin, now at ~$50k (so, fwiw, if anyone wants to use a factory across a number of chains: I have one for you to use, and we will even help deploy it places)… but if it had been hundreds or even tens of thousands, we probably would not have ;P–is going to just not be workable.

I do have a suggestion, though! One might argue that, to the extent to which this is considered functionality the platform “should have”–and the existence of EIP-1820, which developers currently are unable to deploy on Avalanche, as even their “lower as of last week” minimum gas price of 225 nanoAVAX is too high, seems to argue for given that it is a dependency of other standards–the platform needs to provide a guaranteed way to do this: it should either be specified as a hardcoded address or as a new CREATE3 instruction.

In the world where this is CREATE3, it should be pretty clear how it would work… but it would now require getting implementation buy in from all of the chains to add it–and it is kind of feeling like the ship has sailed as of mid-2020: new feature are going to be hard to rely upon–but, in a world where it were a hardcoded address, then Nick’s method could merely be a fallback. Like, AFAIK nothing prevents there from being a special case on (for example) Avalanche to have this factory’s creation be either a one-off special case or even a built-in.

Hey @3esmit this EIP is quite interesting, any update to it, OR do you know of Singleton Factory that we can use today has been deployed across the majority of chains?

1 Like

There is one deficiency of this EIP, and that it doesn’t revert on failure.
This means you can’t even estimate its gas usage.
It does use a standard ABI encoding, which makes it slightly easier to use from solidity than the deterministic deployment proxy.
Not sure that this makes it a better candidate to be a standard, though.

Axelar’s CREATE2 factory has similiar code and has reverts: axelar-gmp-sdk-solidity/contracts/deploy/ConstAddressDeployer.sol at main · axelarnetwork/axelar-gmp-sdk-solidity · GitHub

They’ve deployed it to a number of blockchains. Here’s their guide: Axelar Documentation

These days I find the “CREATE3” method much more interesting, as contract bytecode is not used to calculate the address.

It would be great if both methods were part of Ethereum, so that we wouldn’t have to do the keyless deployment of the factory contract on multiple blockchains. Keyless deployment is best practice but now getting more difficult due to chainId enforcement by nodes.

We really need a solution to EIP-155 enforcement.

hey 3esmit! i’m taking a close look at AA and see that originally there was a relatively high probability of using this eip to implement a standard account creation factory compatible with other eips like 4337. would love to learn more about how those convos progressed and ultimately why the outcome was moving this proposal to stagnant. lmk how might be best to chat.

Yes, non-EIP155 deployment is tricky on new networks, but I think that adding a new opcode (or precompile) for that purpose is an overkill: it is much simpler to do a “nonstandard state change” for those networks and deploy the deterministic deployer…
(actually, this is exactly what “Base” did, and I think other networks too, to have the deployer available)