5.1 AccessManager / onlyAuthorized modifier

I have extended the 5.0 accessManager and want to set permissions on new functions to control with roles from the AccessManager itself.

I came up with the following modifer...

    modifier selfGuarded() {
        (bool canExecute, ) = canCall(_msgSender(), address(this), msg.sig);
        if (!canExecute) {
            revert AccessDeniedToSelfFunction(_msgSender(), msg.sig);
        }
        _;
    }

But I see now that the 5.1 contracts have an update to accessManager to ' Allow the onlyAuthorized modifier to restrict functions added to the manager.`'

Can onlyAuhorized functions be assigned to roles like how restricted functions can?

Hi @p0pps, sorry for the late response

The AccessManager has a different permission system for its functions. We did it in this way because we considered the permissions should be self-contained for the most sensitive functions (i.e. setTargetFunctionRole). An example of how it can go wrong is if the manager closes itself, effectively bricking the contract.

The modifier you came up will only guard new functions in the AccessManager, all the original admin functions will continue to follow the internal logic. Aside from that, I think it works fine. However, I'd recommend using the onlyAuthorized modifier if you're using OpenZeppelin Contracts >5.1x