@lukso/lsp-smart-contracts 0.8.0 → 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.
Files changed (81) hide show
  1. package/CONTRIBUTING.md +8 -0
  2. package/README.md +34 -21
  3. package/artifacts/LSP0ERC725Account.json +51 -5
  4. package/artifacts/LSP0ERC725AccountInit.json +51 -5
  5. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  6. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  7. package/artifacts/LSP16UniversalFactory.json +31 -2
  8. package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
  9. package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
  10. package/artifacts/LSP4Compatibility.json +7 -2
  11. package/artifacts/LSP4DigitalAssetMetadata.json +7 -2
  12. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +7 -2
  13. package/artifacts/LSP6KeyManager.json +91 -6
  14. package/artifacts/LSP6KeyManagerInit.json +103 -18
  15. package/artifacts/LSP7CappedSupply.json +12 -2
  16. package/artifacts/LSP7CappedSupplyInitAbstract.json +12 -2
  17. package/artifacts/LSP7CompatibleERC20.json +12 -2
  18. package/artifacts/LSP7CompatibleERC20InitAbstract.json +12 -2
  19. package/artifacts/LSP7CompatibleERC20Mintable.json +14 -4
  20. package/artifacts/LSP7CompatibleERC20MintableInit.json +14 -4
  21. package/artifacts/LSP7DigitalAsset.json +12 -2
  22. package/artifacts/LSP7DigitalAssetInitAbstract.json +12 -2
  23. package/artifacts/LSP7Mintable.json +14 -4
  24. package/artifacts/LSP7MintableInit.json +14 -4
  25. package/artifacts/LSP8CappedSupply.json +12 -2
  26. package/artifacts/LSP8CappedSupplyInitAbstract.json +12 -2
  27. package/artifacts/LSP8CompatibleERC721.json +12 -2
  28. package/artifacts/LSP8CompatibleERC721InitAbstract.json +12 -2
  29. package/artifacts/LSP8CompatibleERC721Mintable.json +14 -4
  30. package/artifacts/LSP8CompatibleERC721MintableInit.json +14 -4
  31. package/artifacts/LSP8IdentifiableDigitalAsset.json +12 -2
  32. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +12 -2
  33. package/artifacts/LSP8Mintable.json +14 -4
  34. package/artifacts/LSP8MintableInit.json +14 -4
  35. package/artifacts/LSP9Vault.json +29 -5
  36. package/artifacts/LSP9VaultInit.json +29 -5
  37. package/artifacts/UniversalProfile.json +51 -5
  38. package/artifacts/UniversalProfileInit.json +51 -5
  39. package/common/constants.d.ts +461 -0
  40. package/common/constants.js +789 -0
  41. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +27 -0
  42. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +353 -145
  44. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
  45. package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
  46. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +48 -54
  47. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -6
  48. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
  49. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +36 -77
  50. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
  51. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +50 -57
  52. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -8
  53. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
  54. package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
  55. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +74 -0
  56. package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
  57. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +7 -7
  58. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +50 -56
  59. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
  60. package/contracts/LSP6KeyManager/LSP6Constants.sol +8 -2
  61. package/contracts/LSP6KeyManager/LSP6Errors.sol +18 -1
  62. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +126 -745
  63. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +407 -0
  64. package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
  65. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +633 -0
  66. package/contracts/LSP6KeyManager/LSP6Utils.sol +60 -15
  67. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +14 -23
  68. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  69. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +5 -0
  70. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +19 -30
  71. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -3
  72. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +1 -3
  73. package/contracts/LSP9Vault/ILSP9Vault.sol +19 -0
  74. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  75. package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
  76. package/contracts/LSP9Vault/LSP9VaultCore.sol +166 -83
  77. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
  78. package/module/constants.d.ts +461 -0
  79. package/module/constants.js +786 -0
  80. package/package.json +30 -6
  81. package/constants.js +0 -856
@@ -3,33 +3,44 @@ pragma solidity ^0.8.5;
3
3
 
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
- import {IERC725X} from "@erc725/smart-contracts/contracts/interfaces/IERC725X.sol";
7
6
  import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
7
+ import {
8
+ ILSP20CallVerification as ILSP20
9
+ } from "../LSP20CallVerification/ILSP20CallVerification.sol";
8
10
 
9
11
  // modules
10
12
  import {ILSP14Ownable2Step} from "../LSP14Ownable2Step/ILSP14Ownable2Step.sol";
11
13
  import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
12
14
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
15
+ import {LSP6SetDataModule} from "./LSP6Modules/LSP6SetDataModule.sol";
16
+ import {LSP6ExecuteModule} from "./LSP6Modules/LSP6ExecuteModule.sol";
17
+ import {LSP6OwnershipModule} from "./LSP6Modules/LSP6OwnershipModule.sol";
13
18
 
14
19
  // libraries
15
20
  import {GasLib} from "../Utils/GasLib.sol";
16
21
  import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
17
22
  import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
18
23
  import {Address} from "@openzeppelin/contracts/utils/Address.sol";
19
- import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
20
24
  import {LSP6Utils} from "./LSP6Utils.sol";
21
25
  import {EIP191Signer} from "../Custom/EIP191Signer.sol";
22
26
 
23
27
  // errors
24
- import "./LSP6Errors.sol";
28
+ import {
29
+ BatchExecuteParamsLengthMismatch,
30
+ BatchExecuteRelayCallParamsLengthMismatch,
31
+ LSP6BatchExcessiveValueSent,
32
+ LSP6BatchInsufficientValueSent,
33
+ InvalidPayload,
34
+ InvalidRelayNonce,
35
+ NoPermissionsSet,
36
+ InvalidERC725Function,
37
+ NotAuthorised,
38
+ CallerIsNotTheTarget,
39
+ CannotSendValueToSetData
40
+ } from "./LSP6Errors.sol";
25
41
 
26
42
  // constants
