Skip to main content

AccessControlTemporalFacet

Grants and revokes roles with expiry timestamps

Key Features
  • Manages roles with specific expiry timestamps.
  • Integrates seamlessly with the diamond proxy pattern.
  • Exposes external functions for temporal role management.
  • Utilizes Compose's internal storage access patterns.

Overview

This facet implements temporal role-based access control within a diamond. It provides functions to grant roles with specific expiry dates and to revoke them. Calls are routed through the diamond proxy, allowing for dynamic access management integrated with other diamond functionalities. Developers add this facet to enable time-limited permissions for accounts.


Storage

AccessControlStorage

Definition
struct AccessControlStorage {
mapping(address account => mapping(bytes32 role => bool hasRole)) hasRole;
mapping(bytes32 role => bytes32 adminRole) adminRole;
}

AccessControlTemporalStorage

Definition
struct AccessControlTemporalStorage {
mapping(address account => mapping(bytes32 role => uint256 expiryTimestamp)) roleExpiry;
}

State Variables

PropertyTypeDescription
ACCESS_CONTROL_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol"))
TEMPORAL_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol.temporal"))

Functions

getRoleExpiry

Returns the expiry timestamp for a role assignment.

function getRoleExpiry(bytes32 _role, address _account) external view returns (uint256);

Parameters:

PropertyTypeDescription
_rolebytes32The role to check.
_accountaddressThe account to check.

Returns:

PropertyTypeDescription
-uint256The expiry timestamp, or 0 if no expiry is set.

isRoleExpired

Checks if a role assignment has expired.

function isRoleExpired(bytes32 _role, address _account) external view returns (bool);

Parameters:

PropertyTypeDescription
_rolebytes32The role to check.
_accountaddressThe account to check.

Returns:

PropertyTypeDescription
-boolTrue if the role has expired or doesn't exist, false if still valid.

grantRoleWithExpiry

Grants a role to an account with an expiry timestamp. Only the admin of the role can grant it with expiry. Emits a RoleGrantedWithExpiry event. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.

function grantRoleWithExpiry(bytes32 _role, address _account, uint256 _expiresAt) external;

Parameters:

PropertyTypeDescription
_rolebytes32The role to grant.
_accountaddressThe account to grant the role to.
_expiresAtuint256The timestamp when the role should expire (must be in the future).

revokeTemporalRole

Revokes a temporal role from an account. Only the admin of the role can revoke it. Emits a TemporalRoleRevoked event. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.

function revokeTemporalRole(bytes32 _role, address _account) external;

Parameters:

PropertyTypeDescription
_rolebytes32The role to revoke.
_accountaddressThe account to revoke the role from.

requireValidRole

Checks if an account has a valid (non-expired) role. - Reverts with AccessControlUnauthorizedAccount If the account does not have the role. - Reverts with AccessControlRoleExpired If the role has expired.

function requireValidRole(bytes32 _role, address _account) external view;

Parameters:

PropertyTypeDescription
_rolebytes32The role to check.
_accountaddressThe account to check the role for.

Events

Errors

Best Practices

Best Practice
  • Initialize temporal roles using grantRoleWithExpiry during diamond setup or via authorized administrative functions.
  • Regularly check role expiry using isRoleExpired before executing sensitive operations.
  • Ensure that only authorized administrative facets can call grantRoleWithExpiry and revokeTemporalRole.

Security Considerations

Security

All state-changing functions (grantRoleWithExpiry, revokeTemporalRole) require the caller to be the admin of the respective role, enforced by AccessControlUnauthorizedAccount revert. The requireValidRole function checks for both role existence and expiry, reverting with AccessControlUnauthorizedAccount or AccessControlRoleExpired respectively. Input validation for expiry timestamps is crucial at the calling facet level.

Was this helpful?
Last updated: