Skip to content

feat(rbac): add role-based access control to TradeFlow contract#183

Open
Rocket1960 wants to merge 1 commit into
BETAIL-BOYS:mainfrom
Rocket1960:feat/rbac-access-control
Open

feat(rbac): add role-based access control to TradeFlow contract#183
Rocket1960 wants to merge 1 commit into
BETAIL-BOYS:mainfrom
Rocket1960:feat/rbac-access-control

Conversation

@Rocket1960

Copy link
Copy Markdown

closes issue #170
The RBAC implementation for TradeFlow-Core is complete. All 17 tests pass. Here's what was delivered:

rbac.rs — Core module:

Role hashes as BytesN<32> (SHA-256 of role name string)
has_role, require_role, grant_role_unchecked, revoke_role_unchecked
TTL management: 30-day threshold → extends to 100 days
Events emitted on grant/revoke
lib.rs changes:

init() bootstraps DEFAULT_ADMIN_ROLE for the initial admin
DataKey extended with PendingFeeChange (fixes pre-existing key collision in fee proposals) and Role(Address, BytesN<32>)
Protected functions now take caller: Address + enforce role via require_role:
propose_fee_change / execute_fee_change → FEE_MANAGER_ROLE
upgrade_contract / emergency_upgrade → DEFAULT_ADMIN_ROLE
set_fee_recipient → FEE_MANAGER_ROLE
toggle_pool_status → PAUSER_ROLE
Public API: grant_role, revoke_role, renounce_role, has_role, role_*() getters
rbac_tests.rs — 10 tests covering grant/revoke/renounce, unauthorized access panics, role-gated functions, deterministic role hash constants.

- Add rbac.rs module: BytesN<32> role hashes (SHA-256 of role name),
  has_role / require_role / grant_role_unchecked / revoke_role_unchecked,
  TTL management for instance storage (~30 day threshold / ~100 day extend).
- Four built-in roles: DEFAULT_ADMIN_ROLE, FEE_MANAGER_ROLE, PAUSER_ROLE,
  KYC_MANAGER_ROLE exposed via role_* getter functions.
- Wire RBAC into protected functions: propose_fee_change / execute_fee_change
  (FEE_MANAGER_ROLE), upgrade_contract / emergency_upgrade (DEFAULT_ADMIN_ROLE),
  set_fee_recipient (FEE_MANAGER_ROLE), toggle_pool_status (PAUSER_ROLE).
- init() now bootstraps DEFAULT_ADMIN_ROLE for the initial admin address.
- Public API: grant_role, revoke_role, renounce_role, has_role.
- DataKey extended with PendingFeeChange and Role(Address, BytesN<32>) variants.
- 10 RBAC-focused unit tests in rbac_tests.rs; all 17 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant