1

I have a factory contract, which creates child contracts. The child contract inherits from OpenZeppelin's Ownable, so it has an owner and a transferOwnership method.

The factory contract uses CREATE2 to deploy the child contract, and is passing the owner's address as the 32 bytes salt:

bytes32 salt = keccak256(abi.encode(owner));
assembly {
  proxy := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
}

The issue I ran into is that when the owner calls the transferOwnerwship method, the factory contract cannot deploy another child contract for that owner. That's because CREATE2 does not allow overwriting a contract deployed with a specific salt.

The question is: is it possible to use the owner as the salt, at all? I thought about forking Ownable and deleting the transferOwnership method, yet I'd prefer to keep that if I can.

Is there some cryptographic hack that I could employ?

1 Answer 1

2

Don't think so mate, I don't understand your question really; if you are going to use the same salt and same master copy (clone bytecode) the factory contract will never be able to deploy more than one contract (what's the point of using a factory then). So transferOwnership is actually your only way to change owner and hence deploy new contracts.

I suggest you pass the salt as a function parameter, be it random, incremental or whatever uint value u chose. Also it will be cheaper than hashing the owner.

1
  • Yeah I ended up making the salt incremental and using tx.origin to prevent front-running. Commented Sep 29, 2022 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.