@bloxchain/contracts 1.0.0-alpha.6 → 1.0.0
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/CHANGELOG.md +19 -0
- package/README.md +8 -9
- package/abi/BaseStateMachine.abi.json +773 -822
- package/abi/EngineBlox.abi.json +562 -552
- package/abi/GuardController.abi.json +1597 -1609
- package/abi/GuardControllerDefinitions.abi.json +257 -120
- package/abi/IDefinition.abi.json +57 -47
- package/abi/RuntimeRBAC.abi.json +841 -842
- package/abi/RuntimeRBACDefinitions.abi.json +265 -99
- package/abi/SecureOwnable.abi.json +1365 -1349
- package/abi/SecureOwnableDefinitions.abi.json +174 -164
- package/components/README.md +8 -0
- package/core/AUDIT.md +45 -0
- package/core/access/RuntimeRBAC.sol +130 -61
- package/core/access/interface/IRuntimeRBAC.sol +3 -3
- package/core/access/lib/definitions/RuntimeRBACDefinitions.sol +67 -3
- package/core/base/BaseStateMachine.sol +971 -967
- package/core/base/interface/IBaseStateMachine.sol +153 -160
- package/core/execution/GuardController.sol +89 -75
- package/core/execution/interface/IGuardController.sol +146 -160
- package/core/execution/lib/definitions/GuardControllerDefinitions.sol +180 -24
- package/core/lib/EngineBlox.sol +577 -327
- package/core/lib/interfaces/IDefinition.sol +49 -49
- package/core/lib/interfaces/IEventForwarder.sol +4 -2
- package/core/lib/utils/SharedValidation.sol +534 -487
- package/core/pattern/Account.sol +84 -65
- package/core/security/SecureOwnable.sol +446 -390
- package/core/security/interface/ISecureOwnable.sol +105 -105
- package/core/security/lib/definitions/SecureOwnableDefinitions.sol +49 -17
- package/package.json +11 -7
- package/standards/README.md +12 -0
- package/{core/research → standards/behavior}/ICopyable.sol +3 -11
- package/standards/hooks/IOnActionHook.sol +21 -0
- package/abi/AccountBlox.abi.json +0 -3916
- package/abi/BareBlox.abi.json +0 -1378
- package/abi/RoleBlox.abi.json +0 -2983
- 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
- package/core/research/BloxchainWallet.sol +0 -292
- package/core/research/FactoryBlox/FactoryBlox.sol +0 -346
- package/core/research/FactoryBlox/FactoryBloxDefinitions.sol +0 -143
- package/core/research/erc1155-blox/ERC1155Blox.sol +0 -169
- package/core/research/erc1155-blox/lib/definitions/ERC1155BloxDefinitions.sol +0 -203
- package/core/research/erc20-blox/ERC20Blox.sol +0 -167
- package/core/research/erc20-blox/lib/definitions/ERC20BloxDefinitions.sol +0 -185
- package/core/research/erc721-blox/ERC721Blox.sol +0 -131
- package/core/research/erc721-blox/lib/definitions/ERC721BloxDefinitions.sol +0 -172
- package/core/research/lending-blox/.gitkeep +0 -1
- package/core/research/p2p-blox/P2PBlox.sol +0 -266
- package/core/research/p2p-blox/README.md +0 -85
- package/core/research/p2p-blox/lib/definitions/P2PBloxDefinitions.sol +0 -19
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"inputs": [],
|
|
4
|
-
"name": "APPROVE_WITHDRAWAL_DELAYED_SELECTOR",
|
|
5
|
-
"outputs": [
|
|
6
|
-
{
|
|
7
|
-
"internalType": "bytes4",
|
|
8
|
-
"name": "",
|
|
9
|
-
"type": "bytes4"
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
"stateMutability": "view",
|
|
13
|
-
"type": "function"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"inputs": [],
|
|
17
|
-
"name": "APPROVE_WITHDRAWAL_META_SELECTOR",
|
|
18
|
-
"outputs": [
|
|
19
|
-
{
|
|
20
|
-
"internalType": "bytes4",
|
|
21
|
-
"name": "",
|
|
22
|
-
"type": "bytes4"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"stateMutability": "view",
|
|
26
|
-
"type": "function"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"inputs": [],
|
|
30
|
-
"name": "CANCEL_WITHDRAWAL_SELECTOR",
|
|
31
|
-
"outputs": [
|
|
32
|
-
{
|
|
33
|
-
"internalType": "bytes4",
|
|
34
|
-
"name": "",
|
|
35
|
-
"type": "bytes4"
|
|
36
|
-
}
|
|
37
|
-
],
|
|
38
|
-
"stateMutability": "view",
|
|
39
|
-
"type": "function"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"inputs": [],
|
|
43
|
-
"name": "GENERIC_APPROVAL",
|
|
44
|
-
"outputs": [
|
|
45
|
-
{
|
|
46
|
-
"internalType": "bytes32",
|
|
47
|
-
"name": "",
|
|
48
|
-
"type": "bytes32"
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
"stateMutability": "view",
|
|
52
|
-
"type": "function"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"inputs": [],
|
|
56
|
-
"name": "GENERIC_CANCELLATION",
|
|
57
|
-
"outputs": [
|
|
58
|
-
{
|
|
59
|
-
"internalType": "bytes32",
|
|
60
|
-
"name": "",
|
|
61
|
-
"type": "bytes32"
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
"stateMutability": "view",
|
|
65
|
-
"type": "function"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
"inputs": [],
|
|
69
|
-
"name": "GENERIC_META_APPROVAL",
|
|
70
|
-
"outputs": [
|
|
71
|
-
{
|
|
72
|
-
"internalType": "bytes32",
|
|
73
|
-
"name": "",
|
|
74
|
-
"type": "bytes32"
|
|
75
|
-
}
|
|
76
|
-
],
|
|
77
|
-
"stateMutability": "view",
|
|
78
|
-
"type": "function"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"inputs": [],
|
|
82
|
-
"name": "WITHDRAW_ETH",
|
|
83
|
-
"outputs": [
|
|
84
|
-
{
|
|
85
|
-
"internalType": "bytes32",
|
|
86
|
-
"name": "",
|
|
87
|
-
"type": "bytes32"
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
|
-
"stateMutability": "view",
|
|
91
|
-
"type": "function"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"inputs": [],
|
|
95
|
-
"name": "WITHDRAW_ETH_REQUEST_SELECTOR",
|
|
96
|
-
"outputs": [
|
|
97
|
-
{
|
|
98
|
-
"internalType": "bytes4",
|
|
99
|
-
"name": "",
|
|
100
|
-
"type": "bytes4"
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
"stateMutability": "view",
|
|
104
|
-
"type": "function"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"inputs": [],
|
|
108
|
-
"name": "WITHDRAW_ETH_SELECTOR",
|
|
109
|
-
"outputs": [
|
|
110
|
-
{
|
|
111
|
-
"internalType": "bytes4",
|
|
112
|
-
"name": "",
|
|
113
|
-
"type": "bytes4"
|
|
114
|
-
}
|
|
115
|
-
],
|
|
116
|
-
"stateMutability": "view",
|
|
117
|
-
"type": "function"
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"inputs": [],
|
|
121
|
-
"name": "WITHDRAW_TOKEN",
|
|
122
|
-
"outputs": [
|
|
123
|
-
{
|
|
124
|
-
"internalType": "bytes32",
|
|
125
|
-
"name": "",
|
|
126
|
-
"type": "bytes32"
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
"stateMutability": "view",
|
|
130
|
-
"type": "function"
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
"inputs": [],
|
|
134
|
-
"name": "WITHDRAW_TOKEN_REQUEST_SELECTOR",
|
|
135
|
-
"outputs": [
|
|
136
|
-
{
|
|
137
|
-
"internalType": "bytes4",
|
|
138
|
-
"name": "",
|
|
139
|
-
"type": "bytes4"
|
|
140
|
-
}
|
|
141
|
-
],
|
|
142
|
-
"stateMutability": "view",
|
|
143
|
-
"type": "function"
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
"inputs": [],
|
|
147
|
-
"name": "WITHDRAW_TOKEN_SELECTOR",
|
|
148
|
-
"outputs": [
|
|
149
|
-
{
|
|
150
|
-
"internalType": "bytes4",
|
|
151
|
-
"name": "",
|
|
152
|
-
"type": "bytes4"
|
|
153
|
-
}
|
|
154
|
-
],
|
|
155
|
-
"stateMutability": "view",
|
|
156
|
-
"type": "function"
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
"inputs": [],
|
|
160
|
-
"name": "getFunctionSchemas",
|
|
161
|
-
"outputs": [
|
|
162
|
-
{
|
|
163
|
-
"components": [
|
|
164
|
-
{
|
|
165
|
-
"internalType": "string",
|
|
166
|
-
"name": "functionSignature",
|
|
167
|
-
"type": "string"
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
"internalType": "bytes4",
|
|
171
|
-
"name": "functionSelector",
|
|
172
|
-
"type": "bytes4"
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
"internalType": "bytes32",
|
|
176
|
-
"name": "operationType",
|
|
177
|
-
"type": "bytes32"
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
"internalType": "string",
|
|
181
|
-
"name": "operationName",
|
|
182
|
-
"type": "string"
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
"internalType": "uint16",
|
|
186
|
-
"name": "supportedActionsBitmap",
|
|
187
|
-
"type": "uint16"
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
"internalType": "bool",
|
|
191
|
-
"name": "isProtected",
|
|
192
|
-
"type": "bool"
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"internalType": "bytes4[]",
|
|
196
|
-
"name": "handlerForSelectors",
|
|
197
|
-
"type": "bytes4[]"
|
|
198
|
-
}
|
|
199
|
-
],
|
|
200
|
-
"internalType": "struct EngineBlox.FunctionSchema[]",
|
|
201
|
-
"name": "",
|
|
202
|
-
"type": "tuple[]"
|
|
203
|
-
}
|
|
204
|
-
],
|
|
205
|
-
"stateMutability": "pure",
|
|
206
|
-
"type": "function"
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
"inputs": [],
|
|
210
|
-
"name": "getRolePermissions",
|
|
211
|
-
"outputs": [
|
|
212
|
-
{
|
|
213
|
-
"components": [
|
|
214
|
-
{
|
|
215
|
-
"internalType": "bytes32[]",
|
|
216
|
-
"name": "roleHashes",
|
|
217
|
-
"type": "bytes32[]"
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
"components": [
|
|
221
|
-
{
|
|
222
|
-
"internalType": "bytes4",
|
|
223
|
-
"name": "functionSelector",
|
|
224
|
-
"type": "bytes4"
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
"internalType": "uint16",
|
|
228
|
-
"name": "grantedActionsBitmap",
|
|
229
|
-
"type": "uint16"
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
"internalType": "bytes4[]",
|
|
233
|
-
"name": "handlerForSelectors",
|
|
234
|
-
"type": "bytes4[]"
|
|
235
|
-
}
|
|
236
|
-
],
|
|
237
|
-
"internalType": "struct EngineBlox.FunctionPermission[]",
|
|
238
|
-
"name": "functionPermissions",
|
|
239
|
-
"type": "tuple[]"
|
|
240
|
-
}
|
|
241
|
-
],
|
|
242
|
-
"internalType": "struct IDefinition.RolePermission",
|
|
243
|
-
"name": "",
|
|
244
|
-
"type": "tuple"
|
|
245
|
-
}
|
|
246
|
-
],
|
|
247
|
-
"stateMutability": "pure",
|
|
248
|
-
"type": "function"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
"inputs": [
|
|
252
|
-
{
|
|
253
|
-
"internalType": "bytes4",
|
|
254
|
-
"name": "interfaceId",
|
|
255
|
-
"type": "bytes4"
|
|
256
|
-
}
|
|
257
|
-
],
|
|
258
|
-
"name": "supportsInterface",
|
|
259
|
-
"outputs": [
|
|
260
|
-
{
|
|
261
|
-
"internalType": "bool",
|
|
262
|
-
"name": "",
|
|
263
|
-
"type": "bool"
|
|
264
|
-
}
|
|
265
|
-
],
|
|
266
|
-
"stateMutability": "pure",
|
|
267
|
-
"type": "function"
|
|
268
|
-
}
|
|
269
|
-
]
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
-
// Copyright (c) 2025 Particle Crypto Security
|
|
3
|
-
pragma solidity 0.8.33;
|
|
4
|
-
|
|
5
|
-
// ============ IMPORTS ============
|
|
6
|
-
|
|
7
|
-
// Import core components (relative paths within protocol repo)
|
|
8
|
-
import "../execution/GuardController.sol";
|
|
9
|
-
import "../access/RuntimeRBAC.sol";
|
|
10
|
-
import "../security/SecureOwnable.sol";
|
|
11
|
-
import "../base/BaseStateMachine.sol";
|
|
12
|
-
import "../lib/utils/SharedValidation.sol";
|
|
13
|
-
import "../lib/interfaces/IDefinition.sol";
|
|
14
|
-
|
|
15
|
-
// ============ CONTRACT DOCUMENTATION ============
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @title BloxchainWallet
|
|
19
|
-
* @dev Official ParticleCS wallet controller built on Bloxchain Protocol
|
|
20
|
-
*
|
|
21
|
-
* This contract is based on the ControlBlox template and combines:
|
|
22
|
-
* - GuardController: Execution workflows and time-locked transactions
|
|
23
|
-
* - RuntimeRBAC: Runtime role creation and management
|
|
24
|
-
* - SecureOwnable: Secure ownership transfer and management
|
|
25
|
-
*
|
|
26
|
-
* It serves as the core on-chain controller for the Bloxchain Wallet application.
|
|
27
|
-
*/
|
|
28
|
-
contract BloxchainWallet is GuardController, RuntimeRBAC, SecureOwnable {
|
|
29
|
-
// ============ CONSTANTS ============
|
|
30
|
-
|
|
31
|
-
/// @notice Minimum time lock period: 1 day (86400 seconds)
|
|
32
|
-
uint256 public constant MIN_TIME_LOCK_PERIOD = 1 days;
|
|
33
|
-
|
|
34
|
-
/// @notice Maximum time lock period: 90 days (7776000 seconds)
|
|
35
|
-
uint256 public constant MAX_TIME_LOCK_PERIOD = 90 days;
|
|
36
|
-
|
|
37
|
-
/// @notice Maximum number of definition contracts allowed during initialization (prevents gas exhaustion and DoS)
|
|
38
|
-
/// @dev Limits external calls to untrusted contracts during initialization
|
|
39
|
-
uint256 public constant MAX_DEFINITION_CONTRACTS = 50;
|
|
40
|
-
|
|
41
|
-
/// @notice Maximum number of roles allowed during initialization (prevents gas exhaustion and DoS)
|
|
42
|
-
/// @dev Limits role creation during initialization to prevent excessive gas consumption
|
|
43
|
-
uint256 public constant MAX_INITIAL_ROLES = 50;
|
|
44
|
-
|
|
45
|
-
/// @notice Maximum schemas per definition contract (prevents gas griefing from unbounded getFunctionSchemas())
|
|
46
|
-
uint256 public constant MAX_SCHEMAS_PER_DEFINITION = 100;
|
|
47
|
-
|
|
48
|
-
/// @notice Maximum permissions per definition contract (prevents gas griefing from unbounded getRolePermissions())
|
|
49
|
-
uint256 public constant MAX_PERMISSIONS_PER_DEFINITION = 200;
|
|
50
|
-
|
|
51
|
-
// ============ CUSTOM ERRORS ============
|
|
52
|
-
|
|
53
|
-
/// @dev Thrown when the same definition contract address appears more than once in the initialization array
|
|
54
|
-
// error DuplicateDefinitionContract(address definition);
|
|
55
|
-
|
|
56
|
-
/// @dev Thrown when an address does not implement the IDefinition interface (ERC165)
|
|
57
|
-
error DefinitionNotIDefinition(address definition);
|
|
58
|
-
|
|
59
|
-
// ============ EVENTS ============
|
|
60
|
-
|
|
61
|
-
/// @dev Emitted when ETH is received by the wallet (plain transfer or receive()).
|
|
62
|
-
/// @param from The address that sent the ETH
|
|
63
|
-
/// @param amount The amount of wei received
|
|
64
|
-
event EthReceived(address indexed from, uint256 amount);
|
|
65
|
-
|
|
66
|
-
// ============ STRUCTS ============
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @dev Struct to hold role configuration data for initialization
|
|
70
|
-
* @param roleName The name of the role (must be unique, non-empty)
|
|
71
|
-
* @param maxWallets Maximum number of wallets allowed for this role (must be > 0)
|
|
72
|
-
* @notice Function permissions are NOT included here - they must be added via definition contracts
|
|
73
|
-
* @notice This ensures function schemas exist before permissions are assigned to roles
|
|
74
|
-
* @notice Permissions should be added via definition contracts after roles are created
|
|
75
|
-
*/
|
|
76
|
-
struct RoleConfig {
|
|
77
|
-
string roleName;
|
|
78
|
-
uint256 maxWallets;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ============ INITIALIZATION FUNCTIONS ============
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @notice Initializer to configure the BloxchainWallet
|
|
85
|
-
* @param initialOwner The initial owner address
|
|
86
|
-
* @param broadcaster The broadcaster address
|
|
87
|
-
* @param recovery The recovery address
|
|
88
|
-
* @param timeLockPeriodSec The timelock period in seconds
|
|
89
|
-
* @param eventForwarder The event forwarder address (optional)
|
|
90
|
-
* @dev For proxy/clone deployments, the deployer should call in the same transaction as deployment.
|
|
91
|
-
*/
|
|
92
|
-
function initialize(
|
|
93
|
-
address initialOwner,
|
|
94
|
-
address broadcaster,
|
|
95
|
-
address recovery,
|
|
96
|
-
uint256 timeLockPeriodSec,
|
|
97
|
-
address eventForwarder
|
|
98
|
-
)
|
|
99
|
-
public
|
|
100
|
-
virtual
|
|
101
|
-
override(GuardController, RuntimeRBAC, SecureOwnable)
|
|
102
|
-
initializer
|
|
103
|
-
{
|
|
104
|
-
_initializeBase(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @notice Extended initializer with custom roles and definition contracts
|
|
109
|
-
* @param initialOwner The initial owner address
|
|
110
|
-
* @param broadcaster The broadcaster address
|
|
111
|
-
* @param recovery The recovery address
|
|
112
|
-
* @param timeLockPeriodSec The timelock period in seconds
|
|
113
|
-
* @param eventForwarder The event forwarder address (optional)
|
|
114
|
-
* @param roles Array of role configurations to create before loading definitions
|
|
115
|
-
* @param definitionContracts Array of definition contract addresses implementing IDefinition
|
|
116
|
-
* @dev Execution order:
|
|
117
|
-
* 1. Initialize base (loads RuntimeRBACDefinitions schemas and protected roles)
|
|
118
|
-
* 2. Create custom roles (roles are created with isProtected=false)
|
|
119
|
-
* 3. Load custom definitions (schemas first, then permissions added to existing roles)
|
|
120
|
-
* @dev All validation (protected schemas, duplicates, bounded sizes) is handled internally
|
|
121
|
-
* @custom:security-intentional No caller restriction: designed for clone-based factory initialization where the factory creates the clone and calls this initializer in the same transaction. The factory (or deployer) is the only caller; no window exists for front-running. Do not deploy instances without initializing atomically in the same transaction.
|
|
122
|
-
*/
|
|
123
|
-
function initializeWithRolesAndDefinitions(
|
|
124
|
-
address initialOwner,
|
|
125
|
-
address broadcaster,
|
|
126
|
-
address recovery,
|
|
127
|
-
uint256 timeLockPeriodSec,
|
|
128
|
-
address eventForwarder,
|
|
129
|
-
RoleConfig[] memory roles,
|
|
130
|
-
IDefinition[] memory definitionContracts
|
|
131
|
-
) public initializer {
|
|
132
|
-
// Initialize base (validates time lock period and initializes parent contracts)
|
|
133
|
-
// This also loads RuntimeRBACDefinitions schemas and creates protected roles (OWNER, BROADCASTER, RECOVERY)
|
|
134
|
-
_initializeBase(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
|
|
135
|
-
|
|
136
|
-
// Validate roles array length to prevent gas exhaustion and DoS attacks
|
|
137
|
-
if (roles.length > MAX_INITIAL_ROLES) {
|
|
138
|
-
revert SharedValidation.BatchSizeExceeded(roles.length, MAX_INITIAL_ROLES);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Create custom roles before loading definitions
|
|
142
|
-
for (uint256 i = 0; i < roles.length; i++) {
|
|
143
|
-
_createRole(roles[i].roleName, roles[i].maxWallets, false);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Validate definition contracts array length
|
|
147
|
-
if (definitionContracts.length > MAX_DEFINITION_CONTRACTS) {
|
|
148
|
-
revert SharedValidation.BatchSizeExceeded(definitionContracts.length, MAX_DEFINITION_CONTRACTS);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Load custom definitions from each definition contract (no duplicates, bounded sizes, allowProtectedSchemas=false)
|
|
152
|
-
for (uint256 i = 0; i < definitionContracts.length; i++) {
|
|
153
|
-
address def = address(definitionContracts[i]);
|
|
154
|
-
// SharedValidation.validateNotZeroAddress(def);
|
|
155
|
-
|
|
156
|
-
// Reject duplicate definition contract addresses
|
|
157
|
-
// note: this check and error can be removed as the protocol will handle duplicates
|
|
158
|
-
// for (uint256 j = 0; j < i; j++) {
|
|
159
|
-
// if (address(definitionContracts[j]) == def) revert DuplicateDefinitionContract(def);
|
|
160
|
-
// }
|
|
161
|
-
|
|
162
|
-
// This will be applicable in the next bloxchain update
|
|
163
|
-
// Require ERC165 IDefinition support for clearer errors and safety
|
|
164
|
-
if (!definitionContracts[i].supportsInterface(type(IDefinition).interfaceId)) {
|
|
165
|
-
revert DefinitionNotIDefinition(def);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
EngineBlox.FunctionSchema[] memory schemas = definitionContracts[i].getFunctionSchemas();
|
|
169
|
-
IDefinition.RolePermission memory permissions = definitionContracts[i].getRolePermissions();
|
|
170
|
-
|
|
171
|
-
if (schemas.length > MAX_SCHEMAS_PER_DEFINITION) {
|
|
172
|
-
revert SharedValidation.BatchSizeExceeded(schemas.length, MAX_SCHEMAS_PER_DEFINITION);
|
|
173
|
-
}
|
|
174
|
-
if (permissions.roleHashes.length > MAX_PERMISSIONS_PER_DEFINITION) {
|
|
175
|
-
revert SharedValidation.BatchSizeExceeded(permissions.roleHashes.length, MAX_PERMISSIONS_PER_DEFINITION);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// When using protocol version with allowProtectedSchemas parameter, pass false for custom definitions
|
|
179
|
-
_loadDefinitions(
|
|
180
|
-
schemas,
|
|
181
|
-
permissions.roleHashes,
|
|
182
|
-
permissions.functionPermissions,
|
|
183
|
-
false // Custom definitions must not be protected
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
// This will be applicable in the next bloxchain update
|
|
187
|
-
// _loadDefinitions(
|
|
188
|
-
// schemas,
|
|
189
|
-
// permissions.roleHashes,
|
|
190
|
-
// permissions.functionPermissions,
|
|
191
|
-
// false // Custom definitions must not be protected
|
|
192
|
-
// );
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ============ INTERFACE FUNCTIONS ============
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @dev See {IERC165-supportsInterface}.
|
|
200
|
-
*/
|
|
201
|
-
function supportsInterface(bytes4 interfaceId)
|
|
202
|
-
public
|
|
203
|
-
view
|
|
204
|
-
virtual
|
|
205
|
-
override(GuardController, RuntimeRBAC, SecureOwnable)
|
|
206
|
-
returns (bool)
|
|
207
|
-
{
|
|
208
|
-
return
|
|
209
|
-
GuardController.supportsInterface(interfaceId) ||
|
|
210
|
-
RuntimeRBAC.supportsInterface(interfaceId) ||
|
|
211
|
-
SecureOwnable.supportsInterface(interfaceId);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// ============ FALLBACK & RECEIVE FUNCTIONS ============
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @dev Accepts plain ETH transfers (no calldata).
|
|
218
|
-
* @notice General-use wallet: ETH can be sent naturally; balance is credited.
|
|
219
|
-
* @custom:security No external calls—reentrancy-safe; outgoing ETH only via GuardController execution.
|
|
220
|
-
*/
|
|
221
|
-
receive() external payable {
|
|
222
|
-
emit EthReceived(msg.sender, msg.value);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* @dev Rejects calls with unknown selector (with or without value).
|
|
227
|
-
* @notice Only plain transfers hit receive(); all other calls revert.
|
|
228
|
-
*/
|
|
229
|
-
fallback() external payable {
|
|
230
|
-
revert SharedValidation.NotSupported();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// ============ OVERRIDE FUNCTIONS ============
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @dev Updates the time lock period with validation.
|
|
237
|
-
* @param newTimeLockPeriodSec The new time lock period in seconds
|
|
238
|
-
* @notice Validates that the new time lock period is between MIN_TIME_LOCK_PERIOD and MAX_TIME_LOCK_PERIOD
|
|
239
|
-
*/
|
|
240
|
-
function _updateTimeLockPeriod(uint256 newTimeLockPeriodSec)
|
|
241
|
-
internal
|
|
242
|
-
virtual
|
|
243
|
-
override(BaseStateMachine)
|
|
244
|
-
{
|
|
245
|
-
_validateTimeLockPeriod(newTimeLockPeriodSec);
|
|
246
|
-
super._updateTimeLockPeriod(newTimeLockPeriodSec);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ============ INTERNAL FUNCTIONS ============
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @dev Internal function to initialize base state (common to all initialization paths)
|
|
253
|
-
* @param initialOwner The initial owner address
|
|
254
|
-
* @param broadcaster The broadcaster address
|
|
255
|
-
* @param recovery The recovery address
|
|
256
|
-
* @param timeLockPeriodSec The timelock period in seconds
|
|
257
|
-
* @param eventForwarder The event forwarder address (optional)
|
|
258
|
-
* @notice Validates time lock period and initializes all parent contracts
|
|
259
|
-
* @notice The guarded initialization ensures BaseStateMachine is only initialized once
|
|
260
|
-
*/
|
|
261
|
-
function _initializeBase(
|
|
262
|
-
address initialOwner,
|
|
263
|
-
address broadcaster,
|
|
264
|
-
address recovery,
|
|
265
|
-
uint256 timeLockPeriodSec,
|
|
266
|
-
address eventForwarder
|
|
267
|
-
) internal {
|
|
268
|
-
// Validate time lock period before initialization
|
|
269
|
-
_validateTimeLockPeriod(timeLockPeriodSec);
|
|
270
|
-
|
|
271
|
-
// Initialize all parent contracts.
|
|
272
|
-
// The guarded initialization ensures BaseStateMachine is only initialized once.
|
|
273
|
-
GuardController.initialize(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
|
|
274
|
-
RuntimeRBAC.initialize(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
|
|
275
|
-
SecureOwnable.initialize(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @dev Validates that a time lock period is within the allowed range
|
|
280
|
-
* @param timeLockPeriodSec The time lock period in seconds to validate
|
|
281
|
-
* @notice Reverts with InvalidTimeLockPeriod if the period is outside MIN_TIME_LOCK_PERIOD and MAX_TIME_LOCK_PERIOD
|
|
282
|
-
*/
|
|
283
|
-
function _validateTimeLockPeriod(uint256 timeLockPeriodSec) internal pure {
|
|
284
|
-
if (
|
|
285
|
-
timeLockPeriodSec < MIN_TIME_LOCK_PERIOD ||
|
|
286
|
-
timeLockPeriodSec > MAX_TIME_LOCK_PERIOD
|
|
287
|
-
) {
|
|
288
|
-
revert SharedValidation.InvalidTimeLockPeriod(timeLockPeriodSec);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|