Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions contracts/src/access/AccessControl.compact
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ pragma language_version >= 0.21.0;
* {revokeRole} circuits. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE` (zero bytes), which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}. To set a custom `DEFAULT_ADMIN_ROLE`, implement the `Initializable`
* module and set `DEFAULT_ADMIN_ROLE` in the `initialize()` circuit.
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
Expand Down Expand Up @@ -93,7 +92,15 @@ module AccessControl {
 */
export ledger _adminRoles: Map<Bytes<32>, Bytes<32>>;

export ledger DEFAULT_ADMIN_ROLE: Bytes<32>;
/**
* @description The default admin role for all roles. Only accounts with this role will be able
* to grant or revoke other roles unless custom admin roles are created via {_setRoleAdmin}.
*
* @return {Bytes<32>} - The default admin role identifier (zero bytes).
*/
export pure circuit DEFAULT_ADMIN_ROLE(): Bytes<32> {
return default<Bytes<32>>;
}

/**
* @description Returns `true` if `account` has been granted `roleId`.
Expand Down Expand Up @@ -167,7 +174,7 @@ module AccessControl {
if (_adminRoles.member(disclose(roleId))) {
return _adminRoles.lookup(disclose(roleId));
}
return default<Bytes<32>>;
return DEFAULT_ADMIN_ROLE();
}

/**
Expand Down
6 changes: 5 additions & 1 deletion contracts/src/access/test/mocks/MockAccessControl.compact
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import CompactStandardLibrary;

import "../../AccessControl" prefix AccessControl_;

export { ZswapCoinPublicKey, ContractAddress, Either, Maybe, AccessControl_DEFAULT_ADMIN_ROLE };
export { ZswapCoinPublicKey, ContractAddress, Either, Maybe };

export pure circuit DEFAULT_ADMIN_ROLE(): Bytes<32> {
return AccessControl_DEFAULT_ADMIN_ROLE();
}

export circuit hasRole(roleId: Bytes<32>, account: Either<ZswapCoinPublicKey, ContractAddress>): Boolean {
return AccessControl_hasRole(roleId, account);
Expand Down
Loading