@bloxchain/contracts 1.0.0-alpha.15 → 1.0.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1141,6 +1141,11 @@
1141
1141
  "name": "supportedActionsBitmap",
1142
1142
  "type": "uint16"
1143
1143
  },
1144
+ {
1145
+ "internalType": "bool",
1146
+ "name": "enforceHandlerRelations",
1147
+ "type": "bool"
1148
+ },
1144
1149
  {
1145
1150
  "internalType": "bool",
1146
1151
  "name": "isProtected",
@@ -349,6 +349,28 @@
349
349
  "name": "MetaTxExpired",
350
350
  "type": "error"
351
351
  },
352
+ {
353
+ "inputs": [
354
+ {
355
+ "internalType": "uint256",
356
+ "name": "txId",
357
+ "type": "uint256"
358
+ }
359
+ ],
360
+ "name": "MetaTxPaymentMismatchStoredTx",
361
+ "type": "error"
362
+ },
363
+ {
364
+ "inputs": [
365
+ {
366
+ "internalType": "uint256",
367
+ "name": "txId",
368
+ "type": "uint256"
369
+ }
370
+ ],
371
+ "name": "MetaTxRecordMismatchStoredTx",
372
+ "type": "error"
373
+ },
352
374
  {
353
375
  "inputs": [
354
376
  {
@@ -858,6 +858,11 @@
858
858
  "name": "supportedActionsBitmap",
859
859
  "type": "uint16"
860
860
  },
861
+ {
862
+ "internalType": "bool",
863
+ "name": "enforceHandlerRelations",
864
+ "type": "bool"
865
+ },
861
866
  {
862
867
  "internalType": "bool",
863
868
  "name": "isProtected",
@@ -160,6 +160,11 @@
160
160
  "name": "supportedActionsBitmap",
161
161
  "type": "uint16"
162
162
  },
163
+ {
164
+ "internalType": "bool",
165
+ "name": "enforceHandlerRelations",
166
+ "type": "bool"
167
+ },
163
168
  {
164
169
  "internalType": "bool",
165
170
  "name": "isProtected",
@@ -30,6 +30,11 @@
30
30
  "name": "supportedActionsBitmap",
31
31
  "type": "uint16"
32
32
  },
33
+ {
34
+ "internalType": "bool",
35
+ "name": "enforceHandlerRelations",
36
+ "type": "bool"
37
+ },
33
38
  {
34
39
  "internalType": "bool",
35
40
  "name": "isProtected",
@@ -858,6 +858,11 @@
858
858
  "name": "supportedActionsBitmap",
859
859
  "type": "uint16"
860
860
  },
861
+ {
862
+ "internalType": "bool",
863
+ "name": "enforceHandlerRelations",
864
+ "type": "bool"
865
+ },
861
866
  {
862
867
  "internalType": "bool",
863
868
  "name": "isProtected",
@@ -69,6 +69,11 @@
69
69
  "name": "supportedActionsBitmap",
70
70
  "type": "uint16"
71
71
  },
72
+ {
73
+ "internalType": "bool",
74
+ "name": "enforceHandlerRelations",
75
+ "type": "bool"
76
+ },
72
77
  {
73
78
  "internalType": "bool",
74
79
  "name": "isProtected",
@@ -884,6 +884,11 @@
884
884
  "name": "supportedActionsBitmap",
885
885
  "type": "uint16"
886
886
  },
887
+ {
888
+ "internalType": "bool",
889
+ "name": "enforceHandlerRelations",
890
+ "type": "bool"
891
+ },
887
892
  {
888
893
  "internalType": "bool",
889
894
  "name": "isProtected",
@@ -290,6 +290,11 @@
290
290
  "name": "supportedActionsBitmap",
291
291
  "type": "uint16"
292
292
  },
293
+ {
294
+ "internalType": "bool",
295
+ "name": "enforceHandlerRelations",
296
+ "type": "bool"
297
+ },
293
298
  {
294
299
  "internalType": "bool",
295
300
  "name": "isProtected",
@@ -12,18 +12,28 @@ import "./interface/IRuntimeRBAC.sol";
12
12
  /**
13
13
  * @title RuntimeRBAC
14
14
  * @dev Minimal Runtime Role-Based Access Control system based on EngineBlox
15
- *
15
+ *
16
16
  * This contract provides essential runtime RBAC functionality:
17
17
  * - Creation of non-protected roles
18
18
  * - Basic wallet assignment to roles
19
19
  * - Function permission management per role
20
20
  * - Integration with EngineBlox for secure operations
21
- *
21
+ *
22
22
  * Key Features:
23
23
  * - Only non-protected roles can be created dynamically
24
24
  * - Protected roles (OWNER, BROADCASTER, RECOVERY) are managed by SecureOwnable
25
25
  * - Minimal interface for core RBAC operations
26
26
  * - Essential role management functions only
27
+ *
28
+ * @custom:security PROTECTED-ROLE POLICY (defense in layers):
29
+ * - RuntimeRBAC is **unauthorized** to modify protected roles (wallet add/revoke/remove).
30
+ * - For ADD_WALLET and REVOKE_WALLET we call _requireRoleNotProtected so batch ops cannot
31
+ * change who holds system roles. For REMOVE_ROLE we rely on EngineBlox.removeRole, which
32
+ * enforces the same policy at the library layer (cannot remove protected roles).
33
+ * - The **only** place to modify system wallets (protected roles) is the SecureOwnable
34
+ * security component (e.g. transferOwnershipRequest, broadcaster/recovery changes).
35
+ * - This layering is intentional: RBAC cannot touch protected roles; SecureOwnable is the
36
+ * single source of truth for system wallet changes.
27
37
  */
28
38
  abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
29
39
  using EngineBlox for EngineBlox.SecureOperationState;
@@ -71,7 +81,7 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
71
81
  /**
72
82
  * @dev Requests and approves a RBAC configuration batch using a meta-transaction
73
83
  * @param metaTx The meta-transaction
74
- * @return The transaction record
84
+ * @return The transaction ID of the applied batch
75
85
  * @notice OWNER signs, BROADCASTER executes according to RuntimeRBACDefinitions
76
86
  */
77
87
  function roleConfigBatchRequestAndApprove(
@@ -85,6 +95,13 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
85
95
  /**
86
96
  * @dev External function that can only be called by the contract itself to execute a RBAC configuration batch
87
97
  * @param actions Encoded role configuration actions
98
+ *
99
+ * ## Role config batch ordering (required to avoid revert and gas waste)
100
+ *
101
+ * Actions must be ordered so that dependencies are satisfied:
102
+ * - **CREATE_ROLE** must appear before **ADD_WALLET** or **ADD_FUNCTION_TO_ROLE** for the same role; otherwise the role does not exist and the add will revert.
103
+ * - **REMOVE_ROLE** should be used only for an existing role; use **REVOKE_WALLET** first if the role has assigned wallets (optional but recommended for clarity).
104
+ * - For a given role, typical order: CREATE_ROLE → ADD_WALLET / ADD_FUNCTION_TO_ROLE as needed; to remove: REVOKE_WALLET (and REMOVE_FUNCTION_FROM_ROLE) as needed → REMOVE_ROLE.
88
105
  */
89
106
  function executeRoleConfigBatch(IRuntimeRBAC.RoleConfigAction[] calldata actions) external {
90
107
  _validateExecuteBySelf();
@@ -95,6 +112,9 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
95
112
 
96
113
  /**
97
114
  * @dev Reverts if the role is protected (prevents editing OWNER, BROADCASTER, RECOVERY via batch).
115
+ * Used for ADD_WALLET and REVOKE_WALLET so RuntimeRBAC cannot change who holds system roles.
116
+ * REMOVE_ROLE is not checked here; EngineBlox.removeRole enforces protected-role policy at
117
+ * the library layer. See contract-level @custom:security PROTECTED-ROLE POLICY.
98
118
  * @param roleHash The role hash to check
99
119
  */
100
120
  function _requireRoleNotProtected(bytes32 roleHash) internal view {
@@ -106,6 +126,10 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
106
126
  /**
107
127
  * @dev Internal helper to execute a RBAC configuration batch
108
128
  * @param actions Encoded role configuration actions
129
+ *
130
+ * @custom:order Required ordering to avoid revert and gas waste:
131
+ * 1. CREATE_ROLE before any ADD_WALLET or ADD_FUNCTION_TO_ROLE for that role.
132
+ * 2. REMOVE_ROLE only for a role that exists; prefer REVOKE_WALLET (and REMOVE_FUNCTION_FROM_ROLE) before REMOVE_ROLE when the role has members.
109
133
  */
110
134
  function _executeRoleConfigBatch(IRuntimeRBAC.RoleConfigAction[] calldata actions) internal {
111
135
  _validateBatchSize(actions.length);
@@ -142,7 +166,11 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
142
166
  }
143
167
 
144
168
  /**
145
- * @dev Executes REMOVE_ROLE: removes a role by hash
169
+ * @dev Executes REMOVE_ROLE: removes a role by hash.
170
+ * Protected-role check is enforced in EngineBlox.removeRole (library layer); RuntimeRBAC
171
+ * does not duplicate it here. SecureOwnable is the only component authorized to change
172
+ * system wallets; RBAC is unauthorized to modify protected roles. See @custom:security
173
+ * PROTECTED-ROLE POLICY on the contract.
146
174
  * @param data ABI-encoded (bytes32 roleHash)
147
175
  */
148
176
  function _executeRemoveRole(bytes calldata data) internal {
@@ -174,8 +202,11 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
174
202
  }
175
203
 
176
204
  /**
177
- * @dev Executes ADD_FUNCTION_TO_ROLE: adds a function permission to a role
205
+ * @dev Executes ADD_FUNCTION_TO_ROLE: adds a function permission to a role.
178
206
  * @param data ABI-encoded (bytes32 roleHash, FunctionPermission functionPermission)
207
+ * @custom:security By design we allow adding function permissions to protected roles (OWNER, BROADCASTER, RECOVERY)
208
+ * to retain flexibility to grant new function permissions to system roles; only wallet add/revoke
209
+ * are restricted on protected roles.
179
210
  */
180
211
  function _executeAddFunctionToRole(bytes calldata data) internal {
181
212
  (
@@ -187,8 +218,11 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
187
218
  }
188
219
 
189
220
  /**
190
- * @dev Executes REMOVE_FUNCTION_FROM_ROLE: removes a function permission from a role
221
+ * @dev Executes REMOVE_FUNCTION_FROM_ROLE: removes a function permission from a role.
191
222
  * @param data ABI-encoded (bytes32 roleHash, bytes4 functionSelector)
223
+ * @custom:security By design we allow removing function permissions from protected roles (OWNER, BROADCASTER, RECOVERY)
224
+ * to retain flexibility to adjust which functions system roles can call; only wallet add/revoke
225
+ * are restricted on protected roles.
192
226
  */
193
227
  function _executeRemoveFunctionFromRole(bytes calldata data) internal {
194
228
  (bytes32 roleHash, bytes4 functionSelector) = abi.decode(data, (bytes32, bytes4));
@@ -12,7 +12,7 @@ import "../../lib/EngineBlox.sol";
12
12
  *
13
13
  * Key Features:
14
14
  * - Batch-based role configuration (atomic operations)
15
- * - Runtime function schema registration
15
+ * - Role and permission management (function schema registration is handled by GuardController)
16
16
  * - Integration with EngineBlox for secure operations
17
17
  * - Query functions for role and permission inspection
18
18
  *
@@ -47,7 +47,7 @@ interface IRuntimeRBAC {
47
47
  /**
48
48
  * @dev Requests and approves a RBAC configuration batch using a meta-transaction
49
49
  * @param metaTx The meta-transaction
50
- * @return The transaction record
50
+ * @return The transaction ID of the applied batch
51
51
  */
52
52
  function roleConfigBatchRequestAndApprove(
53
53
  EngineBlox.MetaTransaction memory metaTx