@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
@@ -4,6 +4,9 @@ pragma solidity ^0.8.5;
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
6
  import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
7
+ import {
8
+ ILSP20CallVerification as ILSP20
9
+ } from "../LSP20CallVerification/ILSP20CallVerification.sol";
7
10
 
8
11
  // modules
9
12
  import {ILSP14Ownable2Step} from "../LSP14Ownable2Step/ILSP14Ownable2Step.sol";
@@ -14,7 +17,6 @@ import {LSP6ExecuteModule} from "./LSP6Modules/LSP6ExecuteModule.sol";
14
17
  import {LSP6OwnershipModule} from "./LSP6Modules/LSP6OwnershipModule.sol";
15
18
 
16
19
  // libraries
17
- import {GasLib} from "../Utils/GasLib.sol";
18
20
  import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
19
21
  import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
20
22
  import {Address} from "@openzeppelin/contracts/utils/Address.sol";
@@ -31,13 +33,15 @@ import {
31
33
  InvalidRelayNonce,
32
34
  NoPermissionsSet,
33
35
  InvalidERC725Function,
34
- NotAuthorised
36
+ CannotSendValueToSetData,
37
+ RelayCallBeforeStartTime,
38
+ RelayCallExpired
35
39
  } from "./LSP6Errors.sol";
36
40
 
37
41
  // constants
38
42
  import {
39
43
  SETDATA_SELECTOR,
40
- SETDATA_ARRAY_SELECTOR,
44
+ SETDATA_BATCH_SELECTOR,
41
45
  EXECUTE_SELECTOR
42
46
  } from "@erc725/smart-contracts/contracts/constants.sol";
