@bloxchain/contracts 1.0.0-alpha.13 → 1.0.0-alpha.15
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/README.md +1 -1
- package/abi/BaseStateMachine.abi.json +2 -45
- package/abi/GuardController.abi.json +20 -63
- package/abi/RuntimeRBAC.abi.json +20 -63
- package/abi/SecureOwnable.abi.json +20 -63
- package/core/base/BaseStateMachine.sol +943 -967
- package/core/base/interface/IBaseStateMachine.sol +0 -8
- package/core/execution/GuardController.sol +447 -458
- package/core/execution/interface/IGuardController.sol +5 -19
- package/core/execution/lib/definitions/GuardControllerDefinitions.sol +22 -9
- package/core/lib/EngineBlox.sol +92 -89
- package/core/security/SecureOwnable.sol +394 -394
- package/package.json +1 -1
- package/abi/AccountBlox.abi.json +0 -3946
- package/abi/BareBlox.abi.json +0 -1378
- package/abi/RoleBlox.abi.json +0 -2994
- package/abi/SecureBlox.abi.json +0 -2753
- package/abi/SimpleRWA20.abi.json +0 -4032
- package/abi/SimpleRWA20Definitions.abi.json +0 -191
- package/abi/SimpleVault.abi.json +0 -3407
- package/abi/SimpleVaultDefinitions.abi.json +0 -269
|
@@ -94,67 +94,53 @@ interface IGuardController {
|
|
|
94
94
|
/**
|
|
95
95
|
* @dev Approves and executes a time-locked transaction
|
|
96
96
|
* @param txId The transaction ID
|
|
97
|
-
* @param expectedOperationType The expected operation type for validation
|
|
98
97
|
* @return txId The transaction ID (use getTransaction(txId) for full record and result)
|
|
99
98
|
* @notice Requires STANDARD execution type and EXECUTE_TIME_DELAY_APPROVE permission for the execution function
|
|
100
99
|
*/
|
|
101
100
|
function approveTimeLockExecution(
|
|
102
|
-
uint256 txId
|
|
103
|
-
bytes32 expectedOperationType
|
|
101
|
+
uint256 txId
|
|
104
102
|
) external returns (uint256);
|
|
105
103
|
|
|
106
104
|
/**
|
|
107
105
|
* @dev Cancels a time-locked transaction
|
|
108
106
|
* @param txId The transaction ID
|
|
109
|
-
* @param expectedOperationType The expected operation type for validation
|
|
110
107
|
* @return txId The transaction ID (use getTransaction(txId) for full record)
|
|
111
108
|
* @notice Requires STANDARD execution type and EXECUTE_TIME_DELAY_CANCEL permission for the execution function
|
|
112
109
|
*/
|
|
113
110
|
function cancelTimeLockExecution(
|
|
114
|
-
uint256 txId
|
|
115
|
-
bytes32 expectedOperationType
|
|
111
|
+
uint256 txId
|
|
116
112
|
) external returns (uint256);
|
|
117
113
|
|
|
118
114
|
/**
|
|
119
115
|
* @dev Approves a time-locked transaction using a meta-transaction
|
|
120
116
|
* @param metaTx The meta-transaction containing the transaction record and signature
|
|
121
|
-
* @param expectedOperationType The expected operation type for validation
|
|
122
|
-
* @param requiredSelector The handler selector for validation
|
|
123
117
|
* @return The transaction ID (use getTransaction(txId) for full record)
|
|
124
118
|
* @notice Requires STANDARD execution type and EXECUTE_META_APPROVE permission for the execution function
|
|
125
119
|
*/
|
|
126
120
|
function approveTimeLockExecutionWithMetaTx(
|
|
127
|
-
EngineBlox.MetaTransaction memory metaTx
|
|
128
|
-
bytes32 expectedOperationType,
|
|
129
|
-
bytes4 requiredSelector
|
|
121
|
+
EngineBlox.MetaTransaction memory metaTx
|
|
130
122
|
) external returns (uint256);
|
|
131
123
|
|
|
132
124
|
/**
|
|
133
125
|
* @dev Cancels a time-locked transaction using a meta-transaction
|
|
134
126
|
* @param metaTx The meta-transaction containing the transaction record and signature
|
|
135
|
-
* @param expectedOperationType The expected operation type for validation
|
|
136
|
-
* @param requiredSelector The handler selector for validation
|
|
137
127
|
* @return The transaction ID (use getTransaction(txId) for full record)
|
|
138
128
|
* @notice Requires STANDARD execution type and EXECUTE_META_CANCEL permission for the execution function
|
|
139
129
|
*/
|
|
140
130
|
function cancelTimeLockExecutionWithMetaTx(
|
|
141
|
-
EngineBlox.MetaTransaction memory metaTx
|
|
142
|
-
bytes32 expectedOperationType,
|
|
143
|
-
bytes4 requiredSelector
|
|
131
|
+
EngineBlox.MetaTransaction memory metaTx
|
|
144
132
|
) external returns (uint256);
|
|
145
133
|
|
|
146
134
|
/**
|
|
147
135
|
* @dev Requests and approves a transaction in one step using a meta-transaction
|
|
148
136
|
* @param metaTx The meta-transaction containing the transaction record and signature
|
|
149
|
-
* @param requiredSelector The handler selector for validation
|
|
150
137
|
* @return The transaction ID (use getTransaction(txId) for full record)
|
|
151
138
|
* @notice Requires STANDARD execution type
|
|
152
139
|
* @notice Validates function schema and permissions for the execution function (same as executeWithTimeLock)
|
|
153
140
|
* @notice Requires EXECUTE_META_REQUEST_AND_APPROVE permission for the execution function selector
|
|
154
141
|
*/
|
|
155
142
|
function requestAndApproveExecution(
|
|
156
|
-
EngineBlox.MetaTransaction memory metaTx
|
|
157
|
-
bytes4 requiredSelector
|
|
143
|
+
EngineBlox.MetaTransaction memory metaTx
|
|
158
144
|
) external returns (uint256);
|
|
159
145
|
}
|
|
160
146
|
|
|
@@ -47,14 +47,27 @@ library GuardControllerDefinitions {
|
|
|
47
47
|
// GuardController: cancelTimeLockExecution(uint256)
|
|
48
48
|
bytes4 public constant CANCEL_TIMELOCK_EXECUTION_SELECTOR = bytes4(keccak256("cancelTimeLockExecution(uint256)"));
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
|
|
51
|
+
// GuardController: approveTimeLockExecutionWithMetaTx(EngineBlox.MetaTransaction)
|
|
52
|
+
bytes4 public constant APPROVE_TIMELOCK_EXECUTION_META_SELECTOR = bytes4(
|
|
53
|
+
keccak256(
|
|
54
|
+
"approveTimeLockExecutionWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))"
|
|
55
|
+
)
|
|
56
|
+
);
|
|
52
57
|
|
|
53
|
-
// GuardController: cancelTimeLockExecutionWithMetaTx(
|
|
54
|
-
bytes4 public constant CANCEL_TIMELOCK_EXECUTION_META_SELECTOR = bytes4(
|
|
58
|
+
// GuardController: cancelTimeLockExecutionWithMetaTx(EngineBlox.MetaTransaction)
|
|
59
|
+
bytes4 public constant CANCEL_TIMELOCK_EXECUTION_META_SELECTOR = bytes4(
|
|
60
|
+
keccak256(
|
|
61
|
+
"cancelTimeLockExecutionWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))"
|
|
62
|
+
)
|
|
63
|
+
);
|
|
55
64
|
|
|
56
|
-
// GuardController: requestAndApproveExecution(
|
|
57
|
-
bytes4 public constant REQUEST_AND_APPROVE_EXECUTION_SELECTOR = bytes4(
|
|
65
|
+
// GuardController: requestAndApproveExecution(EngineBlox.MetaTransaction)
|
|
66
|
+
bytes4 public constant REQUEST_AND_APPROVE_EXECUTION_SELECTOR = bytes4(
|
|
67
|
+
keccak256(
|
|
68
|
+
"requestAndApproveExecution(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))"
|
|
69
|
+
)
|
|
70
|
+
);
|
|
58
71
|
|
|
59
72
|
// GuardController: guardConfigBatchRequestAndApprove(...)
|
|
60
73
|
bytes4 public constant GUARD_CONFIG_BATCH_META_SELECTOR = bytes4(
|
|
@@ -171,7 +184,7 @@ library GuardControllerDefinitions {
|
|
|
171
184
|
|
|
172
185
|
// Schema 3: GuardController.approveTimeLockExecutionWithMetaTx
|
|
173
186
|
schemas[3] = EngineBlox.FunctionSchema({
|
|
174
|
-
functionSignature: "approveTimeLockExecutionWithMetaTx((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
187
|
+
functionSignature: "approveTimeLockExecutionWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
175
188
|
functionSelector: APPROVE_TIMELOCK_EXECUTION_META_SELECTOR,
|
|
176
189
|
operationType: CONTROLLER_OPERATION,
|
|
177
190
|
operationName: "CONTROLLER_OPERATION",
|
|
@@ -182,7 +195,7 @@ library GuardControllerDefinitions {
|
|
|
182
195
|
|
|
183
196
|
// Schema 4: GuardController.cancelTimeLockExecutionWithMetaTx
|
|
184
197
|
schemas[4] = EngineBlox.FunctionSchema({
|
|
185
|
-
functionSignature: "cancelTimeLockExecutionWithMetaTx((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
198
|
+
functionSignature: "cancelTimeLockExecutionWithMetaTx(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
186
199
|
functionSelector: CANCEL_TIMELOCK_EXECUTION_META_SELECTOR,
|
|
187
200
|
operationType: CONTROLLER_OPERATION,
|
|
188
201
|
operationName: "CONTROLLER_OPERATION",
|
|
@@ -193,7 +206,7 @@ library GuardControllerDefinitions {
|
|
|
193
206
|
|
|
194
207
|
// Schema 5: GuardController.requestAndApproveExecution
|
|
195
208
|
schemas[5] = EngineBlox.FunctionSchema({
|
|
196
|
-
functionSignature: "requestAndApproveExecution((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
209
|
+
functionSignature: "requestAndApproveExecution(((uint256,uint256,uint8,(address,address,uint256,uint256,bytes32,bytes4,bytes),bytes32,bytes,(address,uint256,address,uint256)),(uint256,uint256,address,bytes4,uint8,uint256,uint256,address),bytes32,bytes,bytes))",
|
|
197
210
|
functionSelector: REQUEST_AND_APPROVE_EXECUTION_SELECTOR,
|
|
198
211
|
operationType: CONTROLLER_OPERATION,
|
|
199
212
|
operationName: "CONTROLLER_OPERATION",
|
package/core/lib/EngineBlox.sol
CHANGED
|
@@ -266,11 +266,11 @@ library EngineBlox {
|
|
|
266
266
|
/**
|
|
267
267
|
* @dev Updates the time lock period for the SecureOperationState.
|
|
268
268
|
* @param self The SecureOperationState to modify.
|
|
269
|
-
* @param
|
|
269
|
+
* @param periodSec The new time lock period in seconds.
|
|
270
270
|
*/
|
|
271
|
-
function updateTimeLockPeriod(SecureOperationState storage self, uint256
|
|
272
|
-
SharedValidation.validateTimeLockPeriod(
|
|
273
|
-
self.timeLockPeriodSec =
|
|
271
|
+
function updateTimeLockPeriod(SecureOperationState storage self, uint256 periodSec) public {
|
|
272
|
+
SharedValidation.validateTimeLockPeriod(periodSec);
|
|
273
|
+
self.timeLockPeriodSec = periodSec;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// ============ TRANSACTION MANAGEMENT FUNCTIONS ============
|
|
@@ -322,7 +322,7 @@ library EngineBlox {
|
|
|
322
322
|
operationType,
|
|
323
323
|
executionSelector,
|
|
324
324
|
executionParams,
|
|
325
|
-
|
|
325
|
+
_emptyPayment()
|
|
326
326
|
);
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -396,9 +396,9 @@ library EngineBlox {
|
|
|
396
396
|
) private returns (TxRecord memory) {
|
|
397
397
|
SharedValidation.validateNotZeroAddress(target);
|
|
398
398
|
// enforce that the requested target is whitelisted for this selector.
|
|
399
|
-
|
|
399
|
+
_validateTargetWhitelist(self, executionSelector, target);
|
|
400
400
|
|
|
401
|
-
TxRecord memory txRequestRecord =
|
|
401
|
+
TxRecord memory txRequestRecord = createTxRecord(
|
|
402
402
|
self,
|
|
403
403
|
requester,
|
|
404
404
|
target,
|
|
@@ -414,7 +414,7 @@ library EngineBlox {
|
|
|
414
414
|
self.txCounter++;
|
|
415
415
|
|
|
416
416
|
// Add to pending transactions list
|
|
417
|
-
|
|
417
|
+
addPendingTx(self, txRequestRecord.txId);
|
|
418
418
|
|
|
419
419
|
logTxEvent(self, txRequestRecord.txId, executionSelector);
|
|
420
420
|
|
|
@@ -576,7 +576,7 @@ library EngineBlox {
|
|
|
576
576
|
// This proves reentrancy protection is active at entry point
|
|
577
577
|
_validateTxStatus(self, record.txId, TxStatus.EXECUTING);
|
|
578
578
|
|
|
579
|
-
bytes memory txData =
|
|
579
|
+
bytes memory txData = buildCallData(record);
|
|
580
580
|
uint gas = record.params.gasLimit;
|
|
581
581
|
if (gas == 0) {
|
|
582
582
|
gas = gasleft();
|
|
@@ -662,11 +662,11 @@ library EngineBlox {
|
|
|
662
662
|
}
|
|
663
663
|
|
|
664
664
|
/**
|
|
665
|
-
* @dev
|
|
665
|
+
* @dev Builds transaction call data from execution selector and params without executing it.
|
|
666
666
|
* @param record The transaction record to prepare data for.
|
|
667
667
|
* @return The prepared transaction data.
|
|
668
668
|
*/
|
|
669
|
-
function
|
|
669
|
+
function buildCallData(TxRecord memory record) private pure returns (bytes memory) {
|
|
670
670
|
// If executionSelector is NATIVE_TRANSFER_SELECTOR, it's a simple native token transfer (no function call)
|
|
671
671
|
if (record.params.executionSelector == NATIVE_TRANSFER_SELECTOR) {
|
|
672
672
|
// SECURITY: Validate empty params to prevent confusion with real function calls
|
|
@@ -683,7 +683,7 @@ library EngineBlox {
|
|
|
683
683
|
|
|
684
684
|
|
|
685
685
|
/**
|
|
686
|
-
* @notice Creates a
|
|
686
|
+
* @notice Creates a transaction record with basic fields populated
|
|
687
687
|
* @dev Initializes a TxRecord struct with the provided parameters and default values
|
|
688
688
|
* @param self The SecureOperationState to reference for txId and timelock
|
|
689
689
|
* @param requester The address initiating the transaction
|
|
@@ -696,7 +696,7 @@ library EngineBlox {
|
|
|
696
696
|
* @param payment The payment details to attach to the record (use empty struct for no payment)
|
|
697
697
|
* @return TxRecord A new transaction record with populated fields
|
|
698
698
|
*/
|
|
699
|
-
function
|
|
699
|
+
function createTxRecord(
|
|
700
700
|
SecureOperationState storage self,
|
|
701
701
|
address requester,
|
|
702
702
|
address target,
|
|
@@ -731,7 +731,7 @@ library EngineBlox {
|
|
|
731
731
|
* @param self The SecureOperationState to modify.
|
|
732
732
|
* @param txId The transaction ID to add to the pending set.
|
|
733
733
|
*/
|
|
734
|
-
function
|
|
734
|
+
function addPendingTx(SecureOperationState storage self, uint256 txId) private {
|
|
735
735
|
SharedValidation.validateTransactionExists(txId);
|
|
736
736
|
_validateTxStatus(self, txId, TxStatus.PENDING);
|
|
737
737
|
|
|
@@ -746,7 +746,7 @@ library EngineBlox {
|
|
|
746
746
|
* @param self The SecureOperationState to modify.
|
|
747
747
|
* @param txId The transaction ID to remove from the pending set.
|
|
748
748
|
*/
|
|
749
|
-
function
|
|
749
|
+
function removePendingTx(SecureOperationState storage self, uint256 txId) private {
|
|
750
750
|
SharedValidation.validateTransactionExists(txId);
|
|
751
751
|
|
|
752
752
|
// Remove the transaction ID from the set (O(1) operation)
|
|
@@ -914,13 +914,13 @@ library EngineBlox {
|
|
|
914
914
|
}
|
|
915
915
|
|
|
916
916
|
/**
|
|
917
|
-
* @dev Updates a
|
|
917
|
+
* @dev Updates a wallet in a role (replaces oldWallet with newWallet).
|
|
918
918
|
* @param self The SecureOperationState to modify.
|
|
919
919
|
* @param role The role to update.
|
|
920
920
|
* @param newWallet The new wallet address to assign the role to.
|
|
921
921
|
* @param oldWallet The old wallet address to remove from the role.
|
|
922
922
|
*/
|
|
923
|
-
function
|
|
923
|
+
function updateWallet(SecureOperationState storage self, bytes32 role, address newWallet, address oldWallet) public {
|
|
924
924
|
_validateRoleExists(self, role);
|
|
925
925
|
SharedValidation.validateNotZeroAddress(newWallet);
|
|
926
926
|
SharedValidation.validateNewAddress(newWallet, oldWallet);
|
|
@@ -1107,7 +1107,7 @@ library EngineBlox {
|
|
|
1107
1107
|
// ============ FUNCTION MANAGEMENT FUNCTIONS ============
|
|
1108
1108
|
|
|
1109
1109
|
/**
|
|
1110
|
-
* @dev
|
|
1110
|
+
* @dev Registers a function access control with specified permissions.
|
|
1111
1111
|
* @param self The SecureOperationState to check.
|
|
1112
1112
|
* @param functionSignature Function signature (e.g., "transfer(address,uint256)") or function name.
|
|
1113
1113
|
* @param functionSelector Hash identifier for the function.
|
|
@@ -1116,7 +1116,7 @@ library EngineBlox {
|
|
|
1116
1116
|
* @param isProtected Whether the function schema is protected from removal.
|
|
1117
1117
|
* @param handlerForSelectors Non-empty array required - execution selectors must contain self-reference, handler selectors must point to execution selectors
|
|
1118
1118
|
*/
|
|
1119
|
-
function
|
|
1119
|
+
function registerFunction(
|
|
1120
1120
|
SecureOperationState storage self,
|
|
1121
1121
|
string memory functionSignature,
|
|
1122
1122
|
bytes4 functionSelector,
|
|
@@ -1183,15 +1183,15 @@ library EngineBlox {
|
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
1185
1185
|
/**
|
|
1186
|
-
* @dev
|
|
1186
|
+
* @dev Unregisters a function schema from the system.
|
|
1187
1187
|
* @param self The SecureOperationState to modify.
|
|
1188
|
-
* @param functionSelector The function selector to
|
|
1188
|
+
* @param functionSelector The function selector to unregister.
|
|
1189
1189
|
* @param safeRemoval If true, reverts with ResourceAlreadyExists when any role still references this function.
|
|
1190
1190
|
* The safeRemoval check is done inside this function (iterating supportedRolesSet directly) for efficiency.
|
|
1191
|
-
* @notice Security: Cannot
|
|
1191
|
+
* @notice Security: Cannot unregister protected function schemas to maintain system integrity.
|
|
1192
1192
|
* @notice Cleanup: Automatically removes unused operation types from supportedOperationTypesSet.
|
|
1193
1193
|
*/
|
|
1194
|
-
function
|
|
1194
|
+
function unregisterFunction(
|
|
1195
1195
|
SecureOperationState storage self,
|
|
1196
1196
|
bytes4 functionSelector,
|
|
1197
1197
|
bool safeRemoval
|
|
@@ -1238,34 +1238,13 @@ library EngineBlox {
|
|
|
1238
1238
|
}
|
|
1239
1239
|
}
|
|
1240
1240
|
|
|
1241
|
-
/**
|
|
1242
|
-
* @dev Checks if a specific action is supported by a function.
|
|
1243
|
-
* @param self The SecureOperationState to check.
|
|
1244
|
-
* @param functionSelector The function selector to check.
|
|
1245
|
-
* @param action The action to check for support.
|
|
1246
|
-
* @return True if the action is supported by the function, false otherwise.
|
|
1247
|
-
*/
|
|
1248
|
-
function isActionSupportedByFunction(
|
|
1249
|
-
SecureOperationState storage self,
|
|
1250
|
-
bytes4 functionSelector,
|
|
1251
|
-
TxAction action
|
|
1252
|
-
) public view returns (bool) {
|
|
1253
|
-
// Check if function exists in supportedFunctionsSet
|
|
1254
|
-
if (!self.supportedFunctionsSet.contains(bytes32(functionSelector))) {
|
|
1255
|
-
return false;
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
FunctionSchema memory functionSchema = self.functions[functionSelector];
|
|
1259
|
-
return hasActionInBitmap(functionSchema.supportedActionsBitmap, action);
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
1241
|
/**
|
|
1263
1242
|
* @dev Adds a target address to the whitelist for a function selector.
|
|
1264
1243
|
* @param self The SecureOperationState to modify.
|
|
1265
1244
|
* @param functionSelector The function selector whose whitelist will be updated.
|
|
1266
1245
|
* @param target The target address to add to the whitelist.
|
|
1267
1246
|
*/
|
|
1268
|
-
function
|
|
1247
|
+
function addTargetToWhitelist(
|
|
1269
1248
|
SecureOperationState storage self,
|
|
1270
1249
|
bytes4 functionSelector,
|
|
1271
1250
|
address target
|
|
@@ -1289,7 +1268,7 @@ library EngineBlox {
|
|
|
1289
1268
|
* @param functionSelector The function selector whose whitelist will be updated.
|
|
1290
1269
|
* @param target The target address to remove from the whitelist.
|
|
1291
1270
|
*/
|
|
1292
|
-
function
|
|
1271
|
+
function removeTargetFromWhitelist(
|
|
1293
1272
|
SecureOperationState storage self,
|
|
1294
1273
|
bytes4 functionSelector,
|
|
1295
1274
|
address target
|
|
@@ -1311,7 +1290,7 @@ library EngineBlox {
|
|
|
1311
1290
|
* @notice Target MUST be present in functionTargetWhitelist[functionSelector] unless target is address(this).
|
|
1312
1291
|
* If whitelist is empty (no entries), no targets are allowed - explicit deny for security.
|
|
1313
1292
|
*/
|
|
1314
|
-
function
|
|
1293
|
+
function _validateTargetWhitelist(
|
|
1315
1294
|
SecureOperationState storage self,
|
|
1316
1295
|
bytes4 functionSelector,
|
|
1317
1296
|
address target
|
|
@@ -1387,17 +1366,17 @@ library EngineBlox {
|
|
|
1387
1366
|
// ============ FUNCTION TARGET HOOKS MANAGEMENT ============
|
|
1388
1367
|
|
|
1389
1368
|
/**
|
|
1390
|
-
* @dev
|
|
1369
|
+
* @dev Sets (adds) a hook contract for a function selector.
|
|
1391
1370
|
* @param self The SecureOperationState to modify.
|
|
1392
1371
|
* @param functionSelector The function selector whose hooks will be updated.
|
|
1393
|
-
* @param
|
|
1372
|
+
* @param hook The hook contract address to add (must not be zero).
|
|
1394
1373
|
*/
|
|
1395
|
-
function
|
|
1374
|
+
function setHook(
|
|
1396
1375
|
SecureOperationState storage self,
|
|
1397
1376
|
bytes4 functionSelector,
|
|
1398
|
-
address
|
|
1377
|
+
address hook
|
|
1399
1378
|
) public {
|
|
1400
|
-
SharedValidation.validateNotZeroAddress(
|
|
1379
|
+
SharedValidation.validateNotZeroAddress(hook);
|
|
1401
1380
|
|
|
1402
1381
|
// Function selector must be registered in the schema set
|
|
1403
1382
|
if (!self.supportedFunctionsSet.contains(bytes32(functionSelector))) {
|
|
@@ -1412,36 +1391,38 @@ library EngineBlox {
|
|
|
1412
1391
|
MAX_HOOKS_PER_SELECTOR
|
|
1413
1392
|
);
|
|
1414
1393
|
|
|
1415
|
-
if (!set.add(
|
|
1416
|
-
revert SharedValidation.ItemAlreadyExists(
|
|
1394
|
+
if (!set.add(hook)) {
|
|
1395
|
+
revert SharedValidation.ItemAlreadyExists(hook);
|
|
1417
1396
|
}
|
|
1418
1397
|
}
|
|
1419
1398
|
|
|
1420
1399
|
/**
|
|
1421
|
-
* @dev
|
|
1400
|
+
* @dev Clears (removes) a hook contract for a function selector.
|
|
1422
1401
|
* @param self The SecureOperationState to modify.
|
|
1423
1402
|
* @param functionSelector The function selector whose hooks will be updated.
|
|
1424
|
-
* @param
|
|
1403
|
+
* @param hook The hook contract address to remove (must not be zero).
|
|
1425
1404
|
*/
|
|
1426
|
-
function
|
|
1405
|
+
function clearHook(
|
|
1427
1406
|
SecureOperationState storage self,
|
|
1428
1407
|
bytes4 functionSelector,
|
|
1429
|
-
address
|
|
1408
|
+
address hook
|
|
1430
1409
|
) public {
|
|
1410
|
+
SharedValidation.validateNotZeroAddress(hook);
|
|
1411
|
+
|
|
1431
1412
|
EnumerableSet.AddressSet storage set = self.functionTargetHooks[functionSelector];
|
|
1432
|
-
if (!set.remove(
|
|
1433
|
-
revert SharedValidation.ItemNotFound(
|
|
1413
|
+
if (!set.remove(hook)) {
|
|
1414
|
+
revert SharedValidation.ItemNotFound(hook);
|
|
1434
1415
|
}
|
|
1435
1416
|
}
|
|
1436
1417
|
|
|
1437
1418
|
/**
|
|
1438
|
-
* @dev Returns all
|
|
1419
|
+
* @dev Returns all configured hooks for a function selector.
|
|
1439
1420
|
* @param self The SecureOperationState to check.
|
|
1440
1421
|
* @param functionSelector The function selector to query.
|
|
1441
|
-
* @return Array of hook
|
|
1422
|
+
* @return Array of hook contract addresses.
|
|
1442
1423
|
* @notice Access control should be enforced by the calling contract.
|
|
1443
1424
|
*/
|
|
1444
|
-
function
|
|
1425
|
+
function getHooks(
|
|
1445
1426
|
SecureOperationState storage self,
|
|
1446
1427
|
bytes4 functionSelector
|
|
1447
1428
|
) public view returns (address[] memory) {
|
|
@@ -1465,7 +1446,7 @@ library EngineBlox {
|
|
|
1465
1446
|
|
|
1466
1447
|
/**
|
|
1467
1448
|
* @dev Internal: Returns all function schemas that use a specific operation type.
|
|
1468
|
-
* Used by
|
|
1449
|
+
* Used by unregisterFunction and getFunctionsByOperationType.
|
|
1469
1450
|
*/
|
|
1470
1451
|
function _getFunctionsByOperationType(
|
|
1471
1452
|
SecureOperationState storage self,
|
|
@@ -1496,42 +1477,42 @@ library EngineBlox {
|
|
|
1496
1477
|
// ============ BACKWARD COMPATIBILITY FUNCTIONS ============
|
|
1497
1478
|
|
|
1498
1479
|
/**
|
|
1499
|
-
* @dev Gets all pending transaction IDs
|
|
1480
|
+
* @dev Gets all pending transaction IDs
|
|
1500
1481
|
* @param self The SecureOperationState to check
|
|
1501
1482
|
* @return Array of pending transaction IDs
|
|
1502
1483
|
* @notice Access control should be enforced by the calling contract.
|
|
1503
1484
|
*/
|
|
1504
|
-
function
|
|
1485
|
+
function getPendingTransactions(SecureOperationState storage self) public view returns (uint256[] memory) {
|
|
1505
1486
|
return _convertUintSetToArray(self.pendingTransactionsSet);
|
|
1506
1487
|
}
|
|
1507
1488
|
|
|
1508
1489
|
/**
|
|
1509
|
-
* @dev Gets all supported roles as an array
|
|
1490
|
+
* @dev Gets all supported roles as an array
|
|
1510
1491
|
* @param self The SecureOperationState to check
|
|
1511
1492
|
* @return Array of supported role hashes
|
|
1512
1493
|
* @notice Access control should be enforced by the calling contract.
|
|
1513
1494
|
*/
|
|
1514
|
-
function
|
|
1495
|
+
function getSupportedRoles(SecureOperationState storage self) public view returns (bytes32[] memory) {
|
|
1515
1496
|
return _convertBytes32SetToArray(self.supportedRolesSet);
|
|
1516
1497
|
}
|
|
1517
1498
|
|
|
1518
1499
|
/**
|
|
1519
|
-
* @dev Gets all supported function selectors as an array
|
|
1500
|
+
* @dev Gets all supported function selectors as an array
|
|
1520
1501
|
* @param self The SecureOperationState to check
|
|
1521
1502
|
* @return Array of supported function selectors
|
|
1522
1503
|
* @notice Access control should be enforced by the calling contract.
|
|
1523
1504
|
*/
|
|
1524
|
-
function
|
|
1505
|
+
function getSupportedFunctions(SecureOperationState storage self) public view returns (bytes4[] memory) {
|
|
1525
1506
|
return _convertBytes4SetToArray(self.supportedFunctionsSet);
|
|
1526
1507
|
}
|
|
1527
1508
|
|
|
1528
1509
|
/**
|
|
1529
|
-
* @dev Gets all supported operation types as an array
|
|
1510
|
+
* @dev Gets all supported operation types as an array
|
|
1530
1511
|
* @param self The SecureOperationState to check
|
|
1531
1512
|
* @return Array of supported operation type hashes
|
|
1532
1513
|
* @notice Access control should be enforced by the calling contract.
|
|
1533
1514
|
*/
|
|
1534
|
-
function
|
|
1515
|
+
function getSupportedOperationTypes(SecureOperationState storage self) public view returns (bytes32[] memory) {
|
|
1535
1516
|
return _convertBytes32SetToArray(self.supportedOperationTypesSet);
|
|
1536
1517
|
}
|
|
1537
1518
|
|
|
@@ -1555,7 +1536,7 @@ library EngineBlox {
|
|
|
1555
1536
|
* @return Array of authorized wallet addresses
|
|
1556
1537
|
* @notice Access control should be enforced by the calling contract.
|
|
1557
1538
|
*/
|
|
1558
|
-
function
|
|
1539
|
+
function getAuthorizedWallets(
|
|
1559
1540
|
SecureOperationState storage self,
|
|
1560
1541
|
bytes32 roleHash
|
|
1561
1542
|
) public view returns (address[] memory) {
|
|
@@ -1767,7 +1748,7 @@ library EngineBlox {
|
|
|
1767
1748
|
) public view returns (MetaTransaction memory) {
|
|
1768
1749
|
SharedValidation.validateNotZeroAddress(txParams.target);
|
|
1769
1750
|
|
|
1770
|
-
TxRecord memory txRecord =
|
|
1751
|
+
TxRecord memory txRecord = createTxRecord(
|
|
1771
1752
|
self,
|
|
1772
1753
|
txParams.requester,
|
|
1773
1754
|
txParams.target,
|
|
@@ -1776,7 +1757,7 @@ library EngineBlox {
|
|
|
1776
1757
|
txParams.operationType,
|
|
1777
1758
|
txParams.executionSelector,
|
|
1778
1759
|
txParams.executionParams,
|
|
1779
|
-
|
|
1760
|
+
_emptyPayment()
|
|
1780
1761
|
);
|
|
1781
1762
|
|
|
1782
1763
|
return generateMetaTransaction(self, txRecord, metaTxParams);
|
|
@@ -1830,7 +1811,7 @@ library EngineBlox {
|
|
|
1830
1811
|
params: metaTxParams,
|
|
1831
1812
|
message: 0,
|
|
1832
1813
|
signature: "",
|
|
1833
|
-
data:
|
|
1814
|
+
data: buildCallData(txRecord)
|
|
1834
1815
|
});
|
|
1835
1816
|
|
|
1836
1817
|
// Generate the message hash for ready to sign meta-transaction
|
|
@@ -2020,7 +2001,7 @@ library EngineBlox {
|
|
|
2020
2001
|
bytes memory result
|
|
2021
2002
|
) private {
|
|
2022
2003
|
// enforce that the requested target is whitelisted for this selector.
|
|
2023
|
-
|
|
2004
|
+
_validateTargetWhitelist(self, self.txRecords[txId].params.executionSelector, self.txRecords[txId].params.target);
|
|
2024
2005
|
|
|
2025
2006
|
// Update storage with new status and result
|
|
2026
2007
|
if (success) {
|
|
@@ -2035,7 +2016,7 @@ library EngineBlox {
|
|
|
2035
2016
|
}
|
|
2036
2017
|
|
|
2037
2018
|
// Remove from pending transactions list
|
|
2038
|
-
|
|
2019
|
+
removePendingTx(self, txId);
|
|
2039
2020
|
|
|
2040
2021
|
logTxEvent(self, txId, self.txRecords[txId].params.executionSelector);
|
|
2041
2022
|
}
|
|
@@ -2050,12 +2031,12 @@ library EngineBlox {
|
|
|
2050
2031
|
uint256 txId
|
|
2051
2032
|
) private {
|
|
2052
2033
|
// enforce that the requested target is whitelisted for this selector.
|
|
2053
|
-
|
|
2034
|
+
_validateTargetWhitelist(self, self.txRecords[txId].params.executionSelector, self.txRecords[txId].params.target);
|
|
2054
2035
|
|
|
2055
2036
|
self.txRecords[txId].status = TxStatus.CANCELLED;
|
|
2056
2037
|
|
|
2057
2038
|
// Remove from pending transactions list
|
|
2058
|
-
|
|
2039
|
+
removePendingTx(self, txId);
|
|
2059
2040
|
|
|
2060
2041
|
logTxEvent(self, txId, self.txRecords[txId].params.executionSelector);
|
|
2061
2042
|
}
|
|
@@ -2135,6 +2116,10 @@ library EngineBlox {
|
|
|
2135
2116
|
bytes4 handlerSelector,
|
|
2136
2117
|
TxAction action
|
|
2137
2118
|
) internal view {
|
|
2119
|
+
// Ensure both execution and handler selectors have registered function schemas
|
|
2120
|
+
_validateFunctionSchemaExists(self, executionSelector);
|
|
2121
|
+
_validateFunctionSchemaExists(self, handlerSelector);
|
|
2122
|
+
|
|
2138
2123
|
// Validate permission for the execution selector (underlying operation)
|
|
2139
2124
|
if (!hasActionPermission(self, wallet, executionSelector, action)) {
|
|
2140
2125
|
revert SharedValidation.NoPermission(wallet);
|
|
@@ -2227,14 +2212,32 @@ library EngineBlox {
|
|
|
2227
2212
|
revert SharedValidation.ConflictingMetaTxPermissions(functionPermission.functionSelector);
|
|
2228
2213
|
}
|
|
2229
2214
|
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2215
|
+
_validateActionsSupportedByFunction(self, functionPermission.functionSelector, bitmap);
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
/**
|
|
2219
|
+
* @dev Validates that all actions present in the bitmap are supported by the function schema.
|
|
2220
|
+
* @param self The SecureOperationState to check.
|
|
2221
|
+
* @param functionSelector The function selector to check.
|
|
2222
|
+
* @param bitmap The granted actions bitmap to validate.
|
|
2223
|
+
*/
|
|
2224
|
+
function _validateActionsSupportedByFunction(
|
|
2225
|
+
SecureOperationState storage self,
|
|
2226
|
+
bytes4 functionSelector,
|
|
2227
|
+
uint16 bitmap
|
|
2228
|
+
) internal view {
|
|
2229
|
+
// If the function itself is not supported, none of its actions can be considered valid
|
|
2230
|
+
if (!self.supportedFunctionsSet.contains(bytes32(functionSelector))) {
|
|
2231
|
+
revert SharedValidation.NotSupported();
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
uint16 granted = bitmap;
|
|
2235
|
+
uint16 supported = self.functions[functionSelector].supportedActionsBitmap;
|
|
2236
|
+
|
|
2237
|
+
// Any bit set in granted but not in supported is invalid
|
|
2238
|
+
uint16 invalid = granted & ~supported;
|
|
2239
|
+
if (invalid != 0) {
|
|
2240
|
+
revert SharedValidation.NotSupported();
|
|
2238
2241
|
}
|
|
2239
2242
|
}
|
|
2240
2243
|
|
|
@@ -2302,7 +2305,7 @@ library EngineBlox {
|
|
|
2302
2305
|
* @dev Returns an empty PaymentDetails struct for use when no payment is attached.
|
|
2303
2306
|
* @return payment Empty payment details (recipient and amounts zero).
|
|
2304
2307
|
*/
|
|
2305
|
-
function
|
|
2308
|
+
function _emptyPayment() internal pure returns (PaymentDetails memory payment) {
|
|
2306
2309
|
return PaymentDetails({
|
|
2307
2310
|
recipient: address(0),
|
|
2308
2311
|
nativeTokenAmount: 0,
|