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

Consider adding _authorizeUpgrade to UpgradeableBeacon instead of using Ownable #5158

Open
fruiz08 opened this issue Aug 20, 2024 · 1 comment
Milestone

Comments

@fruiz08
Copy link

fruiz08 commented Aug 20, 2024

🧐 Motivation
We want a more flexible way to be able to make upgrades and at the same time, maintain consistency on the approach used on UUPS pattern

📝 Details

Now, we cannot inherit from UpgradeableBeacon.sol and override the upgradeTo function removing the OnlyOwner modifier beacause _setImplementation is a private function.

function upgradeTo(address newImplementation) public virtual onlyOwner {
        _setImplementation(newImplementation);
    }

    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert BeaconInvalidImplementation(newImplementation);
        }
        _implementation = newImplementation;
        emit Upgraded(newImplementation);
    }

Suggestion: Use the _authorizeUpgrade like UUPSUpgradeable.sol to override it with the protected method you want

function upgradeTo(address newImplementation) public virtual {
       _authorizeUpgrade(newImplementation);
       _setImplementation(newImplementation);
    }

function _authorizeUpgrade(address newImplementation) internal virtual;
@ernestognw
Copy link
Member

Hi @fruiz08,

Ownable also has an internal _checkOwner function that's also virtual. Overriding it has the same effect as overriding _authorizeUpgrade. Alternatively, you can set an AccessManager as the owner of the UpgradeableBeacon, so that it can handle roles and delays more dynamically for authorizing upgrades.

Still, I agree the UpgradeableBeacon should have an _authorizeUpgrade function instead.

@ernestognw ernestognw changed the title UpgradeableBeacon: use _authorizeUpgrade instead of onlyOwner Consider adding _authorizeUpgrade to UpgradeableBeacon instead of using Ownable Aug 20, 2024
@ernestognw ernestognw added this to the 5.x milestone Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants