Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning the ownership in the constructor creates issues for factory patterns #2402

Closed
thegostep opened this issue Nov 9, 2020 · 4 comments
Labels
breaking change Changes that break backwards compatibility of the public API.

Comments

@thegostep
Copy link

thegostep commented Nov 9, 2020

This creates additional 5k deployment cost to update the ownership as a part of the deployment. I recommend using an initializer function which accepts an arbitrary address as the owner.

constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}

@frangio
Copy link
Contributor

frangio commented Nov 12, 2020

I agree that using msg.sender in the constructor was a mistake. As far as I can tell there is nothing we can do in a backwards compatible way, unless Solidity supports optional arguments at some point.

@Amxx
Copy link
Collaborator

Amxx commented Jan 8, 2021

That is not exactly what you are asking for, but if you plan to have your contract inherit from Ownable AND have an initializer, maybe the initializer could use the internal function proposed in #2464

@thegostep
Copy link
Author

Nice - that's also a much needed improvement but I would still request removing setting ownership in the constructor

@frangio frangio added the breaking change Changes that break backwards compatibility of the public API. label Feb 8, 2021
@frangio
Copy link
Contributor

frangio commented Feb 17, 2021

We've come to the following conclusion. We would have slightly preferred to have had the owner constructor argument since the beginning, but at this point we don't want to make the breaking change in the existing contracts.

FWIW, the upcoming storage cost changes in the Berlin hard fork, if I'm reading them correctly, seem to drastically reduce the cost of the extra SSTORE caused by having to use an internal setter in the constructor body after the default value of msg.sender has already been set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Changes that break backwards compatibility of the public API.
Projects
None yet
Development

No branches or pull requests

3 participants