43
47
  import {
@@ -51,6 +55,7 @@ import {
51
55
  _PERMISSION_SIGN,
52
56
  _PERMISSION_REENTRANCY
53
57
  } from "./LSP6Constants.sol";
58
+ import "../LSP20CallVerification/LSP20Constants.sol";
54
59
 
55
60
  /**
56
61
  * @title Core implementation of the LSP6 Key Manager standard.
@@ -61,6 +66,7 @@ import {
61
66
  abstract contract LSP6KeyManagerCore is
62
67
  ERC165,
63
68
  ILSP6KeyManager,
69
+ ILSP20,
64
70
  LSP6SetDataModule,
65
71
  LSP6ExecuteModule,
66
72
  LSP6OwnershipModule
@@ -89,6 +95,7 @@ abstract contract LSP6KeyManagerCore is
89
95
  return
90
96
  interfaceId == _INTERFACEID_LSP6 ||
91
97
  interfaceId == _INTERFACEID_ERC1271 ||
98
+ interfaceId == _INTERFACEID_LSP20_CALL_VERIFIER ||
92
99
  super.supportsInterface(interfaceId);
93
100
  }
94
101
 
@@ -108,8 +115,16 @@ abstract contract LSP6KeyManagerCore is
108
115
  view
109
116
  returns (bytes4 magicValue)
110
117
  {
111
- address recoveredAddress = dataHash.recover(signature);
118
+ // if isValidSignature fail, the error is catched in returnedError
119
+ (address recoveredAddress, ECDSA.RecoverError returnedError) = ECDSA.tryRecover(
120
+ dataHash,
121
+ signature
122
+ );
123
+
124
+ // if recovering throws an error, return the fail value
125
+ if (returnedError != ECDSA.RecoverError.NoError) return _ERC1271_FAILVALUE;
112
126
 
127
+ // if the address recovered has SIGN permission return the ERC1271 magic value, otherwise the fail value
113
128
  return (
114
129
  ERC725Y(_target).getPermissionsFor(recoveredAddress).hasPermission(_PERMISSION_SIGN)
115
130
  ? _ERC1271_MAGICVALUE
@@ -127,7 +142,7 @@ abstract contract LSP6KeyManagerCore is
127
142
  /**
128
143
  * @inheritdoc ILSP6KeyManager
129
144
  */
130
- function execute(uint256[] calldata values, bytes[] calldata payloads)
145
+ function executeBatch(uint256[] calldata values, bytes[] calldata payloads)
131
146
  public
132
147
  payable
133
148
  virtual
@@ -140,12 +155,16 @@ abstract contract LSP6KeyManagerCore is
140
155
  bytes[] memory results = new bytes[](payloads.length);
141
156
  uint256 totalValues;
142
157
 
143
- for (uint256 ii; ii < payloads.length; ii = GasLib.uncheckedIncrement(ii)) {
158
+ for (uint256 ii; ii < payloads.length; ) {
144
159
  if ((totalValues += values[ii]) > msg.value) {
145
160
  revert LSP6BatchInsufficientValueSent(totalValues, msg.value);
146
161
  }
147
162
 
148
163
  results[ii] = _execute(values[ii], payloads[ii]);
164
+
165
+ unchecked {
166
+ ++ii;
167
+ }
149
168
  }
150
169
 
151
170
  if (totalValues < msg.value) {
@@ -161,23 +180,26 @@ abstract contract LSP6KeyManagerCore is
161
180
  function executeRelayCall(
162
181
  bytes memory signature,
163
182
  uint256 nonce,
183
+ uint256 validityTimestamps,
164
184
  bytes calldata payload
165
185
  ) public payable virtual returns (bytes memory) {
166
- return _executeRelayCall(signature, nonce, msg.value, payload);
186
+ return _executeRelayCall(signature, nonce, validityTimestamps, msg.value, payload);
167
187
  }
168
188
 
169
189
  /**
170
190
  * @inheritdoc ILSP6KeyManager
171
191
  */
172
- function executeRelayCall(
192
+ function executeRelayCallBatch(
173
193
  bytes[] memory signatures,
174
194
  uint256[] calldata nonces,
195
+ uint256[] calldata validityTimestamps,
175
196
  uint256[] calldata values,
176
197
  bytes[] calldata payloads
177
198
  ) public payable virtual returns (bytes[] memory) {
178
199
  if (
179
200
  signatures.length != nonces.length ||
180
- nonces.length != values.length ||
201
+ nonces.length != validityTimestamps.length ||
202
+ validityTimestamps.length != values.length ||
181
203
  values.length != payloads.length
182
204
  ) {
183
205
  revert BatchExecuteRelayCallParamsLengthMismatch();
@@ -186,12 +208,22 @@ abstract contract LSP6KeyManagerCore is
186
208
  bytes[] memory results = new bytes[](payloads.length);
187
209
  uint256 totalValues;
188
210
 
189
- for (uint256 ii; ii < payloads.length; ii = GasLib.uncheckedIncrement(ii)) {
211
+ for (uint256 ii; ii < payloads.length; ) {
190
212
  if ((totalValues += values[ii]) > msg.value) {
191
213
  revert LSP6BatchInsufficientValueSent(totalValues, msg.value);
192
214
  }
193
215
 
194
- results[ii] = _executeRelayCall(signatures[ii], nonces[ii], values[ii], payloads[ii]);
216
+ results[ii] = _executeRelayCall(
217
+ signatures[ii],
218
+ nonces[ii],
219
+ validityTimestamps[ii],
220
+ values[ii],
221
+ payloads[ii]
222
+ );
223
+
224
+ unchecked {
225
+ ++ii;
226
+ }
195
227
  }
196
228
 
197
229
  if (totalValues < msg.value) {
@@ -201,6 +233,70 @@ abstract contract LSP6KeyManagerCore is
201
233
  return results;
202
234
  }
203
235
 
236
+ /**
237
+ * @inheritdoc ILSP20
238
+ */
239
+ function lsp20VerifyCall(
240
+ address caller,
241
+ uint256 msgValue,
242
+ bytes calldata data
243
+ ) external returns (bytes4) {
244
+ bool isSetData = false;
245
+ if (bytes4(data) == SETDATA_SELECTOR || bytes4(data) == SETDATA_BATCH_SELECTOR) {
246
+ isSetData = true;
247
+ }
248
+
249
+ // If target is invoking the verification, emit the event and change the reentrancy guard
250
+ if (msg.sender == _target) {
251
+ bool isReentrantCall = _nonReentrantBefore(isSetData, caller);
252
+
253
+ _verifyPermissions(caller, msgValue, data);
254
+ emit VerifiedCall(caller, msgValue, bytes4(data));
255
+
256
+ // if it's a setData call, do not invoke the `lsp20VerifyCallResult(..)` function
257
+ return
258
+ isSetData || isReentrantCall
259
+ ? _LSP20_VERIFY_CALL_MAGIC_VALUE_WITHOUT_POST_VERIFICATION
260
+ : _LSP20_VERIFY_CALL_MAGIC_VALUE_WITH_POST_VERIFICATION;
261
+ }
262
+ // If a different address is invoking the verification, do not change the state
263
+ // and do read-only verification
264
+ else {
265
+ bool isReentrantCall = _reentrancyStatus;
266
+
267
+ if (isReentrantCall) {
268
+ _requirePermissions(
269
+ caller,
270
+ ERC725Y(_target).getPermissionsFor(caller),
271
+ _PERMISSION_REENTRANCY
272
+ );
273
+ }
274
+
275
+ _verifyPermissions(caller, msgValue, data);
276
+
277
+ // if it's a setData call, do not invoke the `lsp20VerifyCallResult(..)` function
278
+ return
279
+ isSetData || isReentrantCall
280
+ ? _LSP20_VERIFY_CALL_MAGIC_VALUE_WITHOUT_POST_VERIFICATION
281
+ : _LSP20_VERIFY_CALL_MAGIC_VALUE_WITH_POST_VERIFICATION;
282
+ }
283
+ }
284
+
285
+ /**
286
+ * @inheritdoc ILSP20
287
+ */
288
+ function lsp20VerifyCallResult(
289
+ bytes32, /*callHash*/
290
+ bytes memory /*result*/
291
+ ) external returns (bytes4) {
292
+ // If it's the target calling, set back the reentrancy guard
293
+ // to false, if not return the magic value
294
+ if (msg.sender == _target) {
295
+ _nonReentrantAfter();
296
+ }
297
+ return _LSP20_VERIFY_CALL_RESULT_MAGIC_VALUE;
298
+ }
299
+
204
300
  function _execute(uint256 msgValue, bytes calldata payload)
205
301
  internal
206
302
  virtual
@@ -210,16 +306,29 @@ abstract contract LSP6KeyManagerCore is
210
306
  revert InvalidPayload(payload);
211
307
  }
212
308
 
213
- _nonReentrantBefore(msg.sender);
214
- _verifyPermissions(msg.sender, payload);
309
+ bool isSetData = false;
310
+ if (bytes4(payload) == SETDATA_SELECTOR || bytes4(payload) == SETDATA_BATCH_SELECTOR) {
311
+ isSetData = true;
312
+ }
313
+
314
+ bool isReentrantCall = _nonReentrantBefore(isSetData, msg.sender);
315
+
316
+ _verifyPermissions(msg.sender, msgValue, payload);
317
+ emit VerifiedCall(msg.sender, msgValue, bytes4(payload));
318
+
215
319
  bytes memory result = _executePayload(msgValue, payload);
216
- _nonReentrantAfter();
320
+
321
+ if (!isReentrantCall && !isSetData) {
322
+ _nonReentrantAfter();
323
+ }
324
+
217
325
  return result;
218
326
  }
219
327
 
220
328
  function _executeRelayCall(
221
329
  bytes memory signature,
222
330
  uint256 nonce,
331
+ uint256 validityTimestamps,
223
332
  uint256 msgValue,
224
333
  bytes calldata payload
225
334
  ) internal virtual returns (bytes memory) {
@@ -231,6 +340,7 @@ abstract contract LSP6KeyManagerCore is
231
340
  LSP6_VERSION,
232
341
  block.chainid,
233
342
  nonce,
343
+ validityTimestamps,
234
344
  msgValue,
235
345
  payload
236
346
  );
@@ -239,7 +349,12 @@ abstract contract LSP6KeyManagerCore is
239
349
  signature
240
350
  );
241
351
 
242
- _nonReentrantBefore(signer);
352
+ bool isSetData = false;
353
+ if (bytes4(payload) == SETDATA_SELECTOR || bytes4(payload) == SETDATA_BATCH_SELECTOR) {
354
+ isSetData = true;
355
+ }
356
+
357
+ bool isReentrantCall = _nonReentrantBefore(isSetData, signer);
243
358
 
244
359
  if (!_isValidNonce(signer, nonce)) {
245
360
  revert InvalidRelayNonce(signer, nonce, signature);
@@ -248,11 +363,27 @@ abstract contract LSP6KeyManagerCore is
248
363
  // increase nonce after successful verification
249
364
  _nonceStore[signer][nonce >> 128]++;
250
365
 
251
- _verifyPermissions(signer, payload);
366
+ if (validityTimestamps != 0) {
367
+ uint128 startingTimestamp = uint128(validityTimestamps >> 128);
368
+ uint128 endingTimestamp = uint128(validityTimestamps);
369
+
370
+ // solhint-disable not-rely-on-time
371
+ if (block.timestamp < startingTimestamp) {
372
+ revert RelayCallBeforeStartTime();
373
+ }
374
+ if (block.timestamp > endingTimestamp) {
375
+ revert RelayCallExpired();
376
+ }
377
+ }
378
+
379
+ _verifyPermissions(signer, msgValue, payload);
380
+ emit VerifiedCall(signer, msgValue, bytes4(payload));
252
381
 
253
382
  bytes memory result = _executePayload(msgValue, payload);
254
383
 
255
- _nonReentrantAfter();
384
+ if (!isReentrantCall && !isSetData) {
385
+ _nonReentrantAfter();
386
+ }
256
387
 
257
388
  return result;
258
389
  }
@@ -267,8 +398,6 @@ abstract contract LSP6KeyManagerCore is
267
398
  virtual
268
399
  returns (bytes memory)
269
400
  {
270
- emit Executed(bytes4(payload), msgValue);
271
-
272
401
  (bool success, bytes memory returnData) = _target.call{value: msgValue, gas: gasleft()}(
273
402
  payload
274
403
  );
@@ -290,10 +419,11 @@ abstract contract LSP6KeyManagerCore is
290
419
  * @param idx (channel id + nonce within the channel)
291
420
  */
292
421
  function _isValidNonce(address from, uint256 idx) internal view virtual returns (bool) {
293
- // idx % (1 << 128) = nonce
294
- // (idx >> 128) = channel
295
- // equivalent to: return (nonce == _nonceStore[_from][channel]
296
- return (idx % (1 << 128)) == (_nonceStore[from][idx >> 128]);
422
+ uint256 mask = ~uint128(0);
423
+ // Alternatively:
424
+ // uint256 mask = (1<<128)-1;
425
+ // uint256 mask = 0xffffffffffffffffffffffffffffffff;
426
+ return (idx & mask) == (_nonceStore[from][idx >> 128]);
297
427
  }
298
428
 
299
429
  /**
@@ -301,7 +431,11 @@ abstract contract LSP6KeyManagerCore is
301
431
  * @param from either the caller of `execute(...)` or the signer of `executeRelayCall(...)`.
302
432
  * @param payload the payload to execute on the `target`.
303
433
  */
304
- function _verifyPermissions(address from, bytes calldata payload) internal view virtual {
434
+ function _verifyPermissions(
435
+ address from,
436
+ uint256 msgValue,
437
+ bytes calldata payload
438
+ ) internal view virtual {
305
439
  bytes32 permissions = ERC725Y(_target).getPermissionsFor(from);
306
440
  if (permissions == bytes32(0)) revert NoPermissionsSet(from);
307
441
 
@@ -309,12 +443,14 @@ abstract contract LSP6KeyManagerCore is
309
443
 
310
444
  // ERC725Y.setData(bytes32,bytes)
311
445
  if (erc725Function == SETDATA_SELECTOR) {
446
+ if (msgValue != 0) revert CannotSendValueToSetData();
312
447
  (bytes32 inputKey, bytes memory inputValue) = abi.decode(payload[4:], (bytes32, bytes));
313
448
 
314
449
  LSP6SetDataModule._verifyCanSetData(_target, from, permissions, inputKey, inputValue);
315
450
 
316
- // ERC725Y.setData(bytes32[],bytes[])
317
- } else if (erc725Function == SETDATA_ARRAY_SELECTOR) {
451
+ // ERC725Y.setDataBatch(bytes32[],bytes[])
452
+ } else if (erc725Function == SETDATA_BATCH_SELECTOR) {
453
+ if (msgValue != 0) revert CannotSendValueToSetData();
318
454
  (bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(
319
455
  payload[4:],
320
456
  (bytes32[], bytes[])
@@ -347,8 +483,13 @@ abstract contract LSP6KeyManagerCore is
347
483
  * the status is `_ENTERED` in order to revert the call unless the caller has the REENTRANCY permission
348
484
  * Used in the beginning of the `nonReentrant` modifier, before the method execution starts.
349
485
  */
350
- function _nonReentrantBefore(address from) internal virtual {
351
- if (_reentrancyStatus) {
486
+ function _nonReentrantBefore(bool isSetData, address from)
487
+ internal
488
+ virtual
489
+ returns (bool isReentrantCall)
490
+ {
491
+ isReentrantCall = _reentrancyStatus;
492
+ if (isReentrantCall) {
352
493
  // CHECK the caller has REENTRANCY permission
353
494
  _requirePermissions(
354
495
  from,
@@ -356,7 +497,9 @@ abstract contract LSP6KeyManagerCore is
356
497
  _PERMISSION_REENTRANCY
357
498
  );
358
499
  } else {
359
- _reentrancyStatus = true;
500
+ if (!isSetData) {
501
+ _reentrancyStatus = true;
502
+ }
360
503
  }
361
504
  }
362
505
 
@@ -2,7 +2,6 @@
2
2
  pragma solidity ^0.8.5;
3
3
 
4
4
  // modules
5
- import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
6
5
  import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7
6
  import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
8
7
  import {InvalidLSP6Target} from "./LSP6Errors.sol";