@@ -44,11 +44,8 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
4444 uint256 timeLockPeriodSec ,
4545 address eventForwarder
4646 ) public virtual onlyInitializing {
47- // Initialize base state machine (only if not already initialized)
48- if (! _secureState.initialized) {
49- _initializeBaseStateMachine (initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
50- }
51-
47+ _initializeBaseStateMachine (initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
48+
5249 // Load RuntimeRBAC-specific definitions
5350 IDefinition.RolePermission memory permissions = RuntimeRBACDefinitions.getRolePermissions ();
5451 _loadDefinitions (
@@ -117,68 +114,95 @@ abstract contract RuntimeRBAC is BaseStateMachine, IRuntimeRBAC {
117114 IRuntimeRBAC.RoleConfigAction calldata action = actions[i];
118115
119116 if (action.actionType == IRuntimeRBAC.RoleConfigActionType.CREATE_ROLE) {
120- // Decode CREATE_ROLE action data
121- // Format: (string roleName, uint256 maxWallets)
122- (
123- string memory roleName ,
124- uint256 maxWallets
125- ) = abi.decode (action.data, (string , uint256 ));
126-
127- // Create the role in the secure state with isProtected = false
128- bytes32 roleHash = _createRole (roleName, maxWallets, false );
129-
130- _logComponentEvent (_encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.CREATE_ROLE, roleHash, bytes4 (0 )));
117+ _executeCreateRole (action.data);
131118 } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.REMOVE_ROLE) {
132- // Decode REMOVE_ROLE action data
133- // Format: (bytes32 roleHash)
134- (bytes32 roleHash ) = abi.decode (action.data, (bytes32 ));
135- _removeRole (roleHash);
136-
137- _logComponentEvent (_encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.REMOVE_ROLE, roleHash, bytes4 (0 )));
119+ _executeRemoveRole (action.data);
138120 } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.ADD_WALLET) {
139- // Decode ADD_WALLET action data
140- // Format: (bytes32 roleHash, address wallet)
141- (bytes32 roleHash , address wallet ) = abi.decode (action.data, (bytes32 , address ));
142- _requireRoleNotProtected (roleHash);
143- _assignWallet (roleHash, wallet);
144-
145- _logComponentEvent (_encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.ADD_WALLET, roleHash, bytes4 (0 )));
121+ _executeAddWallet (action.data);
146122 } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.REVOKE_WALLET) {
147- // Decode REVOKE_WALLET action data
148- // Format: (bytes32 roleHash, address wallet)
149- (bytes32 roleHash , address wallet ) = abi.decode (action.data, (bytes32 , address ));
150- _requireRoleNotProtected (roleHash);
151- _revokeWallet (roleHash, wallet);
152-
153- _logComponentEvent (_encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.REVOKE_WALLET, roleHash, bytes4 (0 )));
123+ _executeRevokeWallet (action.data);
154124 } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.ADD_FUNCTION_TO_ROLE) {
155- // Decode ADD_FUNCTION_TO_ROLE action data
156- // Format: (bytes32 roleHash, FunctionPermission functionPermission)
157- (
158- bytes32 roleHash ,
159- EngineBlox.FunctionPermission memory functionPermission
160- ) = abi.decode (action.data, (bytes32 , EngineBlox.FunctionPermission));
161-
162- _addFunctionToRole (roleHash, functionPermission);
163-
164- _logComponentEvent (_encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.ADD_FUNCTION_TO_ROLE, roleHash, functionPermission.functionSelector));
125+ _executeAddFunctionToRole (action.data);
165126 } else if (action.actionType == IRuntimeRBAC.RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE) {
166- // Decode REMOVE_FUNCTION_FROM_ROLE action data
167- // Format: (bytes32 roleHash, bytes4 functionSelector)
168- (bytes32 roleHash , bytes4 functionSelector ) = abi.decode (action.data, (bytes32 , bytes4 ));
169- _removeFunctionFromRole (roleHash, functionSelector);
170-
171- _logComponentEvent (_encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE, roleHash, functionSelector));
127+ _executeRemoveFunctionFromRole (action.data);
172128 } else {
173129 revert SharedValidation.NotSupported ();
174130 }
175131 }
176132 }
177133
178134 /**
179- * @dev Encodes RBAC config event payload for ComponentEvent. Decode as (RoleConfigActionType, bytes32 roleHash, bytes4 functionSelector).
135+ * @dev Executes CREATE_ROLE: creates a new non-protected role
136+ * @param data ABI-encoded (string roleName, uint256 maxWallets)
137+ */
138+ function _executeCreateRole (bytes calldata data ) internal {
139+ (string memory roleName , uint256 maxWallets ) = abi.decode (data, (string , uint256 ));
140+ bytes32 roleHash = _createRole (roleName, maxWallets, false );
141+ _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.CREATE_ROLE, roleHash, bytes4 (0 ));
142+ }
143+
144+ /**
145+ * @dev Executes REMOVE_ROLE: removes a role by hash
146+ * @param data ABI-encoded (bytes32 roleHash)
147+ */
148+ function _executeRemoveRole (bytes calldata data ) internal {
149+ (bytes32 roleHash ) = abi.decode (data, (bytes32 ));
150+ _removeRole (roleHash);
151+ _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.REMOVE_ROLE, roleHash, bytes4 (0 ));
152+ }
153+
154+ /**
155+ * @dev Executes ADD_WALLET: assigns a wallet to a role (role must not be protected)
156+ * @param data ABI-encoded (bytes32 roleHash, address wallet)
157+ */
158+ function _executeAddWallet (bytes calldata data ) internal {
159+ (bytes32 roleHash , address wallet ) = abi.decode (data, (bytes32 , address ));
160+ _requireRoleNotProtected (roleHash);
161+ _assignWallet (roleHash, wallet);
162+ _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.ADD_WALLET, roleHash, bytes4 (0 ));
163+ }
164+
165+ /**
166+ * @dev Executes REVOKE_WALLET: revokes a wallet from a role (role must not be protected)
167+ * @param data ABI-encoded (bytes32 roleHash, address wallet)
168+ */
169+ function _executeRevokeWallet (bytes calldata data ) internal {
170+ (bytes32 roleHash , address wallet ) = abi.decode (data, (bytes32 , address ));
171+ _requireRoleNotProtected (roleHash);
172+ _revokeWallet (roleHash, wallet);
173+ _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.REVOKE_WALLET, roleHash, bytes4 (0 ));
174+ }
175+
176+ /**
177+ * @dev Executes ADD_FUNCTION_TO_ROLE: adds a function permission to a role
178+ * @param data ABI-encoded (bytes32 roleHash, FunctionPermission functionPermission)
179+ */
180+ function _executeAddFunctionToRole (bytes calldata data ) internal {
181+ (
182+ bytes32 roleHash ,
183+ EngineBlox.FunctionPermission memory functionPermission
184+ ) = abi.decode (data, (bytes32 , EngineBlox.FunctionPermission));
185+ _addFunctionToRole (roleHash, functionPermission);
186+ _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.ADD_FUNCTION_TO_ROLE, roleHash, functionPermission.functionSelector);
187+ }
188+
189+ /**
190+ * @dev Executes REMOVE_FUNCTION_FROM_ROLE: removes a function permission from a role
191+ * @param data ABI-encoded (bytes32 roleHash, bytes4 functionSelector)
192+ */
193+ function _executeRemoveFunctionFromRole (bytes calldata data ) internal {
194+ (bytes32 roleHash , bytes4 functionSelector ) = abi.decode (data, (bytes32 , bytes4 ));
195+ _removeFunctionFromRole (roleHash, functionSelector);
196+ _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE, roleHash, functionSelector);
197+ }
198+
199+ /**
200+ * @dev Encodes and logs a role config event via ComponentEvent. Payload decodes as (RoleConfigActionType, bytes32 roleHash, bytes4 functionSelector).
201+ * @param action The role config action type
202+ * @param roleHash The role hash
203+ * @param selector The function selector (or zero for N/A)
180204 */
181- function _encodeRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType action , bytes32 roleHash , bytes4 selector ) internal pure returns ( bytes memory ) {
182- return abi.encode (action, roleHash, selector);
205+ function _logRoleConfigEvent (IRuntimeRBAC.RoleConfigActionType action , bytes32 roleHash , bytes4 selector ) internal {
206+ _logComponentEvent ( abi.encode (action, roleHash, selector) );
183207 }
184208}
0 commit comments