Access Control Admin Module
Provides internal functions for managing role administrators within a diamond.
Key Features
- Internal functions for role administration.
- Uses the diamond storage pattern for shared state.
- Guards updates by checking caller has the role's current admin role.
- Emits
RoleAdminChangedon successful admin updates.
Initialization Requirement
setRoleAdmin reads adminRole[_role] before writing the new value.
If no admin role has been configured yet, that value is bytes32(0), so the caller must already hold role bytes32(0).
Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
Access Control Storage
Functions
getStorage
Returns the storage for the AccessControl.
Returns:
| Property | Type | Description |
|---|---|---|
s | AccessControlStorage | The storage for the AccessControl. |
setRoleAdmin
Updates the admin role for _role. Emits RoleAdminChanged.
Authorization flow:
- Require caller has the previous admin role over the
_role - Update the admin role
- Emit
RoleAdminChanged(_role, previousAdminRole, _adminRole)
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to set the admin for. |
_adminRole | bytes32 | The new admin role to set. |
Events
Errors
Best Practices
- Bootstrap initial role/admin assignments during initialization so authorized accounts can pass the first checks.
- Treat
bytes32(0)as a privileged role in your access model when relying on default admin mappings. - For admin rotation: grant new admin role first, then call
setRoleAdmin, then revoke the old admin role. - Keep
AccessControlStoragelayout compatible across upgrades (erc8042:compose.accesscontrol).
Was this helpful?
Last updated: