@lukso/lsp-smart-contracts 0.8.2 → 0.10.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 (179) hide show
  1. package/README.md +29 -8
  2. package/artifacts/LSP0ERC725Account.json +90 -50
  3. package/artifacts/LSP0ERC725AccountInit.json +90 -50
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP16UniversalFactory.json +31 -2
  7. package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
  8. package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
  9. package/artifacts/LSP4Compatibility.json +39 -40
  10. package/artifacts/LSP4DigitalAssetMetadata.json +39 -40
  11. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +39 -40
  12. package/artifacts/LSP6KeyManager.json +107 -8
  13. package/artifacts/LSP6KeyManagerInit.json +119 -20
  14. package/artifacts/LSP7CappedSupply.json +78 -38
  15. package/artifacts/LSP7CappedSupplyInitAbstract.json +78 -38
  16. package/artifacts/LSP7CompatibleERC20.json +78 -38
  17. package/artifacts/LSP7CompatibleERC20InitAbstract.json +78 -38
  18. package/artifacts/LSP7CompatibleERC20Mintable.json +80 -40
  19. package/artifacts/LSP7CompatibleERC20MintableInit.json +80 -40
  20. package/artifacts/LSP7DigitalAsset.json +78 -38
  21. package/artifacts/LSP7DigitalAssetInitAbstract.json +78 -38
  22. package/artifacts/LSP7Mintable.json +80 -40
  23. package/artifacts/LSP7MintableInit.json +80 -40
  24. package/artifacts/LSP8CappedSupply.json +39 -40
  25. package/artifacts/LSP8CappedSupplyInitAbstract.json +39 -40
  26. package/artifacts/LSP8CompatibleERC721.json +42 -43
  27. package/artifacts/LSP8CompatibleERC721InitAbstract.json +42 -43
  28. package/artifacts/LSP8CompatibleERC721Mintable.json +44 -45
  29. package/artifacts/LSP8CompatibleERC721MintableInit.json +44 -45
  30. package/artifacts/LSP8IdentifiableDigitalAsset.json +39 -40
  31. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +39 -40
  32. package/artifacts/LSP8Mintable.json +41 -42
  33. package/artifacts/LSP8MintableInit.json +41 -42
  34. package/artifacts/LSP9Vault.json +73 -55
  35. package/artifacts/LSP9VaultInit.json +73 -55
  36. package/artifacts/UniversalProfile.json +90 -50
  37. package/artifacts/UniversalProfileInit.json +90 -50
  38. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +62 -0
  39. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  40. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +36 -6
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +605 -219
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +31 -5
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +37 -3
  44. package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
  45. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +71 -60
  46. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -7
  47. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
  48. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
  49. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +41 -84
  50. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
  51. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
  52. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
  53. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +129 -77
  54. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +45 -16
  55. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
  56. package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
  57. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +83 -0
  58. package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
  59. package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
  60. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
  61. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
  62. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +76 -66
  63. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +12 -3
  64. package/contracts/LSP6KeyManager/LSP6Constants.sol +9 -3
  65. package/contracts/LSP6KeyManager/LSP6Errors.sol +22 -1
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +172 -29
  67. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
  68. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +270 -100
  69. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +187 -67
  70. package/contracts/LSP6KeyManager/LSP6Utils.sol +31 -20
  71. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +79 -30
  72. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
  74. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
  75. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
  76. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
  77. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
  78. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +27 -29
  80. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
  81. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
  82. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
  87. package/contracts/LSP9Vault/ILSP9Vault.sol +27 -0
  88. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  89. package/contracts/LSP9Vault/LSP9Vault.sol +11 -8
  90. package/contracts/LSP9Vault/LSP9VaultCore.sol +96 -71
  91. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
  92. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +19 -7
  93. package/contracts/UniversalProfileInitAbstract.sol +5 -0
  94. package/devdocs/Create2Factory.json +16 -0
  95. package/devdocs/LSP0ERC725Account.json +200 -0
  96. package/devdocs/LSP0ERC725AccountInit.json +203 -0
  97. package/devdocs/LSP11BasicSocialRecovery.json +146 -0
  98. package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
  99. package/devdocs/LSP16UniversalFactory.json +51 -0
  100. package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
  101. package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
  102. package/devdocs/LSP4Compatibility.json +79 -0
  103. package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
  104. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
  105. package/devdocs/LSP6KeyManager.json +257 -0
  106. package/devdocs/LSP6KeyManagerInit.json +260 -0
  107. package/devdocs/LSP7CappedSupply.json +211 -0
  108. package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
  109. package/devdocs/LSP7CompatibleERC20.json +225 -0
  110. package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
  111. package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
  112. package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
  113. package/devdocs/LSP7DigitalAsset.json +210 -0
  114. package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
  115. package/devdocs/LSP7Mintable.json +219 -0
  116. package/devdocs/LSP7MintableInit.json +220 -0
  117. package/devdocs/LSP8CappedSupply.json +232 -0
  118. package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
  119. package/devdocs/LSP8CompatibleERC721.json +298 -0
  120. package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
  121. package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
  122. package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
  123. package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
  124. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
  125. package/devdocs/LSP8Mintable.json +242 -0
  126. package/devdocs/LSP8MintableInit.json +245 -0
  127. package/devdocs/LSP9Vault.json +171 -0
  128. package/devdocs/LSP9VaultInit.json +175 -0
  129. package/devdocs/UniversalProfile.json +199 -0
  130. package/devdocs/UniversalProfileInit.json +202 -0
  131. package/devdocs/UniversalReceiverAddressStore.json +9 -0
  132. package/dist/constants.cjs.js +31569 -0
  133. package/dist/constants.d.ts +31681 -0
  134. package/dist/constants.es.js +31550 -0
  135. package/package.json +70 -52
  136. package/userdocs/Create2Factory.json +5 -0
  137. package/userdocs/LSP0ERC725Account.json +47 -0
  138. package/userdocs/LSP0ERC725AccountInit.json +47 -0
  139. package/userdocs/LSP11BasicSocialRecovery.json +29 -0
  140. package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
  141. package/userdocs/LSP16UniversalFactory.json +5 -0
  142. package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
  143. package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
  144. package/userdocs/LSP4Compatibility.json +20 -0
  145. package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
  146. package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
  147. package/userdocs/LSP6KeyManager.json +18 -0
  148. package/userdocs/LSP6KeyManagerInit.json +18 -0
  149. package/userdocs/LSP7CappedSupply.json +29 -0
  150. package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
  151. package/userdocs/LSP7CompatibleERC20.json +35 -0
  152. package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
  153. package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
  154. package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
  155. package/userdocs/LSP7DigitalAsset.json +29 -0
  156. package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
  157. package/userdocs/LSP7Mintable.json +29 -0
  158. package/userdocs/LSP7MintableInit.json +29 -0
  159. package/userdocs/LSP8CappedSupply.json +23 -0
  160. package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
  161. package/userdocs/LSP8CompatibleERC721.json +29 -0
  162. package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
  163. package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
  164. package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
  165. package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
  166. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
  167. package/userdocs/LSP8Mintable.json +23 -0
  168. package/userdocs/LSP8MintableInit.json +23 -0
  169. package/userdocs/LSP9Vault.json +38 -0
  170. package/userdocs/LSP9VaultInit.json +38 -0
  171. package/userdocs/UniversalProfile.json +50 -0
  172. package/userdocs/UniversalProfileInit.json +50 -0
  173. package/userdocs/UniversalReceiverAddressStore.json +5 -0
  174. package/CONTRIBUTING.md +0 -57
  175. package/common/constants.d.ts +0 -738
  176. package/common/constants.js +0 -785
  177. package/contracts/Utils/GasLib.sol +0 -17
  178. package/module/constants.d.ts +0 -738
  179. package/module/constants.js +0 -782
