feat(rbac): add role-based access control to TradeFlow contract#183
Open
Rocket1960 wants to merge 1 commit into
Open
feat(rbac): add role-based access control to TradeFlow contract#183Rocket1960 wants to merge 1 commit into
Rocket1960 wants to merge 1 commit into
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.