-
Couldn't load subscription status.
- Fork 179
Description
Currently, for transactions such as these (example https://specs.optimism.io/protocol/isthmus/derivation.html#l1block-deployment) we choose the from address to be a unique account which has nonce=0. The choice of from affects the deployment address of the contract. Using a fresh account means we can safely set nonce:0 in the upgrade transaction.
That unique account tends to be chosen in the 0x421... namespace. Choosing it correctly involves checking the entire spec history to ensure we aren't reusing an address. This is error prone, particularly when forks get reordered.
A better pattern is
take the first 20 bytes of the source hash as sender address. That way you have a guaranteed unique deployer address, and thus nonce 0, and thus a unique and deterministic deployed contract address. Without making it coupled to bytecode, so the proxy upgrade tx input stays stable on dev changes
h/t to @protolambda for this idea.
The source hash is defined here https://specs.optimism.io/protocol/deposits.html#source-hash-computation
Note: the idea of using a CREATE2 type deployment was considered, but discarded in favour of the above approach (in particular it would couple the deployment address and tx input to the contract bytecode, which is undesirable).