web3 icon indicating copy to clipboard operation
web3 copied to clipboard

Setting an owner on upgradeable contracts without being able to call constructor

Open treeder opened this issue 5 years ago • 10 comments

If the contract requires an owner, how can you securely set it to the deployers address when using upgradeable contracts? cc @benbjohnson

treeder avatar Aug 22 '19 14:08 treeder

IIRC, it sets the owner to the msg.sender when it gets created.

benbjohnson avatar Aug 22 '19 14:08 benbjohnson

@treeder The proxy constructor does run: https://github.com/gochain/web3/blob/master/assets/OwnerUpgradeableProxy.sol#L16

jmank88 avatar Aug 22 '19 14:08 jmank88

I mean the constructor of the underlying contract, that doesn't run right? (or if it does, the docs are wrong).

treeder avatar Aug 22 '19 14:08 treeder

AFAIK that is correct. Perhaps the contract would need to reference the proxy owner via keccak256("gochain.proxy.owner") to bootstrap its own owner, or to just use directly instead.

jmank88 avatar Aug 22 '19 14:08 jmank88

Maybe we should have the proxy call an init() function (if it exists), that can be used as a constructor. Otherwise, it seems to me that you'd have to deploy, then call functions a constructor would do, such as call setOwner. And that setOwner to be secure would have to have a defense in like if owner == address(0x0) then allow it so it can only be called once.

treeder avatar Aug 22 '19 16:08 treeder

cc @brockmcblockchain

treeder avatar Aug 22 '19 16:08 treeder

An generalized init() solution might be possible, but if the only concern is managing an owner, then the target contract can reference the owner from the proxy contract with keccak256("gochain.proxy.owner") because they share the same state.

jmank88 avatar Aug 22 '19 16:08 jmank88

It's not just owner, it's anything you'd put in a constructor. That's just a common one.

treeder avatar Aug 22 '19 16:08 treeder

Alternatively, can we figure out a way to call the constructor?

treeder avatar Aug 22 '19 16:08 treeder

AFAIK running the constructor of the target contract against the state of the proxy contract is not possible. It does run when the target is deployed, but against its own state, not the proxy state.

jmank88 avatar Aug 22 '19 16:08 jmank88