@@ -18,8 +18,10 @@ import {
18
18
  _PERMISSION_SUPER_CALL,
19
19
  _PERMISSION_STATICCALL,
20
20
  _PERMISSION_SUPER_STATICCALL,
21
- _PERMISSION_DELEGATECALL,
22
- _PERMISSION_SUPER_DELEGATECALL
21
+ _ALLOWEDCALLS_TRANSFERVALUE,
22
+ _ALLOWEDCALLS_CALL,
23
+ _ALLOWEDCALLS_STATICCALL,
24
+ _ALLOWEDCALLS_DELEGATECALL
23
25
  } from "../LSP6Constants.sol";
24
26
  import {
25
27
  OPERATION_0_CALL,
@@ -36,7 +38,9 @@ import {
36
38
  NotAllowedCall,
37
39
  InvalidEncodedAllowedCalls,
38
40
  InvalidWhitelistedCall,
39
- NotAuthorised
41
+ NotAuthorised,
42
+ InvalidPayload,
43
+ CallingKeyManagerNotAllowed
40
44
  } from "../LSP6Errors.sol";
41
45
 
42
46
  abstract contract LSP6ExecuteModule {
@@ -46,80 +50,156 @@ abstract contract LSP6ExecuteModule {
46
50
  /**
47
51
  * @dev verify if `controllerAddress` has the required permissions to interact with other addresses using the controlledContract.
48
52
  * @param controlledContract the address of the ERC725 contract where the payload is executed and where the permissions are verified.
49
- * @param controllerAddress the address who want to run the execute function on the ERC725Account.
50
- * @param controllerPermissions the permissions of the controller address.
53
+ * @param controller the address who want to run the execute function on the ERC725Account.
54
+ * @param permissions the permissions of the controller address.
51
55
  * @param payload the ABI encoded payload `controlledContract.execute(...)`.
52
56
  */
53
57
  function _verifyCanExecute(
54
58
  address controlledContract,
55
- address controllerAddress,
56
- bytes32 controllerPermissions,
59
+ address controller,
60
+ bytes32 permissions,
57
61
  bytes calldata payload
58
62
  ) internal view virtual {
63
+ // CHECK the offset of `data` is not pointing to the previous parameters
64
+ if (
65
+ bytes32(payload[100:132]) !=
66
+ 0x0000000000000000000000000000000000000000000000000000000000000080
67
+ ) {
68
+ revert InvalidPayload(payload);
69
+ }
70
+
59
71
  // MUST be one of the ERC725X operation types.
60
72
  uint256 operationType = uint256(bytes32(payload[4:36]));
61
73
 
62
- // DELEGATECALL is disallowed by default on the LSP6 Key Manager.
74
+ address to = address(bytes20(payload[48:68]));
75
+
76
+ // if to is the KeyManager address revert
77
+ if (to == address(this)) {
78
+ revert CallingKeyManagerNotAllowed();
79
+ }
80
+
81
+ // Future versions of the KeyManager willing to allow LSP0 to call the KeyManager
82
+ // may need to implement this check to avoid inconsistent state of reentrancy
83
+ // that may lead to lock the use of the KeyManager
84
+
85
+ // Check to restrict controllers with execute permissions to call lsp20 functions
86
+ // to avoid setting the reentrancy guard to a non-valid state
87
+
88
+ // if (payload.length >= 168 && to == address(this)) {
89
+ // if (
90
+ // bytes4(payload[164:168]) == ILSP20.lsp20VerifyCall.selector ||
91
+ // bytes4(payload[164:168]) == ILSP20.lsp20VerifyCallResult.selector
92
+ // ) {
93
+ // revert CallingLSP20FunctionsOnLSP6NotAllowed();
94
+ // }
95
+ // }
96
+
97
+ // if it is a message call
98
+ if (operationType == OPERATION_0_CALL) {
99
+ return _verifyCanCall(controlledContract, controller, permissions, payload);
100
+ }
101
+
102
+ // if it is a contract creation
103
+ if (operationType == OPERATION_1_CREATE || operationType == OPERATION_2_CREATE2) {
104
+ // required to check for permission TRANSFERVALUE if we are funding
105
+ // the contract on deployment via a payable constructor
106
+ bool isFundingContract = uint256(bytes32(payload[68:100])) != 0;
107
+
108
+ return _verifyCanDeployContract(controller, permissions, isFundingContract);
109
+ }
110
+
111
+ // if it is a STATICALL
112
+ // we do not check for TRANSFERVALUE permission,
113
+ // as ERC725X will revert if a value is provided with operation type STATICCALL.
114
+ if (operationType == OPERATION_3_STATICCALL) {
115
+ return _verifyCanStaticCall(controlledContract, controller, permissions, payload);
116
+ }
117
+
118
+ // DELEGATECALL is disallowed by default on the Key Manager.
63
119
  if (operationType == OPERATION_4_DELEGATECALL) {
64
120
  revert DelegateCallDisallowedViaKeyManager();
65
121
  }
122
+ }
123
+
124
+ function _verifyCanDeployContract(
125
+ address controller,
126
+ bytes32 permissions,
127
+ bool isFundingContract
128
+ ) internal view virtual {
129
+ _requirePermissions(controller, permissions, _PERMISSION_DEPLOY);
66
130
 
67
- uint256 value = uint256(bytes32(payload[68:100]));
131
+ bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
68
132
 
69
- // prettier-ignore
70
- bool isContractCreation = operationType == OPERATION_1_CREATE || operationType == OPERATION_2_CREATE2;
133
+ // CHECK if we are funding the contract
134
+ if (isFundingContract && !hasSuperTransferValue) {
135
+ revert NotAuthorised(controller, "SUPER_TRANSFERVALUE");
136
+ }
137
+ }
138
+
139
+ function _verifyCanStaticCall(
140
+ address controlledContract,
141
+ address controller,
142
+ bytes32 permissions,
143
+ bytes calldata payload
144
+ ) internal view virtual {
145
+ bool hasSuperStaticCall = permissions.hasPermission(_PERMISSION_SUPER_STATICCALL);
146
+
147
+ // Skip if caller has SUPER permission for static calls
148
+ if (hasSuperStaticCall) return;
149
+
150
+ _requirePermissions(controller, permissions, _PERMISSION_STATICCALL);
151
+
152
+ _verifyAllowedCall(controlledContract, controller, payload);
153
+ }
154
+
155
+ function _verifyCanCall(
156
+ address controlledContract,
157
+ address controller,
158
+ bytes32 permissions,
159
+ bytes calldata payload
160
+ ) internal view virtual {
161
+ bool isTransferringValue = uint256(bytes32(payload[68:100])) != 0;
162
+
163
+ bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
164
+
165
+ // all the parameters are abi-encoded (padded to 32 bytes words)
166
+ //
167
+ // 4 (ERC725X.execute selector)
168
+ // + 32 (uint256 operationType)
169
+ // + 32 (address to/target)
170
+ // + 32 (uint256 value)
171
+ // + 32 (`data` offset)
172
+ // + 32 (`data` length)
173
+ // --------------------
174
+ // = 164 bytes in total
71
175
  bool isCallDataPresent = payload.length > 164;
72
176
 
73
- // SUPER operation only applies to contract call, not contract creation
74
- bool hasSuperOperation = isContractCreation
75
- ? false
76
- : controllerPermissions.hasPermission(
77
- _extractSuperPermissionFromOperation(operationType)
78
- );
177
+ bool hasSuperCall = permissions.hasPermission(_PERMISSION_SUPER_CALL);
79
178
 
80
- // CHECK if we are doing an empty call, as the receive() or fallback() function
81
- // of the controlledContract could run some code.
82
- if (!hasSuperOperation && !isCallDataPresent && value == 0) {
83
- _requirePermissions(
84
- controllerAddress,
85
- controllerPermissions,
86
- _extractPermissionFromOperation(operationType)
87
- );
179
+ if (isTransferringValue && !hasSuperTransferValue) {
180
+ _requirePermissions(controller, permissions, _PERMISSION_TRANSFERVALUE);
88
181
  }
89
182
 
90
- if (isCallDataPresent && !hasSuperOperation) {
91
- _requirePermissions(
92
- controllerAddress,
93
- controllerPermissions,
94
- _extractPermissionFromOperation(operationType)
95
- );
183
+ // CHECK if we are doing an empty call, as the receive() or fallback() function
184
+ // of the controlledContract could run some code.
185
+ if (!hasSuperCall && !isCallDataPresent && !isTransferringValue) {
186
+ _requirePermissions(controller, permissions, _PERMISSION_CALL);
96
187
  }
97
188
 
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
- );
189
+ if (isCallDataPresent && !hasSuperCall) {
190
+ _requirePermissions(controller, permissions, _PERMISSION_CALL);
108
191
  }
109
192
 
110
- // Skip on contract creation (CREATE or CREATE2)
111
- if (isContractCreation) return;
112
-
113
193
  // Skip if caller has SUPER permissions for external calls, with or without calldata (empty calls)
114
- if (hasSuperOperation && value == 0) return;
194
+ if (hasSuperCall && !isTransferringValue) return;
115
195
 
116
196
  // Skip if caller has SUPER permission for value transfers
117
- if (hasSuperTransferValue && !isCallDataPresent && value != 0) return;
197
+ if (hasSuperTransferValue && !isCallDataPresent && isTransferringValue) return;
118
198
 
119
199
  // Skip if both SUPER permissions are present
120
- if (hasSuperOperation && hasSuperTransferValue) return;
200
+ if (hasSuperCall && hasSuperTransferValue) return;
121
201
 
122
- _verifyAllowedCall(controlledContract, controllerAddress, payload);
202
+ _verifyAllowedCall(controlledContract, controller, payload);
123
203
  }
124
204
 
125
205
  function _verifyAllowedCall(
@@ -127,87 +207,177 @@ abstract contract LSP6ExecuteModule {
127
207
  address controllerAddress,
128
208
  bytes calldata payload
129
209
  ) internal view virtual {
130
- // CHECK for ALLOWED CALLS
131
- address to = address(bytes20(payload[48:68]));
132
-
133
- bool containsFunctionCall = payload.length >= 168;
134
- bytes4 selector;
135
- if (containsFunctionCall) selector = bytes4(payload[164:168]);
210
+ (
211
+ uint256 operationType,
212
+ address to,
213
+ uint256 value,
214
+ bytes4 selector,
215
+ bool isEmptyCall
216
+ ) = _extractExecuteParameters(payload);
136
217
 
218
+ // CHECK for ALLOWED CALLS
137
219
  bytes memory allowedCalls = ERC725Y(controlledContract).getAllowedCallsFor(
138
220
  controllerAddress
139
221
  );
140
- uint256 allowedCallsLength = allowedCalls.length;
141
222
 
142
- if (allowedCallsLength == 0) {
223
+ if (allowedCalls.length == 0) {
143
224
  revert NoCallsAllowed(controllerAddress);
144
225
  }
145
226
 
146
- bool isAllowedStandard;
147
- bool isAllowedAddress;
148
- bool isAllowedFunction;
149
-
150
- for (uint256 ii; ii < allowedCallsLength; ii += 30) {
151
- if (ii + 30 > allowedCallsLength) {
227
+ bytes4 requiredCallTypes = _extractCallType(operationType, value, isEmptyCall);
228
+
229
+ for (uint256 ii; ii < allowedCalls.length; ii += 34) {
230
+ /// @dev structure of an AllowedCall
231
+ //
232
+ /// AllowedCall = 0x00200000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
233
+ ///
234
+ /// 0020 = hex for '32' bytes long
235
+ /// 0000000n = call type(s)
236
+ /// cafecafecafecafecafecafecafecafecafecafe = address
237
+ /// 5a5a5a5a = standard
238
+ /// f1f1f1f1 = function
239
+
240
+ // CHECK that we can extract an AllowedCall
241
+ if (ii + 34 > allowedCalls.length) {
152
242
  revert InvalidEncodedAllowedCalls(allowedCalls);
153
243
  }
154
- bytes memory chunk = BytesLib.slice(allowedCalls, ii + 2, 28);
155
244
 
156
- if (bytes28(chunk) == 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff) {
245
+ // extract one AllowedCall at a time
246
+ bytes memory allowedCall = BytesLib.slice(allowedCalls, ii + 2, 32);
247
+
248
+ // 0xxxxxxxxxffffffffffffffffffffffffffffffffffffffffffffffffffffffff
249
+ // (excluding the callTypes) not allowed
250
+ // as equivalent to whitelisting any call (= SUPER permission)
251
+ if (bytes28(bytes32(allowedCall) << 32) == bytes28(type(uint224).max)) {
157
252
  revert InvalidWhitelistedCall(controllerAddress);
158
253
  }
159
254
 
160
- bytes4 allowedStandard = bytes4(chunk);
161
- address allowedAddress = address(bytes20(bytes28(chunk) << 32));
162
- bytes4 allowedFunction = bytes4(bytes28(chunk) << 192);
163
-
164
- isAllowedStandard =
165
- allowedStandard == 0xffffffff ||
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;
255
+ if (
256
+ _isAllowedCallType(allowedCall, requiredCallTypes) &&
257
+ _isAllowedAddress(allowedCall, to) &&
258
+ _isAllowedStandard(allowedCall, to) &&
259
+ _isAllowedFunction(allowedCall, selector)
260
+ ) return;
175
261
  }
176
262
 
177
263
  revert NotAllowedCall(controllerAddress, to, selector);
178
264
  }
179
265
 
180
266
  /**
181
- * @dev extract the required permission + a descriptive string, based on the `_operationType`
182
- * being run via ERC725Account.execute(...)
183
- * @param operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
184
- * @return permissionsRequired (bytes32) the permission associated with the `_operationType`
267
+ * @dev extract the bytes4 representation of a single bit for the type of call according to the `operationType`
268
+ * @param operationType 0 = CALL, 3 = STATICCALL or 3 = DELEGATECALL
269
+ * @return requiredCallTypes a bytes4 value containing a single 1 bit for the callType
185
270
  */
186
- function _extractPermissionFromOperation(uint256 operationType)
271
+ function _extractCallType(
272
+ uint256 operationType,
273
+ uint256 value,
274
+ bool isEmptyCall
275
+ ) internal pure returns (bytes4 requiredCallTypes) {
276
+ // if there is value being transferred, add the extra bit
277
+ // for the first bit for Value Transfer in the `requiredCallTypes`
278
+ if (value != 0) {
279
+ requiredCallTypes |= _ALLOWEDCALLS_TRANSFERVALUE;
280
+ }
281
+
282
+ if (!isEmptyCall) {
283
+ if (operationType == OPERATION_0_CALL) {
284
+ requiredCallTypes |= _ALLOWEDCALLS_CALL;
285
+ } else if (operationType == OPERATION_3_STATICCALL) {
286
+ requiredCallTypes |= _ALLOWEDCALLS_STATICCALL;
287
+ } else if (operationType == OPERATION_4_DELEGATECALL) {
288
+ requiredCallTypes |= _ALLOWEDCALLS_DELEGATECALL;
289
+ }
290
+ }
291
+ }
292
+
293
+ function _extractExecuteParameters(bytes calldata executeCalldata)
187
294
  internal
188
295
  pure
189
- virtual
190
- returns (bytes32 permissionsRequired)
296
+ returns (
297
+ uint256,
298
+ address,
299
+ uint256,
300
+ bytes4,
301
+ bool
302
+ )
191
303
  {
192
- if (operationType == OPERATION_0_CALL) return _PERMISSION_CALL;
193
- else if (operationType == OPERATION_1_CREATE) return _PERMISSION_DEPLOY;
194
- else if (operationType == OPERATION_2_CREATE2) return _PERMISSION_DEPLOY;
195
- else if (operationType == OPERATION_3_STATICCALL) return _PERMISSION_STATICCALL;
196
- else if (operationType == OPERATION_4_DELEGATECALL) return _PERMISSION_DELEGATECALL;
304
+ uint256 operationType = uint256(bytes32(executeCalldata[4:36]));
305
+
306
+ // CHECK that it is a valid address left-padded with `00` on the 12 upper bytes
307
+ if (bytes12(executeCalldata[36:48]) != bytes12(0)) {
308
+ revert InvalidPayload(executeCalldata);
309
+ }
310
+ address to = address(bytes20(executeCalldata[48:68]));
311
+
312
+ uint256 value = uint256(bytes32(executeCalldata[68:100]));
313
+
314
+ // CHECK if there is at least a 4 bytes function selector
315
+ bytes4 selector = executeCalldata.length >= 168
316
+ ? bytes4(executeCalldata[164:168])
317
+ : bytes4(0);
318
+
319
+ return (operationType, to, value, selector, executeCalldata.length == 164);
197
320
  }
198
321
 
199
- /**
200
- * @dev returns the `superPermission` needed for a specific `operationType` of the `execute(..)`
201
- */
202
- function _extractSuperPermissionFromOperation(uint256 operationType)
322
+ function _isAllowedAddress(bytes memory allowedCall, address to) internal pure returns (bool) {
323
+ // <offset> = 4 bytes x 8 bits = 32 bits
324
+ //
325
+ // <offset>v----------------address---------------v
326
+ // 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
327
+ address allowedAddress = address(bytes20(bytes32(allowedCall) << 32));
328
+
329
+ // ANY address = 0xffffffffffffffffffffffffffffffffffffffff
330
+ return allowedAddress == address(bytes20(type(uint160).max)) || to == allowedAddress;
331
+ }
332
+
333
+ function _isAllowedStandard(bytes memory allowedCall, address to) internal view returns (bool) {
334
+ // <offset> = 24 bytes x 8 bits = 192 bits
335
+ //
336
+ // standard
337
+ // <----------------<offset>---------------------->v------v
338
+ // 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
339
+ bytes4 allowedStandard = bytes4(bytes32(allowedCall) << 192);
340
+
341
+ // ANY Standard = 0xffffffff
342
+ return
343
+ allowedStandard == bytes4(type(uint32).max) ||
344
+ to.supportsERC165InterfaceUnchecked(allowedStandard);
345
+ }
346
+
347
+ function _isAllowedFunction(bytes memory allowedCall, bytes4 requiredFunction)
348
+ internal
349
+ pure
350
+ returns (bool)
351
+ {
352
+ // <offset> = 28 bytes x 8 bits = 224 bits
353
+ //
354
+ // function
355
+ // <------------------------<offset>---------------------->v------v
356
+ // 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
357
+ bytes4 allowedFunction = bytes4(bytes32(allowedCall) << 224);
358
+
359
+ bool isFunctionCall = requiredFunction != bytes4(0);
360
+
361
+ // ANY function = 0xffffffff
362
+ return
363
+ allowedFunction == bytes4(type(uint32).max) ||
364
+ (isFunctionCall && (requiredFunction == allowedFunction));
365
+ }
366
+
367
+ function _isAllowedCallType(bytes memory allowedCall, bytes4 requiredCallTypes)
203
368
  internal
204
369
  pure
205
- virtual
206
- returns (bytes32 superPermission)
370
+ returns (bool)
207
371
  {
208
- if (operationType == OPERATION_0_CALL) return _PERMISSION_SUPER_CALL;
209
- else if (operationType == OPERATION_3_STATICCALL) return _PERMISSION_SUPER_STATICCALL;
210
- else if (operationType == OPERATION_4_DELEGATECALL) return _PERMISSION_SUPER_DELEGATECALL;
372
+ // extract callType
373
+ //
374
+ // <offset> = 0
375
+ //
376
+ // callType
377
+ // v------v
378
+ // 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
379
+ bytes4 allowedCallType = bytes4(allowedCall);
380
+ return (allowedCallType & requiredCallTypes == requiredCallTypes);
211
381
  }
212
382
 
213
383
  /**