Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bea59cf
feat: add main logic
ericnordelo May 13, 2025
f3eeb97
fix: typo
ericnordelo May 13, 2025
72cad7a
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Jun 9, 2025
b922d6b
Update packages/access/src/accesscontrol/extensions/interface.cairo
ericnordelo Jun 9, 2025
f095a87
feat: apply review updates
ericnordelo Jun 9, 2025
031a491
feat: add store packing for pending delay
ericnordelo Jun 9, 2025
9fb4a71
feat: add access control tests to default admin rules
ericnordelo Jun 16, 2025
9b7eccd
Merge branch 'feat/add-default-admin-rules-ext-#1164' of github.com:e…
ericnordelo Jun 16, 2025
8a9141b
feat: add more tests
ericnordelo Jun 16, 2025
404373e
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Jun 24, 2025
72b82ff
docs: add DefaultAdminRules entries
ericnordelo Jun 24, 2025
65ffd7e
feat: update Changelog
ericnordelo Jun 24, 2025
4f44d07
Update packages/access/src/accesscontrol/extensions/accesscontrol_def…
ericnordelo Jul 1, 2025
0441da3
Update packages/access/src/accesscontrol/extensions/accesscontrol_def…
ericnordelo Jul 1, 2025
2019936
Update packages/access/src/accesscontrol/extensions/accesscontrol_def…
ericnordelo Jul 1, 2025
3fd44d9
Update packages/access/src/accesscontrol/extensions/accesscontrol_def…
ericnordelo Jul 1, 2025
7071f90
Update packages/access/src/accesscontrol/extensions/interface.cairo
ericnordelo Jul 1, 2025
f70af94
Update packages/access/src/accesscontrol/extensions/interface.cairo
ericnordelo Jul 1, 2025
8de7a7e
Update packages/access/src/accesscontrol/extensions/interface.cairo
ericnordelo Jul 1, 2025
dec146f
Update packages/access/src/accesscontrol/extensions/accesscontrol_def…
ericnordelo Jul 1, 2025
8e0f74c
Update docs/modules/ROOT/pages/api/access.adoc
ericnordelo Jul 1, 2025
05990d3
Update docs/modules/ROOT/pages/api/access.adoc
ericnordelo Jul 1, 2025
357b443
Update docs/modules/ROOT/pages/api/access.adoc
ericnordelo Jul 1, 2025
417ce9e
feat: apply review updates
ericnordelo Jul 1, 2025
1d7706c
Merge branch 'feat/add-default-admin-rules-ext-#1164' of github.com:e…
ericnordelo Jul 1, 2025
48b8c21
feat: format files
ericnordelo Jul 1, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- AccessControlDefaultAdminRules interface and component (#1432)

## 2.0.0 (2025-06-18)

### Added
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/ROOT/pages/access.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ security practice. Note that each account may still have more than one role, if

=== Granting and revoking roles

:access-control-default-admin-rules: xref:api/access.adoc#AccessControlDefaultAdminRulesComponent[AccessControlDefaultAdminRules]

The ERC20 token example above uses xref:api/access.adoc#AccessControlComponent-_grant_role[`_grant_role`],
an `internal` function that is useful when programmatically assigning
roles (such as during construction). But what if we later want to grant the 'minter' role to additional accounts?
Expand All @@ -378,6 +380,8 @@ of `0`, called `DEFAULT_ADMIN_ROLE`, which acts as the *default admin role for a
An account with this role will be able to manage any other role, unless
xref:api/access.adoc#AccessControlComponent-set_role_admin[`set_role_admin`] is used to select a new admin role.

Since it is the admin for all roles by default, and in fact it is also its own admin, this role carries significant risk. To mitigate this risk we provide {access-control-default-admin-rules}, a recommended extension of AccessControl that adds a number of enforced security measures for this role: the admin is restricted to a single account, with a 2-step transfer procedure with a delay in between steps.

Let's take a look at the ERC20 token example, this time taking advantage of the default admin role:

[,cairo]
Expand Down
910 changes: 908 additions & 2 deletions docs/modules/ROOT/pages/api/access.adoc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/access/src/accesscontrol.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod accesscontrol;
pub mod account_role_info;
pub mod extensions;
pub mod interface;

pub use accesscontrol::AccessControlComponent;
Expand Down
8 changes: 4 additions & 4 deletions packages/access/src/accesscontrol/accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ pub mod AccessControlComponent {
) -> bool {
match self.resolve_role_status(role, account) {
RoleStatus::Effective => true,
RoleStatus::Delayed => false,
RoleStatus::Delayed(_) => false,
RoleStatus::NotGranted => false,
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ pub mod AccessControlComponent {
) {
match self.resolve_role_status(role, account) {
RoleStatus::Effective => (),
RoleStatus::Delayed |
RoleStatus::Delayed(_) |
RoleStatus::NotGranted => {
let caller = starknet::get_caller_address();
let role_info = AccountRoleInfo { is_granted: true, effective_from: 0 };
Expand Down Expand Up @@ -386,7 +386,7 @@ pub mod AccessControlComponent {
assert(delay > 0, Errors::INVALID_DELAY);
match self.resolve_role_status(role, account) {
RoleStatus::Effective => panic_with_const_felt252::<Errors::ALREADY_EFFECTIVE>(),
RoleStatus::Delayed |
RoleStatus::Delayed(_) |
RoleStatus::NotGranted => {
let caller = starknet::get_caller_address();
let effective_from = starknet::get_block_timestamp() + delay;
Expand All @@ -408,7 +408,7 @@ pub mod AccessControlComponent {
match self.resolve_role_status(role, account) {
RoleStatus::NotGranted => (),
RoleStatus::Effective |
RoleStatus::Delayed => {
RoleStatus::Delayed(_) => {
let caller = starknet::get_caller_address();
let role_info = AccountRoleInfo { is_granted: false, effective_from: 0 };
self.AccessControl_role_member.write((role, account), role_info);
Expand Down
6 changes: 6 additions & 0 deletions packages/access/src/accesscontrol/extensions.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod accesscontrol_default_admin_rules;
pub mod interface;
pub mod pending_delay;

pub use accesscontrol_default_admin_rules::AccessControlDefaultAdminRulesComponent::DEFAULT_ADMIN_ROLE;
pub use accesscontrol_default_admin_rules::{AccessControlDefaultAdminRulesComponent, DefaultConfig};
Loading
Loading