@lukso/lsp-smart-contracts 0.8.1 → 0.9.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/README.md +14 -1
- package/artifacts/LSP0ERC725Account.json +51 -5
- package/artifacts/LSP0ERC725AccountInit.json +51 -5
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +31 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
- package/artifacts/LSP4Compatibility.json +7 -2
- package/artifacts/LSP4DigitalAssetMetadata.json +7 -2
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +7 -2
- package/artifacts/LSP6KeyManager.json +91 -6
- package/artifacts/LSP6KeyManagerInit.json +103 -18
- package/artifacts/LSP7CappedSupply.json +7 -2
- package/artifacts/LSP7CappedSupplyInitAbstract.json +7 -2
- package/artifacts/LSP7CompatibleERC20.json +7 -2
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +7 -2
- package/artifacts/LSP7CompatibleERC20Mintable.json +9 -4
- package/artifacts/LSP7CompatibleERC20MintableInit.json +9 -4
- package/artifacts/LSP7DigitalAsset.json +7 -2
- package/artifacts/LSP7DigitalAssetInitAbstract.json +7 -2
- package/artifacts/LSP7Mintable.json +9 -4
- package/artifacts/LSP7MintableInit.json +9 -4
- package/artifacts/LSP8CappedSupply.json +7 -2
- package/artifacts/LSP8CappedSupplyInitAbstract.json +7 -2
- package/artifacts/LSP8CompatibleERC721.json +7 -2
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +7 -2
- package/artifacts/LSP8CompatibleERC721Mintable.json +9 -4
- package/artifacts/LSP8CompatibleERC721MintableInit.json +9 -4
- package/artifacts/LSP8IdentifiableDigitalAsset.json +7 -2
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +7 -2
- package/artifacts/LSP8Mintable.json +9 -4
- package/artifacts/LSP8MintableInit.json +9 -4
- package/artifacts/LSP9Vault.json +29 -5
- package/artifacts/LSP9VaultInit.json +29 -5
- package/artifacts/UniversalProfile.json +51 -5
- package/artifacts/UniversalProfileInit.json +51 -5
- package/common/constants.d.ts +50 -327
- package/common/constants.js +21 -17
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +27 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +344 -195
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +47 -51
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -6
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +36 -77
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +50 -55
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -8
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
- package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +74 -0
- package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +50 -56
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6Constants.sol +8 -2
- package/contracts/LSP6KeyManager/LSP6Errors.sol +18 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +83 -12
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +277 -99
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +36 -9
- package/contracts/LSP6KeyManager/LSP6Utils.sol +30 -15
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +12 -17
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +12 -17
- package/contracts/LSP9Vault/ILSP9Vault.sol +19 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
- package/contracts/LSP9Vault/LSP9VaultCore.sol +81 -58
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
- package/module/constants.d.ts +50 -327
- package/module/constants.js +20 -16
- package/package.json +6 -4
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.5;
|
|
3
3
|
|
|
4
|
+
// interfaces
|
|
5
|
+
import {
|
|
6
|
+
ILSP20CallVerification as ILSP20
|
|
7
|
+
} from "../../LSP20CallVerification/ILSP20CallVerification.sol";
|
|
8
|
+
|
|
4
9
|
// modules
|
|
5
10
|
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
11
|
|
|
@@ -19,7 +24,11 @@ import {
|
|
|
19
24
|
_PERMISSION_STATICCALL,
|
|
20
25
|
_PERMISSION_SUPER_STATICCALL,
|
|
21
26
|
_PERMISSION_DELEGATECALL,
|
|
22
|
-
_PERMISSION_SUPER_DELEGATECALL
|
|
27
|
+
_PERMISSION_SUPER_DELEGATECALL,
|
|
28
|
+
_ALLOWEDCALLS_VALUE,
|
|
29
|
+
_ALLOWEDCALLS_WRITE,
|
|
30
|
+
_ALLOWEDCALLS_READ,
|
|
31
|
+
_ALLOWEDCALLS_EXECUTE
|
|
23
32
|
} from "../LSP6Constants.sol";
|
|
24
33
|
import {
|
|
25
34
|
OPERATION_0_CALL,
|
|
@@ -36,7 +45,9 @@ import {
|
|
|
36
45
|
NotAllowedCall,
|
|
37
46
|
InvalidEncodedAllowedCalls,
|
|
38
47
|
InvalidWhitelistedCall,
|
|
39
|
-
NotAuthorised
|
|
48
|
+
NotAuthorised,
|
|
49
|
+
InvalidPayload,
|
|
50
|
+
CallingKeyManagerNotAllowed
|
|
40
51
|
} from "../LSP6Errors.sol";
|
|
41
52
|
|
|
42
53
|
abstract contract LSP6ExecuteModule {
|
|
@@ -46,80 +57,156 @@ abstract contract LSP6ExecuteModule {
|
|
|
46
57
|
/**
|
|
47
58
|
* @dev verify if `controllerAddress` has the required permissions to interact with other addresses using the controlledContract.
|
|
48
59
|
* @param controlledContract the address of the ERC725 contract where the payload is executed and where the permissions are verified.
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
60
|
+
* @param controller the address who want to run the execute function on the ERC725Account.
|
|
61
|
+
* @param permissions the permissions of the controller address.
|
|
51
62
|
* @param payload the ABI encoded payload `controlledContract.execute(...)`.
|
|
52
63
|
*/
|
|
53
64
|
function _verifyCanExecute(
|
|
54
65
|
address controlledContract,
|
|
55
|
-
address
|
|
56
|
-
bytes32
|
|
66
|
+
address controller,
|
|
67
|
+
bytes32 permissions,
|
|
57
68
|
bytes calldata payload
|
|
58
69
|
) internal view virtual {
|
|
70
|
+
// CHECK the offset of `data` is not pointing to the previous parameters
|
|
71
|
+
if (
|
|
72
|
+
bytes32(payload[100:132]) !=
|
|
73
|
+
0x0000000000000000000000000000000000000000000000000000000000000080
|
|
74
|
+
) {
|
|
75
|
+
revert InvalidPayload(payload);
|
|
76
|
+
}
|
|
77
|
+
|
|
59
78
|
// MUST be one of the ERC725X operation types.
|
|
60
79
|
uint256 operationType = uint256(bytes32(payload[4:36]));
|
|
61
80
|
|
|
62
|
-
|
|
81
|
+
address to = address(bytes20(payload[48:68]));
|
|
82
|
+
|
|
83
|
+
// if to is the KeyManager address revert
|
|
84
|
+
if (to == address(this)) {
|
|
85
|
+
revert CallingKeyManagerNotAllowed();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Future versions of the KeyManager willing to allow LSP0 to call the KeyManager
|
|
89
|
+
// may need to implement this check to avoid inconsistent state of reentrancy
|
|
90
|
+
// that may lead to lock the use of the KeyManager
|
|
91
|
+
|
|
92
|
+
// Check to restrict controllers with execute permissions to call lsp20 functions
|
|
93
|
+
// to avoid setting the reentrancy guard to a non-valid state
|
|
94
|
+
|
|
95
|
+
// if (payload.length >= 168 && to == address(this)) {
|
|
96
|
+
// if (
|
|
97
|
+
// bytes4(payload[164:168]) == ILSP20.lsp20VerifyCall.selector ||
|
|
98
|
+
// bytes4(payload[164:168]) == ILSP20.lsp20VerifyCallResult.selector
|
|
99
|
+
// ) {
|
|
100
|
+
// revert CallingLSP20FunctionsOnLSP6NotAllowed();
|
|
101
|
+
// }
|
|
102
|
+
// }
|
|
103
|
+
|
|
104
|
+
// if it is a message call
|
|
105
|
+
if (operationType == OPERATION_0_CALL) {
|
|
106
|
+
return _verifyCanCall(controlledContract, controller, permissions, payload);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// if it is a contract creation
|
|
110
|
+
if (operationType == OPERATION_1_CREATE || operationType == OPERATION_2_CREATE2) {
|
|
111
|
+
// required to check for permission TRANSFERVALUE if we are funding
|
|
112
|
+
// the contract on deployment via a payable constructor
|
|
113
|
+
bool isFundingContract = uint256(bytes32(payload[68:100])) != 0;
|
|
114
|
+
|
|
115
|
+
return _verifyCanDeployContract(controller, permissions, isFundingContract);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// if it is a STATICALL
|
|
119
|
+
// we do not check for TRANSFERVALUE permission,
|
|
120
|
+
// as ERC725X will revert if a value is provided with operation type STATICCALL.
|
|
121
|
+
if (operationType == OPERATION_3_STATICCALL) {
|
|
122
|
+
return _verifyCanStaticCall(controlledContract, controller, permissions, payload);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// DELEGATECALL is disallowed by default on the Key Manager.
|
|
63
126
|
if (operationType == OPERATION_4_DELEGATECALL) {
|
|
64
127
|
revert DelegateCallDisallowedViaKeyManager();
|
|
65
128
|
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function _verifyCanDeployContract(
|
|
132
|
+
address controller,
|
|
133
|
+
bytes32 permissions,
|
|
134
|
+
bool isFundingContract
|
|
135
|
+
) internal view virtual {
|
|
136
|
+
_requirePermissions(controller, permissions, _PERMISSION_DEPLOY);
|
|
137
|
+
|
|
138
|
+
bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
|
|
139
|
+
|
|
140
|
+
// CHECK if we are funding the contract
|
|
141
|
+
if (isFundingContract && !hasSuperTransferValue) {
|
|
142
|
+
revert NotAuthorised(controller, "SUPER_TRANSFERVALUE");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function _verifyCanStaticCall(
|
|
147
|
+
address controlledContract,
|
|
148
|
+
address controller,
|
|
149
|
+
bytes32 permissions,
|
|
150
|
+
bytes calldata payload
|
|
151
|
+
) internal view virtual {
|
|
152
|
+
bool hasSuperStaticCall = permissions.hasPermission(_PERMISSION_SUPER_STATICCALL);
|
|
66
153
|
|
|
67
|
-
|
|
154
|
+
// Skip if caller has SUPER permission for static calls
|
|
155
|
+
if (hasSuperStaticCall) return;
|
|
68
156
|
|
|
69
|
-
|
|
70
|
-
|
|
157
|
+
_requirePermissions(controller, permissions, _PERMISSION_STATICCALL);
|
|
158
|
+
|
|
159
|
+
_verifyAllowedCall(controlledContract, controller, payload);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function _verifyCanCall(
|
|
163
|
+
address controlledContract,
|
|
164
|
+
address controller,
|
|
165
|
+
bytes32 permissions,
|
|
166
|
+
bytes calldata payload
|
|
167
|
+
) internal view virtual {
|
|
168
|
+
bool isTransferringValue = uint256(bytes32(payload[68:100])) != 0;
|
|
169
|
+
|
|
170
|
+
bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
|
|
171
|
+
|
|
172
|
+
// all the parameters are abi-encoded (padded to 32 bytes words)
|
|
173
|
+
//
|
|
174
|
+
// 4 (ERC725X.execute selector)
|
|
175
|
+
// + 32 (uint256 operationType)
|
|
176
|
+
// + 32 (address to/target)
|
|
177
|
+
// + 32 (uint256 value)
|
|
178
|
+
// + 32 (`data` offset)
|
|
179
|
+
// + 32 (`data` length)
|
|
180
|
+
// --------------------
|
|
181
|
+
// = 164 bytes in total
|
|
71
182
|
bool isCallDataPresent = payload.length > 164;
|
|
72
183
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
184
|
+
bool hasSuperCall = permissions.hasPermission(_PERMISSION_SUPER_CALL);
|
|
185
|
+
|
|
186
|
+
if (isTransferringValue && !hasSuperTransferValue) {
|
|
187
|
+
_requirePermissions(controller, permissions, _PERMISSION_TRANSFERVALUE);
|
|
188
|
+
}
|
|
79
189
|
|
|
80
190
|
// CHECK if we are doing an empty call, as the receive() or fallback() function
|
|
81
191
|
// of the controlledContract could run some code.
|
|
82
|
-
if (!
|
|
83
|
-
_requirePermissions(
|
|
84
|
-
controllerAddress,
|
|
85
|
-
controllerPermissions,
|
|
86
|
-
_extractPermissionFromOperation(operationType)
|
|
87
|
-
);
|
|
192
|
+
if (!hasSuperCall && !isCallDataPresent && !isTransferringValue) {
|
|
193
|
+
_requirePermissions(controller, permissions, _PERMISSION_CALL);
|
|
88
194
|
}
|
|
89
195
|
|
|
90
|
-
if (isCallDataPresent && !
|
|
91
|
-
_requirePermissions(
|
|
92
|
-
controllerAddress,
|
|
93
|
-
controllerPermissions,
|
|
94
|
-
_extractPermissionFromOperation(operationType)
|
|
95
|
-
);
|
|
196
|
+
if (isCallDataPresent && !hasSuperCall) {
|
|
197
|
+
_requirePermissions(controller, permissions, _PERMISSION_CALL);
|
|
96
198
|
}
|
|
97
199
|
|
|
98
|
-
bool hasSuperTransferValue = controllerPermissions.hasPermission(
|
|
99
|
-
_PERMISSION_SUPER_TRANSFERVALUE
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
if (value != 0 && !hasSuperTransferValue) {
|
|
103
|
-
_requirePermissions(
|
|
104
|
-
controllerAddress,
|
|
105
|
-
controllerPermissions,
|
|
106
|
-
_PERMISSION_TRANSFERVALUE
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Skip on contract creation (CREATE or CREATE2)
|
|
111
|
-
if (isContractCreation) return;
|
|
112
|
-
|
|
113
200
|
// Skip if caller has SUPER permissions for external calls, with or without calldata (empty calls)
|
|
114
|
-
if (
|
|
201
|
+
if (hasSuperCall && !isTransferringValue) return;
|
|
115
202
|
|
|
116
203
|
// Skip if caller has SUPER permission for value transfers
|
|
117
|
-
if (hasSuperTransferValue && !isCallDataPresent &&
|
|
204
|
+
if (hasSuperTransferValue && !isCallDataPresent && isTransferringValue) return;
|
|
118
205
|
|
|
119
206
|
// Skip if both SUPER permissions are present
|
|
120
|
-
if (
|
|
207
|
+
if (hasSuperCall && hasSuperTransferValue) return;
|
|
121
208
|
|
|
122
|
-
_verifyAllowedCall(controlledContract,
|
|
209
|
+
_verifyAllowedCall(controlledContract, controller, payload);
|
|
123
210
|
}
|
|
124
211
|
|
|
125
212
|
function _verifyAllowedCall(
|
|
@@ -127,87 +214,178 @@ abstract contract LSP6ExecuteModule {
|
|
|
127
214
|
address controllerAddress,
|
|
128
215
|
bytes calldata payload
|
|
129
216
|
) internal view virtual {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
217
|
+
(
|
|
218
|
+
uint256 operationType,
|
|
219
|
+
address to,
|
|
220
|
+
uint256 value,
|
|
221
|
+
bytes4 selector
|
|
222
|
+
) = _extractExecuteParameters(payload);
|
|
136
223
|
|
|
224
|
+
// CHECK for ALLOWED CALLS
|
|
137
225
|
bytes memory allowedCalls = ERC725Y(controlledContract).getAllowedCallsFor(
|
|
138
226
|
controllerAddress
|
|
139
227
|
);
|
|
140
|
-
uint256 allowedCallsLength = allowedCalls.length;
|
|
141
228
|
|
|
142
|
-
if (
|
|
229
|
+
if (allowedCalls.length == 0) {
|
|
143
230
|
revert NoCallsAllowed(controllerAddress);
|
|
144
231
|
}
|
|
145
232
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
233
|
+
bytes4 requiredCallTypes = _extractCallType(operationType, selector, value);
|
|
234
|
+
|
|
235
|
+
for (uint256 ii; ii < allowedCalls.length; ii += 34) {
|
|
236
|
+
/// @dev structure of an AllowedCall
|
|
237
|
+
//
|
|
238
|
+
/// AllowedCall = 0x00200000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
239
|
+
///
|
|
240
|
+
/// 0020 = hex for '32' bytes long
|
|
241
|
+
/// 0000000n = call type(s)
|
|
242
|
+
/// cafecafecafecafecafecafecafecafecafecafe = address
|
|
243
|
+
/// 5a5a5a5a = standard
|
|
244
|
+
/// f1f1f1f1 = function
|
|
245
|
+
|
|
246
|
+
// CHECK that we can extract an AllowedCall
|
|
247
|
+
if (ii + 34 > allowedCalls.length) {
|
|
152
248
|
revert InvalidEncodedAllowedCalls(allowedCalls);
|
|
153
249
|
}
|
|
154
|
-
bytes memory chunk = BytesLib.slice(allowedCalls, ii + 2, 28);
|
|
155
250
|
|
|
156
|
-
|
|
251
|
+
// extract one AllowedCall at a time
|
|
252
|
+
bytes memory allowedCall = BytesLib.slice(allowedCalls, ii + 2, 32);
|
|
253
|
+
|
|
254
|
+
// 0xxxxxxxxxffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
255
|
+
// (excluding the callTypes) not allowed
|
|
256
|
+
// as equivalent to whitelisting any call (= SUPER permission)
|
|
257
|
+
if (bytes28(bytes32(allowedCall) << 32) == bytes28(type(uint224).max)) {
|
|
157
258
|
revert InvalidWhitelistedCall(controllerAddress);
|
|
158
259
|
}
|
|
159
260
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
to.supportsERC165InterfaceUnchecked(allowedStandard);
|
|
167
|
-
isAllowedAddress =
|
|
168
|
-
allowedAddress == 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF ||
|
|
169
|
-
to == allowedAddress;
|
|
170
|
-
isAllowedFunction =
|
|
171
|
-
allowedFunction == 0xffffffff ||
|
|
172
|
-
(containsFunctionCall && (selector == allowedFunction));
|
|
173
|
-
|
|
174
|
-
if (isAllowedStandard && isAllowedAddress && isAllowedFunction) return;
|
|
261
|
+
if (
|
|
262
|
+
_isAllowedCallType(allowedCall, requiredCallTypes) &&
|
|
263
|
+
_isAllowedAddress(allowedCall, to) &&
|
|
264
|
+
_isAllowedStandard(allowedCall, to) &&
|
|
265
|
+
_isAllowedFunction(allowedCall, selector)
|
|
266
|
+
) return;
|
|
175
267
|
}
|
|
176
268
|
|
|
177
269
|
revert NotAllowedCall(controllerAddress, to, selector);
|
|
178
270
|
}
|
|
179
271
|
|
|
180
272
|
/**
|
|
181
|
-
* @dev extract the
|
|
182
|
-
*
|
|
183
|
-
* @
|
|
184
|
-
* @return permissionsRequired (bytes32) the permission associated with the `_operationType`
|
|
273
|
+
* @dev extract the bytes4 representation of a single bit for the type of call according to the `operationType`
|
|
274
|
+
* @param operationType 0 = CALL, 3 = STATICCALL or 3 = DELEGATECALL
|
|
275
|
+
* @return a bytes4 value containing a single 1 bit for the callType
|
|
185
276
|
*/
|
|
186
|
-
function
|
|
277
|
+
function _extractCallType(
|
|
278
|
+
uint256 operationType,
|
|
279
|
+
bytes4 selector,
|
|
280
|
+
uint256 value
|
|
281
|
+
) internal pure returns (bytes4) {
|
|
282
|
+
bytes4 requiredCallTypes;
|
|
283
|
+
|
|
284
|
+
if (operationType == OPERATION_0_CALL) {
|
|
285
|
+
if (
|
|
286
|
+
// CHECK if we are doing an empty call
|
|
287
|
+
(selector == bytes4(0) && value == 0) ||
|
|
288
|
+
// we do not require callType CALL
|
|
289
|
+
// if we are just transferring value without `data`
|
|
290
|
+
selector != bytes4(0)
|
|
291
|
+
) {
|
|
292
|
+
requiredCallTypes = _ALLOWEDCALLS_WRITE;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (operationType == OPERATION_3_STATICCALL) requiredCallTypes = _ALLOWEDCALLS_READ;
|
|
297
|
+
if (operationType == OPERATION_4_DELEGATECALL) requiredCallTypes = _ALLOWEDCALLS_EXECUTE;
|
|
298
|
+
|
|
299
|
+
// if there is value being transferred, add the extra bit
|
|
300
|
+
// for the first bit for Value Transfer in the `requiredCallTypes`
|
|
301
|
+
if (value != 0) {
|
|
302
|
+
requiredCallTypes |= _ALLOWEDCALLS_VALUE;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return requiredCallTypes;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function _extractExecuteParameters(bytes calldata executeCalldata)
|
|
187
309
|
internal
|
|
188
310
|
pure
|
|
189
|
-
|
|
190
|
-
|
|
311
|
+
returns (
|
|
312
|
+
uint256,
|
|
313
|
+
address,
|
|
314
|
+
uint256,
|
|
315
|
+
bytes4
|
|
316
|
+
)
|
|
191
317
|
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
318
|
+
uint256 operationType = uint256(bytes32(executeCalldata[4:36]));
|
|
319
|
+
address to = address(bytes20(executeCalldata[48:68]));
|
|
320
|
+
uint256 value = uint256(bytes32(executeCalldata[68:100]));
|
|
321
|
+
|
|
322
|
+
// CHECK if there is at least a 4 bytes function selector
|
|
323
|
+
bytes4 selector = executeCalldata.length >= 168
|
|
324
|
+
? bytes4(executeCalldata[164:168])
|
|
325
|
+
: bytes4(0);
|
|
326
|
+
|
|
327
|
+
return (operationType, to, value, selector);
|
|
197
328
|
}
|
|
198
329
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
330
|
+
function _isAllowedAddress(bytes memory allowedCall, address to) internal pure returns (bool) {
|
|
331
|
+
// <offset> = 4 bytes x 8 bits = 32 bits
|
|
332
|
+
//
|
|
333
|
+
// <offset>v----------------address---------------v
|
|
334
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
335
|
+
address allowedAddress = address(bytes20(bytes32(allowedCall) << 32));
|
|
336
|
+
|
|
337
|
+
// ANY address = 0xffffffffffffffffffffffffffffffffffffffff
|
|
338
|
+
return allowedAddress == address(bytes20(type(uint160).max)) || to == allowedAddress;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function _isAllowedStandard(bytes memory allowedCall, address to) internal view returns (bool) {
|
|
342
|
+
// <offset> = 24 bytes x 8 bits = 192 bits
|
|
343
|
+
//
|
|
344
|
+
// standard
|
|
345
|
+
// <----------------<offset>---------------------->v------v
|
|
346
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
347
|
+
bytes4 allowedStandard = bytes4(bytes32(allowedCall) << 192);
|
|
348
|
+
|
|
349
|
+
// ANY Standard = 0xffffffff
|
|
350
|
+
return
|
|
351
|
+
allowedStandard == bytes4(type(uint32).max) ||
|
|
352
|
+
to.supportsERC165InterfaceUnchecked(allowedStandard);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function _isAllowedFunction(bytes memory allowedCall, bytes4 requiredFunction)
|
|
356
|
+
internal
|
|
357
|
+
pure
|
|
358
|
+
returns (bool)
|
|
359
|
+
{
|
|
360
|
+
// <offset> = 28 bytes x 8 bits = 224 bits
|
|
361
|
+
//
|
|
362
|
+
// function
|
|
363
|
+
// <------------------------<offset>---------------------->v------v
|
|
364
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
365
|
+
bytes4 allowedFunction = bytes4(bytes32(allowedCall) << 224);
|
|
366
|
+
|
|
367
|
+
bool isFunctionCall = requiredFunction != bytes4(0);
|
|
368
|
+
|
|
369
|
+
// ANY function = 0xffffffff
|
|
370
|
+
return
|
|
371
|
+
allowedFunction == bytes4(type(uint32).max) ||
|
|
372
|
+
(isFunctionCall && (requiredFunction == allowedFunction));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function _isAllowedCallType(bytes memory allowedCall, bytes4 requiredCallTypes)
|
|
203
376
|
internal
|
|
204
377
|
pure
|
|
205
|
-
|
|
206
|
-
returns (bytes32 superPermission)
|
|
378
|
+
returns (bool)
|
|
207
379
|
{
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
380
|
+
// extract callType
|
|
381
|
+
//
|
|
382
|
+
// <offset> = 0
|
|
383
|
+
//
|
|
384
|
+
// callType
|
|
385
|
+
// v------v
|
|
386
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
387
|
+
bytes4 allowedCallType = bytes4(allowedCall);
|
|
388
|
+
return (allowedCallType & requiredCallTypes == requiredCallTypes);
|
|
211
389
|
}
|
|
212
390
|
|
|
213
391
|
/**
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
_PERMISSION_SETDATA,
|
|
20
20
|
_PERMISSION_SUPER_SETDATA,
|
|
21
21
|
_PERMISSION_ADDCONTROLLER,
|
|
22
|
-
|
|
22
|
+
_PERMISSION_EDITPERMISSIONS,
|
|
23
23
|
_PERMISSION_ADDEXTENSIONS,
|
|
24
24
|
_PERMISSION_CHANGEEXTENSIONS,
|
|
25
25
|
_PERMISSION_ADDUNIVERSALRECEIVERDELEGATE,
|
|
@@ -238,12 +238,12 @@ abstract contract LSP6SetDataModule {
|
|
|
238
238
|
|
|
239
239
|
// AddressPermissions[] -> array length
|
|
240
240
|
if (inputDataKey == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
|
|
241
|
-
|
|
241
|
+
uint128 newLength = uint128(bytes16(inputDataValue));
|
|
242
242
|
|
|
243
243
|
return
|
|
244
|
-
newLength >
|
|
244
|
+
newLength > uint128(bytes16(currentValue))
|
|
245
245
|
? _PERMISSION_ADDCONTROLLER
|
|
246
|
-
:
|
|
246
|
+
: _PERMISSION_EDITPERMISSIONS;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
// AddressPermissions[index] -> array index
|
|
@@ -253,7 +253,7 @@ abstract contract LSP6SetDataModule {
|
|
|
253
253
|
revert AddressPermissionArrayIndexValueNotAnAddress(inputDataKey, inputDataValue);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
return currentValue.length == 0 ? _PERMISSION_ADDCONTROLLER :
|
|
256
|
+
return currentValue.length == 0 ? _PERMISSION_ADDCONTROLLER : _PERMISSION_EDITPERMISSIONS;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
/**
|
|
@@ -271,7 +271,7 @@ abstract contract LSP6SetDataModule {
|
|
|
271
271
|
// if there are already some permissions set under the data key, we are trying to CHANGE the permissions of a controller.
|
|
272
272
|
bytes32(ERC725Y(controlledContract).getData(inputPermissionDataKey)) == bytes32(0)
|
|
273
273
|
? _PERMISSION_ADDCONTROLLER
|
|
274
|
-
:
|
|
274
|
+
: _PERMISSION_EDITPERMISSIONS;
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
/**
|
|
@@ -298,7 +298,7 @@ abstract contract LSP6SetDataModule {
|
|
|
298
298
|
return
|
|
299
299
|
ERC725Y(controlledContract).getData(dataKey).length == 0
|
|
300
300
|
? _PERMISSION_ADDCONTROLLER
|
|
301
|
-
:
|
|
301
|
+
: _PERMISSION_EDITPERMISSIONS;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
/**
|
|
@@ -314,7 +314,10 @@ abstract contract LSP6SetDataModule {
|
|
|
314
314
|
bytes memory dataValue
|
|
315
315
|
) internal view returns (bytes32) {
|
|
316
316
|
if (!LSP6Utils.isCompactBytesArrayOfAllowedERC725YDataKeys(dataValue)) {
|
|
317
|
-
revert InvalidEncodedAllowedERC725YDataKeys(
|
|
317
|
+
revert InvalidEncodedAllowedERC725YDataKeys(
|
|
318
|
+
dataValue,
|
|
319
|
+
"couldn't VALIDATE the data value"
|
|
320
|
+
);
|
|
318
321
|
}
|
|
319
322
|
|
|
320
323
|
// if there is nothing stored under the Allowed ERC725Y Data Keys of the controller,
|
|
@@ -325,7 +328,7 @@ abstract contract LSP6SetDataModule {
|
|
|
325
328
|
return
|
|
326
329
|
ERC725Y(controlledContract).getData(dataKey).length == 0
|
|
327
330
|
? _PERMISSION_ADDCONTROLLER
|
|
328
|
-
:
|
|
331
|
+
: _PERMISSION_EDITPERMISSIONS;
|
|
329
332
|
}
|
|
330
333
|
|
|
331
334
|
/**
|
|
@@ -414,6 +417,18 @@ abstract contract LSP6SetDataModule {
|
|
|
414
417
|
)
|
|
415
418
|
);
|
|
416
419
|
|
|
420
|
+
/**
|
|
421
|
+
* The length of a data key is 32 bytes.
|
|
422
|
+
* Therefore we can have a fixed allowed data key which has
|
|
423
|
+
* a length of 32 bytes or we can have a dynamic data key
|
|
424
|
+
* which can have a length of up to 31 bytes.
|
|
425
|
+
*/
|
|
426
|
+
if (length > 32)
|
|
427
|
+
revert InvalidEncodedAllowedERC725YDataKeys(
|
|
428
|
+
allowedERC725YDataKeysCompacted,
|
|
429
|
+
"couldn't DECODE from storage"
|
|
430
|
+
);
|
|
431
|
+
|
|
417
432
|
/**
|
|
418
433
|
* The bitmask discard the last `32 - length` bytes of the input data key via ANDing &
|
|
419
434
|
* It is used to compare only the relevant parts of each input data key against dynamic allowed data keys.
|
|
@@ -519,6 +534,18 @@ abstract contract LSP6SetDataModule {
|
|
|
519
534
|
)
|
|
520
535
|
);
|
|
521
536
|
|
|
537
|
+
/**
|
|
538
|
+
* The length of a data key is 32 bytes.
|
|
539
|
+
* Therefore we can have a fixed allowed data key which has
|
|
540
|
+
* a length of 32 bytes or we can have a dynamic data key
|
|
541
|
+
* which can have a length of up to 31 bytes.
|
|
542
|
+
*/
|
|
543
|
+
if (length > 32)
|
|
544
|
+
revert InvalidEncodedAllowedERC725YDataKeys(
|
|
545
|
+
allowedERC725YDataKeysCompacted,
|
|
546
|
+
"couldn't DECODE from storage"
|
|
547
|
+
);
|
|
548
|
+
|
|
522
549
|
/**
|
|
523
550
|
* The bitmask discard the last `32 - length` bytes of the input data key via ANDing &
|
|
524
551
|
* It is used to compare only the relevant parts of each input data key against dynamic allowed data keys.
|
|
@@ -107,8 +107,8 @@ library LSP6Utils {
|
|
|
107
107
|
)
|
|
108
108
|
)
|
|
109
109
|
);
|
|
110
|
-
// each entries in the allowedCalls (compact) array must be
|
|
111
|
-
if (elementLength !=
|
|
110
|
+
// each entries in the allowedCalls (compact) array must be 32 bytes long
|
|
111
|
+
if (elementLength != 32) return false;
|
|
112
112
|
pointer += elementLength + 2;
|
|
113
113
|
}
|
|
114
114
|
if (pointer == allowedCallsCompacted.length) return true;
|
|
@@ -162,40 +162,55 @@ library LSP6Utils {
|
|
|
162
162
|
/**
|
|
163
163
|
* @dev combine multiple permissions into a single bytes32
|
|
164
164
|
* Make sure that the sum of the values of the input array is less than 2^256-1 to avoid overflow.
|
|
165
|
-
* @param
|
|
165
|
+
* @param permissions the array of permissions to combine
|
|
166
166
|
* @return a bytes32 containing the combined permissions
|
|
167
167
|
*/
|
|
168
|
-
function combinePermissions(bytes32[] memory
|
|
168
|
+
function combinePermissions(bytes32[] memory permissions) internal pure returns (bytes32) {
|
|
169
169
|
uint256 result = 0;
|
|
170
|
-
for (uint256 i = 0; i <
|
|
171
|
-
result += uint256(
|
|
170
|
+
for (uint256 i = 0; i < permissions.length; i++) {
|
|
171
|
+
result += uint256(permissions[i]);
|
|
172
172
|
}
|
|
173
173
|
return bytes32(result);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
/**
|
|
177
|
+
* @dev Generate a new set of 3 x LSP6 permission data keys to add a new `controller` on `account`
|
|
178
|
+
* @param account the ERC725Y contract to add the controller into (used to fetch the `LSP6Permissions[]` length)
|
|
179
|
+
* @param controller the address of the controller to grant permissions to
|
|
180
|
+
* @param permissions the BitArray of permissions to grant to the controller
|
|
181
|
+
* @return keys an array of 3 x data keys containing:
|
|
182
|
+
* - keys[0] = `AddressPermissions[]` (array length)
|
|
183
|
+
* - keys[1] = `AddressPermissions[index]` (where to store the controller address)
|
|
184
|
+
* - keys[2] = `AddressPermissions:Permissions:<controller>`
|
|
185
|
+
*
|
|
186
|
+
* @return values : an array of 3 x data values containing:
|
|
187
|
+
* - values[0] = the new array length of `AddressPermissions[]`
|
|
188
|
+
* - values[1] = the address of the controller
|
|
189
|
+
* - values[2] = the `permissions` passed as param
|
|
190
|
+
*/
|
|
191
|
+
function generateNewPermissionsKeys(
|
|
192
|
+
IERC725Y account,
|
|
193
|
+
address controller,
|
|
179
194
|
bytes32 permissions
|
|
180
195
|
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
181
196
|
keys = new bytes32[](3);
|
|
182
197
|
values = new bytes[](3);
|
|
183
198
|
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
uint128 arrayLength = uint128(bytes16(account.getData(_LSP6KEY_ADDRESSPERMISSIONS_ARRAY)));
|
|
200
|
+
uint128 newArrayLength = arrayLength + 1;
|
|
186
201
|
|
|
187
202
|
keys[0] = _LSP6KEY_ADDRESSPERMISSIONS_ARRAY;
|
|
188
203
|
values[0] = abi.encodePacked(newArrayLength);
|
|
189
204
|
|
|
190
205
|
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
191
206
|
_LSP6KEY_ADDRESSPERMISSIONS_ARRAY,
|
|
192
|
-
|
|
207
|
+
arrayLength
|
|
193
208
|
);
|
|
194
|
-
values[1] = abi.encodePacked(
|
|
209
|
+
values[1] = abi.encodePacked(controller);
|
|
195
210
|
|
|
196
211
|
keys[2] = LSP2Utils.generateMappingWithGroupingKey(
|
|
197
212
|
_LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX,
|
|
198
|
-
bytes20(
|
|
213
|
+
bytes20(controller)
|
|
199
214
|
);
|
|
200
215
|
values[2] = abi.encodePacked(permissions);
|
|
201
216
|
}
|
|
@@ -209,7 +224,7 @@ library LSP6Utils {
|
|
|
209
224
|
returns (string memory errorMessage)
|
|
210
225
|
{
|
|
211
226
|
if (permission == _PERMISSION_CHANGEOWNER) return "TRANSFEROWNERSHIP";
|
|
212
|
-
if (permission ==
|
|
227
|
+
if (permission == _PERMISSION_EDITPERMISSIONS) return "EDITPERMISSIONS";
|
|
213
228
|
if (permission == _PERMISSION_ADDCONTROLLER) return "ADDCONTROLLER";
|
|
214
229
|
if (permission == _PERMISSION_ADDEXTENSIONS) return "ADDEXTENSIONS";
|
|
215
230
|
if (permission == _PERMISSION_CHANGEEXTENSIONS) return "CHANGEEXTENSIONS";
|