EIP-7997: Deterministic Factory Predeploy

Btw there’s a big limitation of a simple CREATE2 Factory, the Constructor Arguments and Creation Code are mixed together in the same blob, as result is not possible to initialize immutables because altering the constructors parameters also changes the final contract address, this limitation also lead to CREATE3 proposal. Whoever the same Creation Code can generate a completely different Runtime Code when the contract constructor uses the current chain-state like ORIGIN, BLOCK_NUMBER or calls another contract.

In 2024 I faced this issue, I had to deploy the same contract at the same address in different networks, while initializing different IDs as solidity immutable. None of the existing factories I tested solved this issue so I had to solve it myself implementing the Universal Factory. This factory temporarly store the arguments locally and make it available to the contract constructor, it also handles Atomic Proxy Contract initialization. Was very tricky to implement because the same bytecode must work cross-chain, the difference in gas cost between TSTORE and SSTORE was significant but EIP-1153 isn’t universaly supported, to get the same bytecode working in all EVM chains I had to implement some forbidden magic to detect EIP-1153 support.

I think is important for a factory provide a way to decouple the arguments from the bytecode, because storing arguments locally is the only way I know around this issue, and it adds a lot of unecessary gas overhead.

1 Like