27
43
  import {
28
- OPERATION_0_CALL,
29
- OPERATION_1_CREATE,
30
- OPERATION_2_CREATE2,
31
- OPERATION_3_STATICCALL,
32
- OPERATION_4_DELEGATECALL,
33
44
  SETDATA_SELECTOR,
34
45
  SETDATA_ARRAY_SELECTOR,
35
46
  EXECUTE_SELECTOR
@@ -39,15 +50,12 @@ import {
39
50
  _ERC1271_MAGICVALUE,
40
51
  _ERC1271_FAILVALUE
41
52
  } from "../LSP0ERC725Account/LSP0Constants.sol";
42
-
43
53
  import {
44
- _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
45
- _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
46
- } from "../LSP1UniversalReceiver/LSP1Constants.sol";
47
-
48
- import "./LSP6Constants.sol";
49
-
50
- import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
54
+ LSP6_VERSION,
55
+ _INTERFACEID_LSP6,
56
+ _PERMISSION_SIGN,
57
+ _PERMISSION_REENTRANCY
58
+ } from "./LSP6Constants.sol";
51
59
 
52
60
  /**
53
61
  * @title Core implementation of the LSP6 Key Manager standard.
@@ -55,11 +63,16 @@ import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.
55
63
  * @dev This contract acts as a controller for an ERC725 Account.
56
64
  * Permissions for controllers are stored in the ERC725Y storage of the ERC725 Account and can be updated using `setData(...)`.
57
65
  */
58
- abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
66
+ abstract contract LSP6KeyManagerCore is
67
+ ERC165,
68
+ ILSP6KeyManager,
69
+ ILSP20,
70
+ LSP6SetDataModule,
71
+ LSP6ExecuteModule,
72
+ LSP6OwnershipModule
73
+ {
59
74
  using LSP6Utils for *;
60
- using Address for address;
61
75
  using ECDSA for bytes32;
62
- using ERC165Checker for address;
63
76
  using EIP191Signer for address;
64
77
  using BytesLib for bytes;
65
78
 
@@ -75,6 +88,45 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
75
88
  return _target;
76
89
  }
77
90
 
91
+ /**
92
+ * @inheritdoc ILSP20
93
+ */
94
+ function lsp20VerifyCall(
95
+ address caller,
96
+ uint256 msgValue,
97
+ bytes calldata data
98
+ ) external returns (bytes4) {
99
+ if (msg.sender != _target) revert CallerIsNotTheTarget(msg.sender);
100
+
101
+ bool isSetData = false;
102
+ if (bytes4(data) == SETDATA_SELECTOR || bytes4(data) == SETDATA_ARRAY_SELECTOR) {
103
+ isSetData = true;
104
+ }
105
+
106
+ _nonReentrantBefore(isSetData, caller);
107
+
108
+ _verifyPermissions(caller, msgValue, data);
109
+ emit VerifiedCall(msg.sender, msgValue, bytes4(data));
110
+
111
+ // if it's a setData call, do not invoke the `lsp20VerifyCallResult(..)` function
112
+ return
113
+ isSetData
114
+ ? bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"00"))
115
+ : bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"01"));
116
+ }
117
+
118
+ /**
119
+ * @inheritdoc ILSP20
120
+ */
121
+ function lsp20VerifyCallResult(
122
+ bytes32, /*callHash*/
123
+ bytes memory /*result*/
124
+ ) external returns (bytes4) {
125
+ if (msg.sender != _target) revert CallerIsNotTheTarget(msg.sender);
126
+ _nonReentrantAfter();
127
+ return ILSP20.lsp20VerifyCallResult.selector;
128
+ }
129
+
78
130
  /**
79
131
  * @dev See {IERC165-supportsInterface}.
80
132
  */
@@ -203,10 +255,22 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
203
255
  revert InvalidPayload(payload);
204
256
  }
205
257
 
206
- _nonReentrantBefore(msg.sender);
207
- _verifyPermissions(msg.sender, payload);
258
+ bool isSetData;
259
+ if (bytes4(payload) == SETDATA_SELECTOR || bytes4(payload) == SETDATA_ARRAY_SELECTOR) {
260
+ isSetData = true;
261
+ }
262
+
263
+ _nonReentrantBefore(isSetData, msg.sender);
264
+
265
+ _verifyPermissions(msg.sender, msgValue, payload);
266
+ emit VerifiedCall(msg.sender, msgValue, bytes4(payload));
267
+
208
268
  bytes memory result = _executePayload(msgValue, payload);
209
- _nonReentrantAfter();
269
+
270
+ if (!isSetData) {
271
+ _nonReentrantAfter();
272
+ }
273
+
210
274
  return result;
211
275
  }
212
276
 
@@ -232,7 +296,12 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
232
296
  signature
233
297
  );
234
298
 
235
- _nonReentrantBefore(signer);
299
+ bool isSetData;
300
+ if (bytes4(payload) == SETDATA_SELECTOR || bytes4(payload) == SETDATA_ARRAY_SELECTOR) {
301
+ isSetData = true;
302
+ }
303
+
304
+ _nonReentrantBefore(isSetData, signer);
236
305
 
237
306
  if (!_isValidNonce(signer, nonce)) {
238
307
  revert InvalidRelayNonce(signer, nonce, signature);
@@ -241,11 +310,14 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
241
310
  // increase nonce after successful verification
242
311
  _nonceStore[signer][nonce >> 128]++;
243
312
 
244
- _verifyPermissions(signer, payload);
313
+ _verifyPermissions(signer, msgValue, payload);
314
+ emit VerifiedCall(signer, msgValue, bytes4(payload));
245
315
 
246
316
  bytes memory result = _executePayload(msgValue, payload);
247
317
 
248
- _nonReentrantAfter();
318
+ if (!isSetData) {
319
+ _nonReentrantAfter();
320
+ }
249
321
 
250
322
  return result;
251
323
  }
@@ -260,8 +332,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
260
332
  virtual
261
333
  returns (bytes memory)
