@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.
- package/abi/BaseStateMachine.abi.json +5 -0
- package/abi/EngineBlox.abi.json +22 -0
- package/abi/GuardController.abi.json +5 -0
- package/abi/GuardControllerDefinitions.abi.json +5 -0
- package/abi/IDefinition.abi.json +5 -0
- package/abi/RuntimeRBAC.abi.json +5 -0
- package/abi/RuntimeRBACDefinitions.abi.json +5 -0
- package/abi/SecureOwnable.abi.json +5 -0
- package/abi/SecureOwnableDefinitions.abi.json +5 -0
- package/core/access/RuntimeRBAC.sol +40 -6
- package/core/access/interface/IRuntimeRBAC.sol +2 -2
- package/core/access/lib/definitions/RuntimeRBACDefinitions.sol +290 -288
- package/core/base/BaseStateMachine.sol +948 -943
- package/core/execution/GuardController.sol +8 -7
- package/core/execution/interface/IGuardController.sol +3 -3
- package/core/execution/lib/definitions/GuardControllerDefinitions.sol +514 -506
- package/core/lib/EngineBlox.sol +250 -81
- package/core/lib/utils/SharedValidation.sol +6 -4
- package/core/security/lib/definitions/SecureOwnableDefinitions.sol +802 -786
- package/package.json +1 -1
package/abi/EngineBlox.abi.json
CHANGED
|
@@ -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
|
{
|
package/abi/IDefinition.abi.json
CHANGED
package/abi/RuntimeRBAC.abi.json
CHANGED
|
@@ -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
|
|
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
|
-
* -
|
|
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
|
|
50
|
+
* @return The transaction ID of the applied batch
|
|
51
51
|
*/
|
|
52
52
|
function roleConfigBatchRequestAndApprove(
|
|
53
53
|
EngineBlox.MetaTransaction memory metaTx
|