Does the upgradeable deployment call initialize function in a separate or single transaction?

With OpenZeppelin's upgradeable deployProxy for deploying of proxy contracts, are calls to the initialize() function called as a separately transactions (ie, contract creation and calling initialize are 2 separate transactions) or called internally within a single transaction (ie, both contract creation and initialize are called together in a single transaction, like something could be done by having both actions in a create function of a factory contract)?

If it the contract creation and initialize function were done as 2 separate transactions, wouldn't the calling of initialize() risk getting front-run? Sure, it probably isn't a big deal since the contract is brand new and the front runner isn't going to get much from it, but it means we wasted deploying that proxy contract too.

If the contract creation and initialize function were done together within one single transaction, how is this done in deployProxy() without going through a factory contract to create the contract and call initialize all in a single transaction?

Initialization happens at the same time the proxy is created. With deployProxy there is no risk of front-running.

1 Like

Thanks! I'm also curious, what about the minimal proxies since the bytecode is only taking the implementation address? Wouldn't the initialization will still need to be run separately?

Yes in the case of minimal proxies you need to run initialization "separately", but this doesn't necessarily mean in a separate transaction. You can write a factory contract that first deploys the minimal proxy and immediately after initializes it, all in the same transaction so it can't be frontrun.

1 Like