262
334
  {
263
- emit Executed(bytes4(payload), msgValue);
264
-
265
335
  (bool success, bytes memory returnData) = _target.call{value: msgValue, gas: gasleft()}(
266
336
  payload
267
337
  );
@@ -294,7 +364,11 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
294
364
  * @param from either the caller of `execute(...)` or the signer of `executeRelayCall(...)`.
295
365
  * @param payload the payload to execute on the `target`.
296
366
  */
297
- function _verifyPermissions(address from, bytes calldata payload) internal view virtual {
367
+ function _verifyPermissions(
368
+ address from,
369
+ uint256 msgValue,
370
+ bytes calldata payload
371
+ ) internal view virtual {
298
372
  bytes32 permissions = ERC725Y(_target).getPermissionsFor(from);
299
373
  if (permissions == bytes32(0)) revert NoPermissionsSet(from);
300
374
 
@@ -302,743 +376,34 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
302
376
 
303
377
  // ERC725Y.setData(bytes32,bytes)
304
378
  if (erc725Function == SETDATA_SELECTOR) {
379
+ if (msgValue != 0) revert CannotSendValueToSetData();
305
380
  (bytes32 inputKey, bytes memory inputValue) = abi.decode(payload[4:], (bytes32, bytes));
306
381
 
307
- _verifyCanSetData(from, permissions, inputKey, inputValue);
382
+ LSP6SetDataModule._verifyCanSetData(_target, from, permissions, inputKey, inputValue);
308
383
 
309
384
  // ERC725Y.setData(bytes32[],bytes[])
310
385
  } else if (erc725Function == SETDATA_ARRAY_SELECTOR) {
386
+ if (msgValue != 0) revert CannotSendValueToSetData();
311
387
  (bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(
312
388
  payload[4:],
313
389
  (bytes32[], bytes[])
314
390
  );
315
391
 
316
- _verifyCanSetData(from, permissions, inputKeys, inputValues);
392
+ LSP6SetDataModule._verifyCanSetData(_target, from, permissions, inputKeys, inputValues);
317
393
 
318
394
  // ERC725X.execute(uint256,address,uint256,bytes)
319
395
  } else if (erc725Function == EXECUTE_SELECTOR) {
320
- _verifyCanExecute(from, permissions, payload);
396
+ LSP6ExecuteModule._verifyCanExecute(_target, from, permissions, payload);
321
397
  } else if (
322
398
  erc725Function == ILSP14Ownable2Step.transferOwnership.selector ||
323
399
  erc725Function == ILSP14Ownable2Step.acceptOwnership.selector
324
400
  ) {
325
- _requirePermissions(from, permissions, _PERMISSION_CHANGEOWNER);
401
+ LSP6OwnershipModule._verifyOwnershipPermissions(from, permissions);
326
402
  } else {
327
403
  revert InvalidERC725Function(erc725Function);
328
404
  }
329
405
  }
330
406
 
331
- /**
332
- * @dev verify if the `controllerAddress` has the permissions required to set a data key on the ERC725Y storage of the `target`.
333
- * @param controllerAddress the address who want to set the data key.
334
- * @param controllerPermissions the permissions to be checked against.
335
- * @param inputDataKey the data key to set on the `target`.
336
- * @param inputDataValue the data value to set for the `inputDataKey`.
337
- */
338
- function _verifyCanSetData(
339
- address controllerAddress,
340
- bytes32 controllerPermissions,
341
- bytes32 inputDataKey,
342
- bytes memory inputDataValue
343
- ) internal view virtual {
344
- bytes32 requiredPermission = _getPermissionRequiredToSetDataKey(
345
- inputDataKey,
346
- inputDataValue
347
- );
348
-
349
- // CHECK if allowed to set an ERC725Y Data Key
350
- if (requiredPermission == _PERMISSION_SETDATA) {
351
- // Skip if caller has SUPER permissions
352
- if (controllerPermissions.hasPermission(_PERMISSION_SUPER_SETDATA)) return;
353
-
354
- _requirePermissions(controllerAddress, controllerPermissions, _PERMISSION_SETDATA);
355
-
356
- _verifyAllowedERC725YSingleKey(
357
- controllerAddress,
358
- inputDataKey,
359
- ERC725Y(_target).getAllowedERC725YDataKeysFor(controllerAddress)
360
- );
361
- } else {
362
- // Otherwise CHECK the required permission if setting LSP6 permissions, LSP1 Delegate or LSP17 Extensions.
363
- _requirePermissions(controllerAddress, controllerPermissions, requiredPermission);
364
- }
365
- }
366
-
367
- /**
368
- * @dev verify if the `controllerAddress` has the permissions required to set an array of data keys on the ERC725Y storage of the `target`.
369
- * @param controllerAddress the address who want to set the data keys.
370
- * @param controllerPermissions the permissions to be checked against.
371
- * @param inputDataKeys an array of data keys to set on the `target`.
372
- * @param inputDataValues an array of data values to set for the `inputDataKeys`.
373
- */
374
- function _verifyCanSetData(
375
- address controllerAddress,
376
- bytes32 controllerPermissions,
377
- bytes32[] memory inputDataKeys,
378
- bytes[] memory inputDataValues
379
- ) internal view virtual {
380
- bool isSettingERC725YKeys;
381
- bool[] memory validatedInputDataKeys = new bool[](inputDataKeys.length);
382
-
383
- bytes32 requiredPermission;
384
-
385
- uint256 ii;
386
- do {
387
- requiredPermission = _getPermissionRequiredToSetDataKey(
388
- inputDataKeys[ii],
389
- inputDataValues[ii]
390
- );
391
-
392
- if (requiredPermission == _PERMISSION_SETDATA) {
393
- isSettingERC725YKeys = true;
394
- } else {
395
- // CHECK the required permissions if setting LSP6 permissions, LSP1 Delegate or LSP17 Extensions.
396
- _requirePermissions(controllerAddress, controllerPermissions, requiredPermission);
397
- validatedInputDataKeys[ii] = true;
398
- }
399
-
400
- ii = GasLib.uncheckedIncrement(ii);
401
- } while (ii < inputDataKeys.length);
402
-
403
- // CHECK if allowed to set one (or multiple) ERC725Y Data Keys
404
- if (isSettingERC725YKeys) {
405
- // Skip if caller has SUPER permissions
406
- if (controllerPermissions.hasPermission(_PERMISSION_SUPER_SETDATA)) return;
407
-
408
- _requirePermissions(controllerAddress, controllerPermissions, _PERMISSION_SETDATA);
409
-
410
- _verifyAllowedERC725YDataKeys(
411
- controllerAddress,
412
- inputDataKeys,
413
- ERC725Y(_target).getAllowedERC725YDataKeysFor(controllerAddress),
414
- validatedInputDataKeys
415
- );
416
- }
417
- }
418
-
419
- /**
420
- * @dev retrieve the permission required based on the data key to be set on the `target`.
421
- * @param inputDataKey the data key to set on the `target`. Can be related to LSP6 Permissions, LSP1 Delegate or LSP17 Extensions.
422
- * @param inputDataValue the data value to set for the `inputDataKey`.
423
- * @return the permission required to set the `inputDataKey` on the `target`.
424
- */
425
- function _getPermissionRequiredToSetDataKey(bytes32 inputDataKey, bytes memory inputDataValue)
426
- internal
427
- view
428
- virtual
429
- returns (bytes32)
430
- {
431
- // AddressPermissions[] or AddressPermissions[index]
432
- if (bytes16(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
433
- return _getPermissionToSetPermissionsArray(inputDataKey, inputDataValue);
434
-
435
- // AddressPermissions:...
436
- } else if (bytes6(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX) {
437
- // AddressPermissions:Permissions:<address>
438
- if (bytes12(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
439
- return _getPermissionToSetControllerPermissions(inputDataKey);
440
-
441
- // AddressPermissions:AllowedCalls:<address>
442
- } else if (bytes12(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDCALLS_PREFIX) {
443
- return _getPermissionToSetAllowedCalls(inputDataKey, inputDataValue);
444
-
445
- // AddressPermissions:AllowedERC725YKeys:<address>
446
- } else if (
447
- bytes12(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_AllowedERC725YDataKeys_PREFIX
448
- ) {
449
- return _getPermissionToSetAllowedERC725YDataKeys(inputDataKey, inputDataValue);
450
-
451
- // if the first 6 bytes of the input data key are "AddressPermissions:..." but did not match
452
- // with anything above, this is not a standard LSP6 permission data key so we revert.
453
- } else {
454
- /**
455
- * @dev more permissions types starting with `AddressPermissions:...` can be implemented by overriding this function.
456
- *
457
- * // AddressPermissions:MyCustomPermissions:<address>
458
- * bytes12 CUSTOM_PERMISSION_PREFIX = 0x4b80742de2bf9e659ba40000
459
- *
460
- * if (bytes12(dataKey) == CUSTOM_PERMISSION_PREFIX) {
461
- * // custom logic
462
- * }
463
- *
464
- * super._getPermissionRequiredToSetDataKey(...)
465
- */
466
- revert NotRecognisedPermissionKey(inputDataKey);
467
- }
468
-
469
- // LSP1UniversalReceiverDelegate or LSP1UniversalReceiverDelegate:<typeId>
470
- } else if (
471
- inputDataKey == _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY ||
472
- bytes12(inputDataKey) == _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX
473
- ) {
474
- return _getPermissionToSetLSP1Delegate(inputDataKey);
475
-
476
- // LSP17Extension:<bytes4>
477
- } else if (bytes12(inputDataKey) == _LSP17_EXTENSION_PREFIX) {
478
- return _getPermissionToSetLSP17Extension(inputDataKey);
479
- } else {
480
- return _PERMISSION_SETDATA;
481
- }
482
- }
483
-
484
- /**
485
- * @dev retrieve the permission required to update the `AddressPermissions[]` array data key defined in LSP6.
486
- * @param inputDataKey either `AddressPermissions[]` (array length) or `AddressPermissions[index]` (array index)
487
- * @param inputDataValue the updated value for the `inputDataKey`. MUST be:
488
- * - a `uint256` for `AddressPermissions[]` (array length)
489
- * - an `address` or `0x` for `AddressPermissions[index]` (array entry).
490
- *
491
- * @return either ADD or CHANGE PERMISSIONS.
492
- */
493
- function _getPermissionToSetPermissionsArray(bytes32 inputDataKey, bytes memory inputDataValue)
494
- internal
495
- view
496
- virtual
497
- returns (bytes32)
498
- {
499
- bytes memory currentValue = ERC725Y(_target).getData(inputDataKey);
500
-
501
- // AddressPermissions[] -> array length
502
- if (inputDataKey == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
503
- uint256 newLength = uint256(bytes32(inputDataValue));
504
-
505
- return
506
- newLength > uint256(bytes32(currentValue))
507
- ? _PERMISSION_ADDCONTROLLER
508
- : _PERMISSION_CHANGEPERMISSIONS;
509
- }
510
-
511
- // AddressPermissions[index] -> array index
512
-
513
- // CHECK that we either ADD an address (20 bytes long) or REMOVE an address (0x)
514
- if (inputDataValue.length != 0 && inputDataValue.length != 20) {
515
- revert AddressPermissionArrayIndexValueNotAnAddress(inputDataKey, inputDataValue);
516
- }
517
-
518
- return currentValue.length == 0 ? _PERMISSION_ADDCONTROLLER : _PERMISSION_CHANGEPERMISSIONS;
519
- }
520
-
521
- /**
522
- * @dev retrieve the permission required to set permissions for a controller address.
523
- * @param inputPermissionDataKey `AddressPermissions:Permissions:<controller-address>`.
524
- * @return either ADD or CHANGE PERMISSIONS.
525
- */
526
- function _getPermissionToSetControllerPermissions(bytes32 inputPermissionDataKey)
527
- internal
528
- view
529
- virtual
530
- returns (bytes32)
531
- {
532
- return
533
- // if there is nothing stored under the data key, we are trying to ADD a new controller.
534
- // if there are already some permissions set under the data key, we are trying to CHANGE the permissions of a controller.
535
- bytes32(ERC725Y(_target).getData(inputPermissionDataKey)) == bytes32(0)
536
- ? _PERMISSION_ADDCONTROLLER
537
- : _PERMISSION_CHANGEPERMISSIONS;
538
- }
539
-
540
- /**
541
- * @dev retrieve the permission required to set some AllowedCalls for a controller.
542
- * @param dataKey `AddressPermissions:AllowedCalls:<controller-address>`.
543
- * @param dataValue the updated value for the `dataKey`. MUST be a bytes28[CompactBytesArray] of Allowed Calls.
544
- * @return either ADD or CHANGE PERMISSIONS.
545
- */
546
- function _getPermissionToSetAllowedCalls(bytes32 dataKey, bytes memory dataValue)
547
- internal
548
- view
549
- virtual
550
- returns (bytes32)
551
- {
552
- if (!LSP6Utils.isCompactBytesArrayOfAllowedCalls(dataValue)) {
553
- revert InvalidEncodedAllowedCalls(dataValue);
554
- }
555
-
556
- // if there is nothing stored under the Allowed Calls of the controller,
557
- // we are trying to ADD a list of restricted calls (standards + address + function selector)
558
- //
559
- // if there are already some data set under the Allowed Calls of the controller,
560
- // we are trying to CHANGE (= edit) these restrictions.
561
- return
562
- ERC725Y(_target).getData(dataKey).length == 0
563
- ? _PERMISSION_ADDCONTROLLER
564
- : _PERMISSION_CHANGEPERMISSIONS;
565
- }
566
-
567
- /**
568
- * @dev retrieve the permission required to set some AllowedCalls for a controller.
569
- * @param dataKey or `AddressPermissions:AllowedERC725YDataKeys:<controller-address>`.
570
- * @param dataValue the updated value for the `dataKey`. MUST be a bytes[CompactBytesArray] of Allowed ERC725Y Data Keys.
571
- * @return either ADD or CHANGE PERMISSIONS.
572
- */
573
- function _getPermissionToSetAllowedERC725YDataKeys(bytes32 dataKey, bytes memory dataValue)
574
- internal
575
- view
576
- returns (bytes32)
577
- {
578
- if (!LSP6Utils.isCompactBytesArrayOfAllowedERC725YDataKeys(dataValue)) {
579
- revert InvalidEncodedAllowedERC725YDataKeys(dataValue);
580
- }
581
-
582
- // if there is nothing stored under the Allowed ERC725Y Data Keys of the controller,
583
- // we are trying to ADD a list of restricted ERC725Y Data Keys.
584
- //
585
- // if there are already some data set under the Allowed ERC725Y Data Keys of the controller,
586
- // we are trying to CHANGE (= edit) these restricted ERC725Y data keys.
587
- return
588
- ERC725Y(_target).getData(dataKey).length == 0
589
- ? _PERMISSION_ADDCONTROLLER
590
- : _PERMISSION_CHANGEPERMISSIONS;
591
- }
592
-
593
- /**
594
- * @dev retrieve the permission required to either add or change the address
595
- * of a LSP1 Universal Receiver Delegate stored under a specific LSP1 data key.
596
- * @param lsp1DelegateDataKey either the data key for the default `LSP1UniversalReceiverDelegate`,
597
- * or a data key for a specific `LSP1UniversalReceiverDelegate:<typeId>`, starting with `_LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX`.
598
- * @return either ADD or CHANGE UNIVERSALRECEIVERDELEGATE.
599
- */
600
- function _getPermissionToSetLSP1Delegate(bytes32 lsp1DelegateDataKey)
601
- internal
602
- view
603
- virtual
604
- returns (bytes32)
605
- {
606
- return
607
- ERC725Y(_target).getData(lsp1DelegateDataKey).length == 0
608
- ? _PERMISSION_ADDUNIVERSALRECEIVERDELEGATE
609
- : _PERMISSION_CHANGEUNIVERSALRECEIVERDELEGATE;
610
- }
611
-
612
- /**
613
- * @dev Verify if `from` has the required permissions to either add or change the address
614
- * of an LSP0 Extension stored under a specific LSP17Extension data key
615
- * @param lsp17ExtensionDataKey the dataKey to set with `_LSP17_EXTENSION_PREFIX` as prefix.
616
- */
617
- function _getPermissionToSetLSP17Extension(bytes32 lsp17ExtensionDataKey)
618
- internal
619
- view
620
- virtual
621
- returns (bytes32)
622
- {
623
- return
624
- ERC725Y(_target).getData(lsp17ExtensionDataKey).length == 0
625
- ? _PERMISSION_ADDEXTENSIONS
626
- : _PERMISSION_CHANGEEXTENSIONS;
627
- }
628
-
629
- /**
630
- * @dev Verify if the `inputKey` is present in the list of `allowedERC725KeysCompacted` for the `controllerAddress`.
631
- * @param controllerAddress the address of the controller.
632
- * @param inputDataKey the data key to verify against the allowed ERC725Y Data Keys for the `controllerAddress`.
633
- * @param allowedERC725YDataKeysCompacted a CompactBytesArray of allowed ERC725Y Data Keys for the `controllerAddress`.
634
- */
635
- function _verifyAllowedERC725YSingleKey(
636
- address controllerAddress,
637
- bytes32 inputDataKey,
638
- bytes memory allowedERC725YDataKeysCompacted
639
- ) internal pure virtual {
640
- if (allowedERC725YDataKeysCompacted.length == 0)
641
- revert NoERC725YDataKeysAllowed(controllerAddress);
642
-
643
- /**
644
- * The pointer will always land on the length of each bytes value:
645
- *
646
- * ↓↓
647
- * 03 a00000
648
- * 05 fff83a0011
649
- * 20 aa0000000000000000000000000000000000000000000000000000000000cafe
650
- * 12 bb000000000000000000000000000000beef
651
- * 19 cc00000000000000000000000000000000000000000000deed
652
- * ↑↑
653
- *
654
- */
655
- uint256 pointer;
656
-
657
- // information extracted from each Allowed ERC725Y Data Key.
658
- uint256 length;
659
- bytes32 allowedKey;
660
- bytes32 mask;
661
-
662
- /**
663
- * iterate over each data key and update the `pointer` variable with the index where to find the length of each data key.
664
- *
665
- * 0x 03 a00000 03 fff83a 20 aa00...00cafe
666
- * ↑↑ ↑↑ ↑↑
667
- * first | second | third
668
- * length | length | length
669
- */
670
- while (pointer < allowedERC725YDataKeysCompacted.length) {
671
- // save the length of the allowed data key to calculate the `mask`.
672
- length = uint16(
673
- bytes2(
674
- abi.encodePacked(
675
- allowedERC725YDataKeysCompacted[pointer],
676
- allowedERC725YDataKeysCompacted[pointer + 1]
677
- )
678
- )
679
- );
680
-
681
- /**
682
- * The bitmask discard the last `32 - length` bytes of the input data key via ANDing &
683
- * It is used to compare only the relevant parts of each input data key against dynamic allowed data keys.
684
- *
685
- * E.g.:
686
- *
687
- * allowed data key = 0xa00000
688
- *
689
- * compare this part
690
- * vvvvvv
691
- * input data key = 0xa00000cafecafecafecafecafecafecafe000000000000000000000011223344
692
- *
693
- * & discard this part
694
- * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
695
- * mask = 0xffffff0000000000000000000000000000000000000000000000000000000000
696
- */
697
- mask =
698
- bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) <<
699
- (8 * (32 - length));
700
-
701
- /*
702
- * transform the allowed data key situated from `pointer + 1` until `pointer + 1 + length` to a bytes32 value.
703
- * E.g. 0xfff83a -> 0xfff83a0000000000000000000000000000000000000000000000000000000000
704
- */
705
- // solhint-disable-next-line no-inline-assembly
706
- assembly {
707
- // the first 32 bytes word in memory (where allowedERC725YDataKeysCompacted is stored)
708
- // correspond to the total number of bytes in `allowedERC725YDataKeysCompacted`
709
- let offset := add(add(pointer, 2), 32)
710
- let memoryAt := mload(add(allowedERC725YDataKeysCompacted, offset))
711
- // MLOAD loads 32 bytes word, so we need to keep only the `length` number of bytes that makes up the allowed data key.
712
- allowedKey := and(memoryAt, mask)
713
- }
714
-
715
- // voila you found the key ;)
716
- if (allowedKey == (inputDataKey & mask)) return;
717
-
718
- // move the pointer to the index of the next allowed data key
719
- unchecked {
720
- pointer = pointer + (length + 2);
721
- }
722
- }
723
-
724
- revert NotAllowedERC725YDataKey(controllerAddress, inputDataKey);
725
- }
726
-
727
- /**
728
- * @dev Verify if all the `inputDataKeys` are present in the list of `allowedERC725KeysCompacted` of the `controllerAddress`.
729
- * @param controllerAddress the address of the controller.
730
- * @param inputDataKeys the data keys to verify against the allowed ERC725Y Data Keys of the `controllerAddress`.
731
- * @param allowedERC725YDataKeysCompacted a CompactBytesArray of allowed ERC725Y Data Keys of the `controllerAddress`.
732
- * @param validatedInputKeys an array of booleans to store the result of the verification of each data keys checked.
733
- */
734
- function _verifyAllowedERC725YDataKeys(
735
- address controllerAddress,
736
- bytes32[] memory inputDataKeys,
737
- bytes memory allowedERC725YDataKeysCompacted,
738
- bool[] memory validatedInputKeys
739
- ) internal pure virtual {
740
- if (allowedERC725YDataKeysCompacted.length == 0)
741
- revert NoERC725YDataKeysAllowed(controllerAddress);
742
-
743
- uint256 allowedKeysFound;
744
-
745
- // cache the input data keys from the start
746
- uint256 inputKeysLength = inputDataKeys.length;
747
-
748
- /**
749
- * The pointer will always land on the length of each bytes value:
750
- *
751
- * ↓↓
752
- * 03 a00000
753
- * 05 fff83a0011
754
- * 20 aa0000000000000000000000000000000000000000000000000000000000cafe
755
- * 12 bb000000000000000000000000000000beef
756
- * 19 cc00000000000000000000000000000000000000000000deed
757
- * ↑↑
758
- *
759
- */
760
- uint256 pointer;
761
-
762
- // information extracted from each Allowed ERC725Y Data Key.
763
- uint256 length;
764
- bytes32 allowedKey;
765
- bytes32 mask;
766
-
767
- /**
768
- * iterate over each data key and update the `pointer` variable with the index where to find the length of each data key.
769
- *
770
- * 0x 03 a00000 03 fff83a 20 aa00...00cafe
771
- * ↑↑ ↑↑ ↑↑
772
- * first | second | third
773
- * length | length | length
774
- */
775
- while (pointer < allowedERC725YDataKeysCompacted.length) {
776
- // save the length of the allowed data key to calculate the `mask`.
777
- length = uint16(
778
- bytes2(
779
- abi.encodePacked(
780
- allowedERC725YDataKeysCompacted[pointer],
781
- allowedERC725YDataKeysCompacted[pointer + 1]
782
- )
783
- )
784
- );
785
-
786
- /**
787
- * The bitmask discard the last `32 - length` bytes of the input data key via ANDing &
788
- * It is used to compare only the relevant parts of each input data key against dynamic allowed data keys.
789
- *
790
- * E.g.:
791
- *
792
- * allowed data key = 0xa00000
793
- *
794
- * compare this part
795
- * vvvvvv
796
- * input data key = 0xa00000cafecafecafecafecafecafecafe000000000000000000000011223344
797
- *
798
- * & discard this part
799
- * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
800
- * mask = 0xffffff0000000000000000000000000000000000000000000000000000000000
801
- */
802
- mask =
803
- bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) <<
804
- (8 * (32 - length));
805
-
806
- /*
807
- * transform the allowed data key situated from `pointer + 1` until `pointer + 1 + length` to a bytes32 value.
808
- * E.g. 0xfff83a -> 0xfff83a0000000000000000000000000000000000000000000000000000000000
809
- */
810
- // solhint-disable-next-line no-inline-assembly
811
- assembly {
812
- // the first 32 bytes word in memory (where allowedERC725YDataKeysCompacted is stored)
813
- // correspond to the length of allowedERC725YDataKeysCompacted (= total number of bytes)
814
- let offset := add(add(pointer, 2), 32)
815
- let memoryAt := mload(add(allowedERC725YDataKeysCompacted, offset))
816
- allowedKey := and(memoryAt, mask)
817
- }
818
-
819
- /**
820
- * Iterate over the `inputDataKeys` to check them against the allowed data keys.
821
- * This until we have validated them all.
822
- */
823
- for (uint256 ii; ii < inputKeysLength; ii = GasLib.uncheckedIncrement(ii)) {
824
- // if the input data key has been marked as allowed previously,
825
- // SKIP it and move to the next input data key.
826
- if (validatedInputKeys[ii]) continue;
827
-
828
- // CHECK if the input data key is allowed.
829
- if ((inputDataKeys[ii] & mask) == allowedKey) {
830
- // if the input data key is allowed, mark it as allowed
831
- // and increment the number of allowed keys found.
832
- validatedInputKeys[ii] = true;
833
- allowedKeysFound = GasLib.uncheckedIncrement(allowedKeysFound);
834
-
835
- // Continue checking until all the inputKeys` have been found.
836
- if (allowedKeysFound == inputKeysLength) return;
837
- }
838
- }
839
-
840
- // Move the pointer to the next AllowedERC725YKey
841
- unchecked {
842
- pointer = pointer + (length + 2);
843
- }
844
- }
845
-
846
- // if we did not find all the input data keys, search for the first not allowed data key to revert.
847
- for (uint256 jj; jj < inputKeysLength; jj = GasLib.uncheckedIncrement(jj)) {
848
- if (!validatedInputKeys[jj]) {
849
- revert NotAllowedERC725YDataKey(controllerAddress, inputDataKeys[jj]);
850
- }
851
- }
852
- }
853
-
854
- /**
855
- * @dev verify if `from` has the required permissions to interact with other addresses using the target.
856
- * @param from the address who want to run the execute function on the ERC725Account
857
- * @param permissions the permissions of the caller
858
- * @param payload the ABI encoded payload `target.execute(...)`
859
- */
860
- function _verifyCanExecute(
861
- address from,
862
- bytes32 permissions,
863
- bytes calldata payload
864
- ) internal view virtual {
865
- // MUST be one of the ERC725X operation types.
866
- uint256 operationType = uint256(bytes32(payload[4:36]));
867
-
868
- // DELEGATECALL is disallowed by default on the LSP6 Key Manager.
869
- if (operationType == OPERATION_4_DELEGATECALL) {
870
- revert DelegateCallDisallowedViaKeyManager();
871
- }
872
-
873
- uint256 value = uint256(bytes32(payload[68:100]));
874
-
875
- // prettier-ignore
876
- bool isContractCreation = operationType == OPERATION_1_CREATE || operationType == OPERATION_2_CREATE2;
877
- bool isCallDataPresent = payload.length > 164;
878
-
879
- // SUPER operation only applies to contract call, not contract creation
880
- bool hasSuperOperation = isContractCreation
881
- ? false
882
- : permissions.hasPermission(_extractSuperPermissionFromOperation(operationType));
883
-
884
- // CHECK if we are doing an empty call, as the receive() or fallback() function
885
- // of the target contract could run some code.
886
- if (!hasSuperOperation && !isCallDataPresent && value == 0) {
887
- _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
888
- }
889
-
890
- if (isCallDataPresent && !hasSuperOperation) {
891
- _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
892
- }
893
-
894
- bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
895
-
896
- if (value != 0 && !hasSuperTransferValue) {
897
- _requirePermissions(from, permissions, _PERMISSION_TRANSFERVALUE);
898
- }
899
-
900
- // Skip on contract creation (CREATE or CREATE2)
901
- if (isContractCreation) return;
902
-
903
- // Skip if caller has SUPER permissions for external calls, with or without calldata (empty calls)
904
- if (hasSuperOperation && value == 0) return;
905
-
906
- // Skip if caller has SUPER permission for value transfers
907
- if (hasSuperTransferValue && !isCallDataPresent && value != 0) return;
908
-
909
- // Skip if both SUPER permissions are present
910
- if (hasSuperOperation && hasSuperTransferValue) return;
911
-
912
- _verifyAllowedCall(from, payload);
913
- }
914
-
915
- function _verifyAllowedCall(address from, bytes calldata payload) internal view virtual {
916
- // CHECK for ALLOWED CALLS
917
- address to = address(bytes20(payload[48:68]));
918
-
919
- bool containsFunctionCall = payload.length >= 168;
920
- bytes4 selector;
921
- if (containsFunctionCall) selector = bytes4(payload[164:168]);
922
-
923
- bytes memory allowedCalls = ERC725Y(_target).getAllowedCallsFor(from);
924
- uint256 allowedCallsLength = allowedCalls.length;
925
-
926
- if (allowedCallsLength == 0) {
927
- revert NoCallsAllowed(from);
928
- }
929
-
930
- bool isAllowedStandard;
931
- bool isAllowedAddress;
932
- bool isAllowedFunction;
933
-
934
- for (uint256 ii; ii < allowedCallsLength; ii += 30) {
935
- if (ii + 30 > allowedCallsLength) {
936
- revert InvalidEncodedAllowedCalls(allowedCalls);
937
- }
938
- bytes memory chunk = BytesLib.slice(allowedCalls, ii + 2, 28);
939
-
940
- if (bytes28(chunk) == 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff) {
941
- revert InvalidWhitelistedCall(from);
942
- }
943
-
944
- bytes4 allowedStandard = bytes4(chunk);
945
- address allowedAddress = address(bytes20(bytes28(chunk) << 32));
946
- bytes4 allowedFunction = bytes4(bytes28(chunk) << 192);
947
-
948
- isAllowedStandard =
949
- allowedStandard == 0xffffffff ||
950
- to.supportsERC165InterfaceUnchecked(allowedStandard);
951
- isAllowedAddress =
952
- allowedAddress == 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF ||
953
- to == allowedAddress;
954
- isAllowedFunction =
955
- allowedFunction == 0xffffffff ||
956
- (containsFunctionCall && (selector == allowedFunction));
957
-
958
- if (isAllowedStandard && isAllowedAddress && isAllowedFunction) return;
959
- }
960
-
961
- revert NotAllowedCall(from, to, selector);
962
- }
963
-
964
- /**
965
- * @dev extract the required permission + a descriptive string, based on the `_operationType`
966
- * being run via ERC725Account.execute(...)
967
- * @param operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
968
- * @return permissionsRequired (bytes32) the permission associated with the `_operationType`
969
- */
970
- function _extractPermissionFromOperation(uint256 operationType)
971
- internal
972
- pure
973
- virtual
974
- returns (bytes32 permissionsRequired)
975
- {
976
- if (operationType == OPERATION_0_CALL) return _PERMISSION_CALL;
977
- else if (operationType == OPERATION_1_CREATE) return _PERMISSION_DEPLOY;
978
- else if (operationType == OPERATION_2_CREATE2) return _PERMISSION_DEPLOY;
979
- else if (operationType == OPERATION_3_STATICCALL) return _PERMISSION_STATICCALL;
980
- else if (operationType == OPERATION_4_DELEGATECALL) return _PERMISSION_DELEGATECALL;
981
- }
982
-
983
- /**
984
- * @dev returns the `superPermission` needed for a specific `operationType` of the `execute(..)`
985
- */
986
- function _extractSuperPermissionFromOperation(uint256 operationType)
987
- internal
988
- pure
989
- virtual
990
- returns (bytes32 superPermission)
991
- {
992
- if (operationType == OPERATION_0_CALL) return _PERMISSION_SUPER_CALL;
993
- else if (operationType == OPERATION_3_STATICCALL) return _PERMISSION_SUPER_STATICCALL;
994
- else if (operationType == OPERATION_4_DELEGATECALL) return _PERMISSION_SUPER_DELEGATECALL;
995
- }
996
-
997
- /**
998
- * @dev revert if `from`'s `addressPermissions` doesn't contain `permissionsRequired`
999
- * @param from the caller address
1000
- * @param addressPermissions the caller's permissions BitArray
1001
- * @param permissionRequired the required permission
1002
- */
1003
- function _requirePermissions(
1004
- address from,
1005
- bytes32 addressPermissions,
1006
- bytes32 permissionRequired
1007
- ) internal pure virtual {
1008
- if (!addressPermissions.hasPermission(permissionRequired)) {
1009
- string memory permissionErrorString = _getPermissionName(permissionRequired);
1010
- revert NotAuthorised(from, permissionErrorString);
1011
- }
1012
- }
1013
-
1014
- /**
1015
- * @dev returns the name of the permission as a string
1016
- */
1017
- function _getPermissionName(bytes32 permission)
1018
- internal
1019
- pure
1020
- virtual
1021
- returns (string memory errorMessage)
1022
- {
1023
- if (permission == _PERMISSION_CHANGEOWNER) return "TRANSFEROWNERSHIP";
1024
- if (permission == _PERMISSION_CHANGEPERMISSIONS) return "CHANGEPERMISSIONS";
1025
- if (permission == _PERMISSION_ADDCONTROLLER) return "ADDCONTROLLER";
1026
- if (permission == _PERMISSION_ADDEXTENSIONS) return "ADDEXTENSIONS";
1027
- if (permission == _PERMISSION_CHANGEEXTENSIONS) return "CHANGEEXTENSIONS";
1028
- if (permission == _PERMISSION_ADDUNIVERSALRECEIVERDELEGATE)
1029
- return "ADDUNIVERSALRECEIVERDELEGATE";
1030
- if (permission == _PERMISSION_CHANGEUNIVERSALRECEIVERDELEGATE)
1031
- return "CHANGEUNIVERSALRECEIVERDELEGATE";
1032
- if (permission == _PERMISSION_REENTRANCY) return "REENTRANCY";
1033
- if (permission == _PERMISSION_SETDATA) return "SETDATA";
1034
- if (permission == _PERMISSION_CALL) return "CALL";
1035
- if (permission == _PERMISSION_STATICCALL) return "STATICCALL";
1036
- if (permission == _PERMISSION_DELEGATECALL) return "DELEGATECALL";
1037
- if (permission == _PERMISSION_DEPLOY) return "DEPLOY";
1038
- if (permission == _PERMISSION_TRANSFERVALUE) return "TRANSFERVALUE";
1039
- if (permission == _PERMISSION_SIGN) return "SIGN";
1040
- }
1041
-
1042
407
  /**
1043
408
  * @dev Initialise _reentrancyStatus to _NOT_ENTERED.
1044
409
  */
@@ -1051,7 +416,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
1051
416
  * the status is `_ENTERED` in order to revert the call unless the caller has the REENTRANCY permission
1052
417
  * Used in the beginning of the `nonReentrant` modifier, before the method execution starts.
1053
418
  */
1054
- function _nonReentrantBefore(address from) internal virtual {
419
+ function _nonReentrantBefore(bool isSetData, address from) internal virtual {
1055
420
  if (_reentrancyStatus) {
1056
421
  // CHECK the caller has REENTRANCY permission
1057
422
  _requirePermissions(
@@ -1060,7 +425,9 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
1060
425
  _PERMISSION_REENTRANCY
1061
426
  );
1062
427
  } else {
1063
- _reentrancyStatus = true;
428
+ if (!isSetData) {
429
+ _reentrancyStatus = true;
430
+ }
1064
431
  }
1065
432
  }
1066
433
 
@@ -1073,4 +440,18 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
1073
440
  // https://eips.ethereum.org/EIPS/eip-2200)
1074
441
  _reentrancyStatus = false;
1075
442
  }
443
+
444
+ /**
445
+ * @dev revert if `controller`'s `addressPermissions` doesn't contain `permissionsRequired`
446
+ * @param controller the caller address
447
+ * @param addressPermissions the caller's permissions BitArray
448
+ * @param permissionRequired the required permission
449
+ */
450
+ function _requirePermissions(
451
+ address controller,
452
+ bytes32 addressPermissions,
453
+ bytes32 permissionRequired
454
+ ) internal pure override(LSP6ExecuteModule, LSP6SetDataModule) {
455
+ LSP6ExecuteModule._requirePermissions(controller, addressPermissions, permissionRequired);
456
+ }
1076
457
  }