@lukso/lsp-smart-contracts 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +3 -3
- package/artifacts/LSP0ERC725AccountInit.json +3 -3
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
- package/artifacts/LSP6KeyManager.json +2 -2
- package/artifacts/LSP6KeyManagerInit.json +2 -2
- package/artifacts/LSP7CompatibleERC20Mintable.json +2 -2
- package/artifacts/LSP7CompatibleERC20MintableInit.json +2 -2
- package/artifacts/LSP7Mintable.json +2 -2
- package/artifacts/LSP7MintableInit.json +2 -2
- package/artifacts/LSP8CompatibleERC721Mintable.json +2 -2
- package/artifacts/LSP8CompatibleERC721MintableInit.json +2 -2
- package/artifacts/LSP8Mintable.json +2 -2
- package/artifacts/LSP8MintableInit.json +2 -2
- package/artifacts/LSP9Vault.json +2 -2
- package/artifacts/LSP9VaultInit.json +2 -2
- package/artifacts/UniversalProfile.json +3 -3
- package/artifacts/UniversalProfileInit.json +3 -3
- package/artifacts/UniversalReceiverAddressStore.json +2 -2
- package/contracts/Factories/Create2Factory.sol +11 -3
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +13 -5
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +5 -5
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +256 -186
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +6 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +13 -4
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +3 -5
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +25 -10
- package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +4 -2
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +3 -1
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +65 -23
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +7 -2
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +14 -4
- package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +4 -1
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +17 -16
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +4 -1
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +22 -11
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +85 -27
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +38 -16
- package/contracts/LSP17ContractExtension/LSP17Extension.sol +20 -8
- package/contracts/LSP17ContractExtension/LSP17Utils.sol +4 -5
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +38 -14
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +31 -11
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +34 -9
- package/contracts/LSP20CallVerification/{ILSP20CallVerification.sol → ILSP20CallVerifier.sol} +7 -2
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +24 -9
- package/contracts/LSP20CallVerification/LSP20Errors.sol +1 -1
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +62 -36
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +3 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +15 -4
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +18 -5
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -12
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +17 -8
- package/contracts/LSP6KeyManager/LSP6Constants.sol +3 -9
- package/contracts/LSP6KeyManager/LSP6Errors.sol +4 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +114 -72
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -2
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +96 -46
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +10 -5
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +98 -32
- package/contracts/LSP6KeyManager/LSP6Utils.sol +42 -34
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +8 -6
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +13 -10
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +96 -26
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +11 -9
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +8 -2
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +9 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +1 -5
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +4 -6
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +6 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +32 -12
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +28 -7
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +8 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +6 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +6 -1
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +13 -3
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +14 -5
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +12 -10
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +95 -28
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +14 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +23 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +72 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +77 -27
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +8 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +6 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +5 -1
- package/contracts/LSP9Vault/ILSP9Vault.sol +13 -5
- package/contracts/LSP9Vault/LSP9Vault.sol +7 -2
- package/contracts/LSP9Vault/LSP9VaultCore.sol +108 -51
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +10 -3
- package/contracts/Legacy/Registries/AddressRegistry.sol +13 -4
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +6 -2
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +17 -6
- package/contracts/UniversalProfile.sol +4 -1
- package/contracts/UniversalProfileInit.sol +3 -1
- package/contracts/UniversalProfileInitAbstract.sol +13 -4
- package/devdocs/LSP0ERC725Account.json +33 -19
- package/devdocs/LSP0ERC725AccountInit.json +30 -17
- package/devdocs/LSP9Vault.json +3 -3
- package/devdocs/LSP9VaultInit.json +3 -3
- package/devdocs/UniversalProfile.json +30 -17
- package/devdocs/UniversalProfileInit.json +30 -17
- package/dist/constants.cjs.js +142 -102
- package/dist/constants.d.ts +62 -10
- package/dist/constants.es.js +142 -102
- package/package.json +17 -16
- package/userdocs/LSP0ERC725Account.json +2 -2
- package/userdocs/LSP0ERC725AccountInit.json +2 -2
- package/userdocs/UniversalProfile.json +2 -2
- package/userdocs/UniversalProfileInit.json +2 -2
- package/contracts/Custom/EIP191Signer.sol +0 -12
|
@@ -3,10 +3,16 @@ pragma solidity ^0.8.5;
|
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
6
|
+
import {
|
|
7
|
+
IERC725X
|
|
8
|
+
} from "@erc725/smart-contracts/contracts/interfaces/IERC725X.sol";
|
|
9
|
+
import {
|
|
10
|
+
IERC725Y
|
|
11
|
+
} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
6
12
|
import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
|
|
7
13
|
import {
|
|
8
|
-
|
|
9
|
-
} from "../LSP20CallVerification/
|
|
14
|
+
ILSP20CallVerifier as ILSP20
|
|
15
|
+
} from "../LSP20CallVerification/ILSP20CallVerifier.sol";
|
|
10
16
|
|
|
11
17
|
// modules
|
|
12
18
|
import {ILSP14Ownable2Step} from "../LSP14Ownable2Step/ILSP14Ownable2Step.sol";
|
|
@@ -21,7 +27,6 @@ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
|
21
27
|
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
22
28
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
23
29
|
import {LSP6Utils} from "./LSP6Utils.sol";
|
|
24
|
-
import {EIP191Signer} from "../Custom/EIP191Signer.sol";
|
|
25
30
|
|
|
26
31
|
// errors
|
|
27
32
|
import {
|
|
@@ -38,12 +43,6 @@ import {
|
|
|
38
43
|
RelayCallExpired
|
|
39
44
|
} from "./LSP6Errors.sol";
|
|
40
45
|
|
|
41
|
-
// constants
|
|
42
|
-
import {
|
|
43
|
-
SETDATA_SELECTOR,
|
|
44
|
-
SETDATA_BATCH_SELECTOR,
|
|
45
|
-
EXECUTE_SELECTOR
|
|
46
|
-
} from "@erc725/smart-contracts/contracts/constants.sol";
|
|
47
46
|
import {
|
|
48
47
|
_INTERFACEID_ERC1271,
|
|
49
48
|
_ERC1271_MAGICVALUE,
|
|
@@ -72,8 +71,7 @@ abstract contract LSP6KeyManagerCore is
|
|
|
72
71
|
LSP6OwnershipModule
|
|
73
72
|
{
|
|
74
73
|
using LSP6Utils for *;
|
|
75
|
-
using ECDSA for
|
|
76
|
-
using EIP191Signer for address;
|
|
74
|
+
using ECDSA for *;
|
|
77
75
|
using BytesLib for bytes;
|
|
78
76
|
|
|
79
77
|
address internal _target;
|
|
@@ -91,7 +89,9 @@ abstract contract LSP6KeyManagerCore is
|
|
|
91
89
|
/**
|
|
92
90
|
* @dev See {IERC165-supportsInterface}.
|
|
93
91
|
*/
|
|
94
|
-
function supportsInterface(
|
|
92
|
+
function supportsInterface(
|
|
93
|
+
bytes4 interfaceId
|
|
94
|
+
) public view virtual override returns (bool) {
|
|
95
95
|
return
|
|
96
96
|
interfaceId == _INTERFACEID_LSP6 ||
|
|
97
97
|
interfaceId == _INTERFACEID_ERC1271 ||
|
|
@@ -102,7 +102,10 @@ abstract contract LSP6KeyManagerCore is
|
|
|
102
102
|
/**
|
|
103
103
|
* @inheritdoc ILSP6KeyManager
|
|
104
104
|
*/
|
|
105
|
-
function getNonce(
|
|
105
|
+
function getNonce(
|
|
106
|
+
address from,
|
|
107
|
+
uint128 channelId
|
|
108
|
+
) public view returns (uint256) {
|
|
106
109
|
uint256 nonceInChannel = _nonceStore[from][channelId];
|
|
107
110
|
return (uint256(channelId) << 128) | nonceInChannel;
|
|
108
111
|
}
|
|
@@ -110,23 +113,23 @@ abstract contract LSP6KeyManagerCore is
|
|
|
110
113
|
/**
|
|
111
114
|
* @inheritdoc IERC1271
|
|
112
115
|
*/
|
|
113
|
-
function isValidSignature(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
{
|
|
116
|
+
function isValidSignature(
|
|
117
|
+
bytes32 dataHash,
|
|
118
|
+
bytes memory signature
|
|
119
|
+
) public view returns (bytes4 magicValue) {
|
|
118
120
|
// if isValidSignature fail, the error is catched in returnedError
|
|
119
|
-
(address recoveredAddress, ECDSA.RecoverError returnedError) = ECDSA
|
|
120
|
-
dataHash,
|
|
121
|
-
signature
|
|
122
|
-
);
|
|
121
|
+
(address recoveredAddress, ECDSA.RecoverError returnedError) = ECDSA
|
|
122
|
+
.tryRecover(dataHash, signature);
|
|
123
123
|
|
|
124
124
|
// if recovering throws an error, return the fail value
|
|
125
|
-
if (returnedError != ECDSA.RecoverError.NoError)
|
|
125
|
+
if (returnedError != ECDSA.RecoverError.NoError)
|
|
126
|
+
return _ERC1271_FAILVALUE;
|
|
126
127
|
|
|
127
128
|
// if the address recovered has SIGN permission return the ERC1271 magic value, otherwise the fail value
|
|
128
129
|
return (
|
|
129
|
-
ERC725Y(_target).getPermissionsFor(recoveredAddress).hasPermission(
|
|
130
|
+
ERC725Y(_target).getPermissionsFor(recoveredAddress).hasPermission(
|
|
131
|
+
_PERMISSION_SIGN
|
|
132
|
+
)
|
|
130
133
|
? _ERC1271_MAGICVALUE
|
|
131
134
|
: _ERC1271_FAILVALUE
|
|
132
135
|
);
|
|
@@ -135,19 +138,19 @@ abstract contract LSP6KeyManagerCore is
|
|
|
135
138
|
/**
|
|
136
139
|
* @inheritdoc ILSP6KeyManager
|
|
137
140
|
*/
|
|
138
|
-
function execute(
|
|
141
|
+
function execute(
|
|
142
|
+
bytes calldata payload
|
|
143
|
+
) public payable virtual returns (bytes memory) {
|
|
139
144
|
return _execute(msg.value, payload);
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
/**
|
|
143
148
|
* @inheritdoc ILSP6KeyManager
|
|
144
149
|
*/
|
|
145
|
-
function executeBatch(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
returns (bytes[] memory)
|
|
150
|
-
{
|
|
150
|
+
function executeBatch(
|
|
151
|
+
uint256[] calldata values,
|
|
152
|
+
bytes[] calldata payloads
|
|
153
|
+
) public payable virtual returns (bytes[] memory) {
|
|
151
154
|
if (values.length != payloads.length) {
|
|
152
155
|
revert BatchExecuteParamsLengthMismatch();
|
|
153
156
|
}
|
|
@@ -155,7 +158,7 @@ abstract contract LSP6KeyManagerCore is
|
|
|
155
158
|
bytes[] memory results = new bytes[](payloads.length);
|
|
156
159
|
uint256 totalValues;
|
|
157
160
|
|
|
158
|
-
for (uint256 ii; ii < payloads.length; ) {
|
|
161
|
+
for (uint256 ii = 0; ii < payloads.length; ) {
|
|
159
162
|
if ((totalValues += values[ii]) > msg.value) {
|
|
160
163
|
revert LSP6BatchInsufficientValueSent(totalValues, msg.value);
|
|
161
164
|
}
|
|
@@ -183,7 +186,14 @@ abstract contract LSP6KeyManagerCore is
|
|
|
183
186
|
uint256 validityTimestamps,
|
|
184
187
|
bytes calldata payload
|
|
185
188
|
) public payable virtual returns (bytes memory) {
|
|
186
|
-
return
|
|
189
|
+
return
|
|
190
|
+
_executeRelayCall(
|
|
191
|
+
signature,
|
|
192
|
+
nonce,
|
|
193
|
+
validityTimestamps,
|
|
194
|
+
msg.value,
|
|
195
|
+
payload
|
|
196
|
+
);
|
|
187
197
|
}
|
|
188
198
|
|
|
189
199
|
/**
|
|
@@ -208,7 +218,7 @@ abstract contract LSP6KeyManagerCore is
|
|
|
208
218
|
bytes[] memory results = new bytes[](payloads.length);
|
|
209
219
|
uint256 totalValues;
|
|
210
220
|
|
|
211
|
-
for (uint256 ii; ii < payloads.length; ) {
|
|
221
|
+
for (uint256 ii = 0; ii < payloads.length; ) {
|
|
212
222
|
if ((totalValues += values[ii]) > msg.value) {
|
|
213
223
|
revert LSP6BatchInsufficientValueSent(totalValues, msg.value);
|
|
214
224
|
}
|
|
@@ -242,7 +252,10 @@ abstract contract LSP6KeyManagerCore is
|
|
|
242
252
|
bytes calldata data
|
|
243
253
|
) external returns (bytes4) {
|
|
244
254
|
bool isSetData = false;
|
|
245
|
-
if (
|
|
255
|
+
if (
|
|
256
|
+
bytes4(data) == IERC725Y.setData.selector ||
|
|
257
|
+
bytes4(data) == IERC725Y.setDataBatch.selector
|
|
258
|
+
) {
|
|
246
259
|
isSetData = true;
|
|
247
260
|
}
|
|
248
261
|
|
|
@@ -286,7 +299,7 @@ abstract contract LSP6KeyManagerCore is
|
|
|
286
299
|
* @inheritdoc ILSP20
|
|
287
300
|
*/
|
|
288
301
|
function lsp20VerifyCallResult(
|
|
289
|
-
bytes32
|
|
302
|
+
bytes32 /*callHash*/,
|
|
290
303
|
bytes memory /*result*/
|
|
291
304
|
) external returns (bytes4) {
|
|
292
305
|
// If it's the target calling, set back the reentrancy guard
|
|
@@ -297,17 +310,19 @@ abstract contract LSP6KeyManagerCore is
|
|
|
297
310
|
return _LSP20_VERIFY_CALL_RESULT_MAGIC_VALUE;
|
|
298
311
|
}
|
|
299
312
|
|
|
300
|
-
function _execute(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
{
|
|
313
|
+
function _execute(
|
|
314
|
+
uint256 msgValue,
|
|
315
|
+
bytes calldata payload
|
|
316
|
+
) internal virtual returns (bytes memory) {
|
|
305
317
|
if (payload.length < 4) {
|
|
306
318
|
revert InvalidPayload(payload);
|
|
307
319
|
}
|
|
308
320
|
|
|
309
321
|
bool isSetData = false;
|
|
310
|
-
if (
|
|
322
|
+
if (
|
|
323
|
+
bytes4(payload) == IERC725Y.setData.selector ||
|
|
324
|
+
bytes4(payload) == IERC725Y.setDataBatch.selector
|
|
325
|
+
) {
|
|
311
326
|
isSetData = true;
|
|
312
327
|
}
|
|
313
328
|
|
|
@@ -345,12 +360,15 @@ abstract contract LSP6KeyManagerCore is
|
|
|
345
360
|
payload
|
|
346
361
|
);
|
|
347
362
|
|
|
348
|
-
address signer = address(this)
|
|
349
|
-
|
|
350
|
-
|
|
363
|
+
address signer = address(this)
|
|
364
|
+
.toDataWithIntendedValidatorHash(encodedMessage)
|
|
365
|
+
.recover(signature);
|
|
351
366
|
|
|
352
367
|
bool isSetData = false;
|
|
353
|
-
if (
|
|
368
|
+
if (
|
|
369
|
+
bytes4(payload) == IERC725Y.setData.selector ||
|
|
370
|
+
bytes4(payload) == IERC725Y.setDataBatch.selector
|
|
371
|
+
) {
|
|
354
372
|
isSetData = true;
|
|
355
373
|
}
|
|
356
374
|
|
|
@@ -393,14 +411,14 @@ abstract contract LSP6KeyManagerCore is
|
|
|
393
411
|
* @param payload the abi-encoded function call to execute on the target.
|
|
394
412
|
* @return bytes the result from calling the target with `payload`
|
|
395
413
|
*/
|
|
396
|
-
function _executePayload(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
);
|
|
414
|
+
function _executePayload(
|
|
415
|
+
uint256 msgValue,
|
|
416
|
+
bytes calldata payload
|
|
417
|
+
) internal virtual returns (bytes memory) {
|
|
418
|
+
(bool success, bytes memory returnData) = _target.call{
|
|
419
|
+
value: msgValue,
|
|
420
|
+
gas: gasleft()
|
|
421
|
+
}(payload);
|
|
404
422
|
bytes memory result = Address.verifyCallResult(
|
|
405
423
|
success,
|
|
406
424
|
returnData,
|
|
@@ -418,7 +436,10 @@ abstract contract LSP6KeyManagerCore is
|
|
|
418
436
|
* @param from caller address
|
|
419
437
|
* @param idx (channel id + nonce within the channel)
|
|
420
438
|
*/
|
|
421
|
-
function _isValidNonce(
|
|
439
|
+
function _isValidNonce(
|
|
440
|
+
address from,
|
|
441
|
+
uint256 idx
|
|
442
|
+
) internal view virtual returns (bool) {
|
|
422
443
|
uint256 mask = ~uint128(0);
|
|
423
444
|
// Alternatively:
|
|
424
445
|
// uint256 mask = (1<<128)-1;
|
|
@@ -442,25 +463,43 @@ abstract contract LSP6KeyManagerCore is
|
|
|
442
463
|
bytes4 erc725Function = bytes4(payload);
|
|
443
464
|
|
|
444
465
|
// ERC725Y.setData(bytes32,bytes)
|
|
445
|
-
if (erc725Function ==
|
|
466
|
+
if (erc725Function == IERC725Y.setData.selector) {
|
|
446
467
|
if (msgValue != 0) revert CannotSendValueToSetData();
|
|
447
|
-
(bytes32 inputKey, bytes memory inputValue) = abi.decode(
|
|
468
|
+
(bytes32 inputKey, bytes memory inputValue) = abi.decode(
|
|
469
|
+
payload[4:],
|
|
470
|
+
(bytes32, bytes)
|
|
471
|
+
);
|
|
448
472
|
|
|
449
|
-
LSP6SetDataModule._verifyCanSetData(
|
|
473
|
+
LSP6SetDataModule._verifyCanSetData(
|
|
474
|
+
_target,
|
|
475
|
+
from,
|
|
476
|
+
permissions,
|
|
477
|
+
inputKey,
|
|
478
|
+
inputValue
|
|
479
|
+
);
|
|
450
480
|
|
|
451
481
|
// ERC725Y.setDataBatch(bytes32[],bytes[])
|
|
452
|
-
} else if (erc725Function ==
|
|
482
|
+
} else if (erc725Function == IERC725Y.setDataBatch.selector) {
|
|
453
483
|
if (msgValue != 0) revert CannotSendValueToSetData();
|
|
454
|
-
(bytes32[] memory inputKeys, bytes[] memory inputValues) = abi
|
|
455
|
-
payload[4:],
|
|
456
|
-
(bytes32[], bytes[])
|
|
457
|
-
);
|
|
484
|
+
(bytes32[] memory inputKeys, bytes[] memory inputValues) = abi
|
|
485
|
+
.decode(payload[4:], (bytes32[], bytes[]));
|
|
458
486
|
|
|
459
|
-
LSP6SetDataModule._verifyCanSetData(
|
|
487
|
+
LSP6SetDataModule._verifyCanSetData(
|
|
488
|
+
_target,
|
|
489
|
+
from,
|
|
490
|
+
permissions,
|
|
491
|
+
inputKeys,
|
|
492
|
+
inputValues
|
|
493
|
+
);
|
|
460
494
|
|
|
461
495
|
// ERC725X.execute(uint256,address,uint256,bytes)
|
|
462
|
-
} else if (erc725Function ==
|
|
463
|
-
LSP6ExecuteModule._verifyCanExecute(
|
|
496
|
+
} else if (erc725Function == IERC725X.execute.selector) {
|
|
497
|
+
LSP6ExecuteModule._verifyCanExecute(
|
|
498
|
+
_target,
|
|
499
|
+
from,
|
|
500
|
+
permissions,
|
|
501
|
+
payload
|
|
502
|
+
);
|
|
464
503
|
} else if (
|
|
465
504
|
erc725Function == ILSP14Ownable2Step.transferOwnership.selector ||
|
|
466
505
|
erc725Function == ILSP14Ownable2Step.acceptOwnership.selector
|
|
@@ -483,11 +522,10 @@ abstract contract LSP6KeyManagerCore is
|
|
|
483
522
|
* the status is `_ENTERED` in order to revert the call unless the caller has the REENTRANCY permission
|
|
484
523
|
* Used in the beginning of the `nonReentrant` modifier, before the method execution starts.
|
|
485
524
|
*/
|
|
486
|
-
function _nonReentrantBefore(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
{
|
|
525
|
+
function _nonReentrantBefore(
|
|
526
|
+
bool isSetData,
|
|
527
|
+
address from
|
|
528
|
+
) internal virtual returns (bool isReentrantCall) {
|
|
491
529
|
isReentrantCall = _reentrancyStatus;
|
|
492
530
|
if (isReentrantCall) {
|
|
493
531
|
// CHECK the caller has REENTRANCY permission
|
|
@@ -524,6 +562,10 @@ abstract contract LSP6KeyManagerCore is
|
|
|
524
562
|
bytes32 addressPermissions,
|
|
525
563
|
bytes32 permissionRequired
|
|
526
564
|
) internal pure override(LSP6ExecuteModule, LSP6SetDataModule) {
|
|
527
|
-
LSP6ExecuteModule._requirePermissions(
|
|
565
|
+
LSP6ExecuteModule._requirePermissions(
|
|
566
|
+
controller,
|
|
567
|
+
addressPermissions,
|
|
568
|
+
permissionRequired
|
|
569
|
+
);
|
|
528
570
|
}
|
|
529
571
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
pragma solidity ^0.8.5;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Initializable
|
|
7
|
+
} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
6
8
|
import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
|
|
7
9
|
import {InvalidLSP6Target} from "./LSP6Errors.sol";
|
|
8
10
|
|
|
@@ -11,7 +13,10 @@ import {InvalidLSP6Target} from "./LSP6Errors.sol";
|
|
|
11
13
|
* @author Fabian Vogelsteller <frozeman>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
|
|
12
14
|
* @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
|
|
13
15
|
*/
|
|
14
|
-
abstract contract LSP6KeyManagerInitAbstract is
|
|
16
|
+
abstract contract LSP6KeyManagerInitAbstract is
|
|
17
|
+
Initializable,
|
|
18
|
+
LSP6KeyManagerCore
|
|
19
|
+
{
|
|
15
20
|
function _initialize(address target_) internal virtual onlyInitializing {
|
|
16
21
|
if (target_ == address(0)) revert InvalidLSP6Target();
|
|
17
22
|
_target = target_;
|
|
@@ -7,7 +7,9 @@ import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
|
7
7
|
// libraries
|
|
8
8
|
import {LSP6Utils} from "../LSP6Utils.sol";
|
|
9
9
|
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ERC165Checker
|
|
12
|
+
} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
11
13
|
|
|
12
14
|
// constants
|
|
13
15
|
import {
|
|
@@ -61,10 +63,15 @@ abstract contract LSP6ExecuteModule {
|
|
|
61
63
|
bytes calldata payload
|
|
62
64
|
) internal view virtual {
|
|
63
65
|
// CHECK the offset of `data` is not pointing to the previous parameters
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
//
|
|
67
|
+
// offsets in calldata for ERC725X.execute(...) parameters (excluding function selector)
|
|
68
|
+
//
|
|
69
|
+
// - `operationType`: index 0 in calldata
|
|
70
|
+
// - `to`: index 32
|
|
71
|
+
// - `value`: index 64
|
|
72
|
+
// - `data`'s offset location: index 96
|
|
73
|
+
// - `data` starts at: index 128 (= 0x0000...0080)
|
|
74
|
+
if (bytes32(payload[100:132]) != bytes32(uint256(128))) {
|
|
68
75
|
revert InvalidPayload(payload);
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -96,23 +103,43 @@ abstract contract LSP6ExecuteModule {
|
|
|
96
103
|
|
|
97
104
|
// if it is a message call
|
|
98
105
|
if (operationType == OPERATION_0_CALL) {
|
|
99
|
-
return
|
|
106
|
+
return
|
|
107
|
+
_verifyCanCall(
|
|
108
|
+
controlledContract,
|
|
109
|
+
controller,
|
|
110
|
+
permissions,
|
|
111
|
+
payload
|
|
112
|
+
);
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
// if it is a contract creation
|
|
103
|
-
if (
|
|
116
|
+
if (
|
|
117
|
+
operationType == OPERATION_1_CREATE ||
|
|
118
|
+
operationType == OPERATION_2_CREATE2
|
|
119
|
+
) {
|
|
104
120
|
// required to check for permission TRANSFERVALUE if we are funding
|
|
105
121
|
// the contract on deployment via a payable constructor
|
|
106
122
|
bool isFundingContract = uint256(bytes32(payload[68:100])) != 0;
|
|
107
123
|
|
|
108
|
-
return
|
|
124
|
+
return
|
|
125
|
+
_verifyCanDeployContract(
|
|
126
|
+
controller,
|
|
127
|
+
permissions,
|
|
128
|
+
isFundingContract
|
|
129
|
+
);
|
|
109
130
|
}
|
|
110
131
|
|
|
111
132
|
// if it is a STATICALL
|
|
112
133
|
// we do not check for TRANSFERVALUE permission,
|
|
113
134
|
// as ERC725X will revert if a value is provided with operation type STATICCALL.
|
|
114
135
|
if (operationType == OPERATION_3_STATICCALL) {
|
|
115
|
-
return
|
|
136
|
+
return
|
|
137
|
+
_verifyCanStaticCall(
|
|
138
|
+
controlledContract,
|
|
139
|
+
controller,
|
|
140
|
+
permissions,
|
|
141
|
+
payload
|
|
142
|
+
);
|
|
116
143
|
}
|
|
117
144
|
|
|
118
145
|
// DELEGATECALL is disallowed by default on the Key Manager.
|
|
@@ -128,7 +155,9 @@ abstract contract LSP6ExecuteModule {
|
|
|
128
155
|
) internal view virtual {
|
|
129
156
|
_requirePermissions(controller, permissions, _PERMISSION_DEPLOY);
|
|
130
157
|
|
|
131
|
-
bool hasSuperTransferValue = permissions.hasPermission(
|
|
158
|
+
bool hasSuperTransferValue = permissions.hasPermission(
|
|
159
|
+
_PERMISSION_SUPER_TRANSFERVALUE
|
|
160
|
+
);
|
|
132
161
|
|
|
133
162
|
// CHECK if we are funding the contract
|
|
134
163
|
if (isFundingContract && !hasSuperTransferValue) {
|
|
@@ -142,7 +171,9 @@ abstract contract LSP6ExecuteModule {
|
|
|
142
171
|
bytes32 permissions,
|
|
143
172
|
bytes calldata payload
|
|
144
173
|
) internal view virtual {
|
|
145
|
-
bool hasSuperStaticCall = permissions.hasPermission(
|
|
174
|
+
bool hasSuperStaticCall = permissions.hasPermission(
|
|
175
|
+
_PERMISSION_SUPER_STATICCALL
|
|
176
|
+
);
|
|
146
177
|
|
|
147
178
|
// Skip if caller has SUPER permission for static calls
|
|
148
179
|
if (hasSuperStaticCall) return;
|
|
@@ -160,7 +191,9 @@ abstract contract LSP6ExecuteModule {
|
|
|
160
191
|
) internal view virtual {
|
|
161
192
|
bool isTransferringValue = uint256(bytes32(payload[68:100])) != 0;
|
|
162
193
|
|
|
163
|
-
bool hasSuperTransferValue = permissions.hasPermission(
|
|
194
|
+
bool hasSuperTransferValue = permissions.hasPermission(
|
|
195
|
+
_PERMISSION_SUPER_TRANSFERVALUE
|
|
196
|
+
);
|
|
164
197
|
|
|
165
198
|
// all the parameters are abi-encoded (padded to 32 bytes words)
|
|
166
199
|
//
|
|
@@ -177,7 +210,11 @@ abstract contract LSP6ExecuteModule {
|
|
|
177
210
|
bool hasSuperCall = permissions.hasPermission(_PERMISSION_SUPER_CALL);
|
|
178
211
|
|
|
179
212
|
if (isTransferringValue && !hasSuperTransferValue) {
|
|
180
|
-
_requirePermissions(
|
|
213
|
+
_requirePermissions(
|
|
214
|
+
controller,
|
|
215
|
+
permissions,
|
|
216
|
+
_PERMISSION_TRANSFERVALUE
|
|
217
|
+
);
|
|
181
218
|
}
|
|
182
219
|
|
|
183
220
|
// CHECK if we are doing an empty call, as the receive() or fallback() function
|
|
@@ -194,7 +231,8 @@ abstract contract LSP6ExecuteModule {
|
|
|
194
231
|
if (hasSuperCall && !isTransferringValue) return;
|
|
195
232
|
|
|
196
233
|
// Skip if caller has SUPER permission for value transfers
|
|
197
|
-
if (hasSuperTransferValue && !isCallDataPresent && isTransferringValue)
|
|
234
|
+
if (hasSuperTransferValue && !isCallDataPresent && isTransferringValue)
|
|
235
|
+
return;
|
|
198
236
|
|
|
199
237
|
// Skip if both SUPER permissions are present
|
|
200
238
|
if (hasSuperCall && hasSuperTransferValue) return;
|
|
@@ -216,17 +254,20 @@ abstract contract LSP6ExecuteModule {
|
|
|
216
254
|
) = _extractExecuteParameters(payload);
|
|
217
255
|
|
|
218
256
|
// CHECK for ALLOWED CALLS
|
|
219
|
-
bytes memory allowedCalls = ERC725Y(controlledContract)
|
|
220
|
-
controllerAddress
|
|
221
|
-
);
|
|
257
|
+
bytes memory allowedCalls = ERC725Y(controlledContract)
|
|
258
|
+
.getAllowedCallsFor(controllerAddress);
|
|
222
259
|
|
|
223
260
|
if (allowedCalls.length == 0) {
|
|
224
261
|
revert NoCallsAllowed(controllerAddress);
|
|
225
262
|
}
|
|
226
263
|
|
|
227
|
-
bytes4 requiredCallTypes = _extractCallType(
|
|
264
|
+
bytes4 requiredCallTypes = _extractCallType(
|
|
265
|
+
operationType,
|
|
266
|
+
value,
|
|
267
|
+
isEmptyCall
|
|
268
|
+
);
|
|
228
269
|
|
|
229
|
-
for (uint256 ii; ii < allowedCalls.length; ii += 34) {
|
|
270
|
+
for (uint256 ii = 0; ii < allowedCalls.length; ii += 34) {
|
|
230
271
|
/// @dev structure of an AllowedCall
|
|
231
272
|
//
|
|
232
273
|
/// AllowedCall = 0x00200000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
@@ -248,7 +289,10 @@ abstract contract LSP6ExecuteModule {
|
|
|
248
289
|
// 0xxxxxxxxxffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
249
290
|
// (excluding the callTypes) not allowed
|
|
250
291
|
// as equivalent to whitelisting any call (= SUPER permission)
|
|
251
|
-
if (
|
|
292
|
+
if (
|
|
293
|
+
bytes28(bytes32(allowedCall) << 32) ==
|
|
294
|
+
bytes28(type(uint224).max)
|
|
295
|
+
) {
|
|
252
296
|
revert InvalidWhitelistedCall(controllerAddress);
|
|
253
297
|
}
|
|
254
298
|
|
|
@@ -290,17 +334,9 @@ abstract contract LSP6ExecuteModule {
|
|
|
290
334
|
}
|
|
291
335
|
}
|
|
292
336
|
|
|
293
|
-
function _extractExecuteParameters(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
returns (
|
|
297
|
-
uint256,
|
|
298
|
-
address,
|
|
299
|
-
uint256,
|
|
300
|
-
bytes4,
|
|
301
|
-
bool
|
|
302
|
-
)
|
|
303
|
-
{
|
|
337
|
+
function _extractExecuteParameters(
|
|
338
|
+
bytes calldata executeCalldata
|
|
339
|
+
) internal pure returns (uint256, address, uint256, bytes4, bool) {
|
|
304
340
|
uint256 operationType = uint256(bytes32(executeCalldata[4:36]));
|
|
305
341
|
|
|
306
342
|
// CHECK that it is a valid address left-padded with `00` on the 12 upper bytes
|
|
@@ -316,10 +352,19 @@ abstract contract LSP6ExecuteModule {
|
|
|
316
352
|
? bytes4(executeCalldata[164:168])
|
|
317
353
|
: bytes4(0);
|
|
318
354
|
|
|
319
|
-
return (
|
|
355
|
+
return (
|
|
356
|
+
operationType,
|
|
357
|
+
to,
|
|
358
|
+
value,
|
|
359
|
+
selector,
|
|
360
|
+
executeCalldata.length == 164
|
|
361
|
+
);
|
|
320
362
|
}
|
|
321
363
|
|
|
322
|
-
function _isAllowedAddress(
|
|
364
|
+
function _isAllowedAddress(
|
|
365
|
+
bytes memory allowedCall,
|
|
366
|
+
address to
|
|
367
|
+
) internal pure returns (bool) {
|
|
323
368
|
// <offset> = 4 bytes x 8 bits = 32 bits
|
|
324
369
|
//
|
|
325
370
|
// <offset>v----------------address---------------v
|
|
@@ -327,10 +372,15 @@ abstract contract LSP6ExecuteModule {
|
|
|
327
372
|
address allowedAddress = address(bytes20(bytes32(allowedCall) << 32));
|
|
328
373
|
|
|
329
374
|
// ANY address = 0xffffffffffffffffffffffffffffffffffffffff
|
|
330
|
-
return
|
|
375
|
+
return
|
|
376
|
+
allowedAddress == address(bytes20(type(uint160).max)) ||
|
|
377
|
+
to == allowedAddress;
|
|
331
378
|
}
|
|
332
379
|
|
|
333
|
-
function _isAllowedStandard(
|
|
380
|
+
function _isAllowedStandard(
|
|
381
|
+
bytes memory allowedCall,
|
|
382
|
+
address to
|
|
383
|
+
) internal view returns (bool) {
|
|
334
384
|
// <offset> = 24 bytes x 8 bits = 192 bits
|
|
335
385
|
//
|
|
336
386
|
// standard
|
|
@@ -344,11 +394,10 @@ abstract contract LSP6ExecuteModule {
|
|
|
344
394
|
to.supportsERC165InterfaceUnchecked(allowedStandard);
|
|
345
395
|
}
|
|
346
396
|
|
|
347
|
-
function _isAllowedFunction(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
{
|
|
397
|
+
function _isAllowedFunction(
|
|
398
|
+
bytes memory allowedCall,
|
|
399
|
+
bytes4 requiredFunction
|
|
400
|
+
) internal pure returns (bool) {
|
|
352
401
|
// <offset> = 28 bytes x 8 bits = 224 bits
|
|
353
402
|
//
|
|
354
403
|
// function
|
|
@@ -364,11 +413,10 @@ abstract contract LSP6ExecuteModule {
|
|
|
364
413
|
(isFunctionCall && (requiredFunction == allowedFunction));
|
|
365
414
|
}
|
|
366
415
|
|
|
367
|
-
function _isAllowedCallType(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
{
|
|
416
|
+
function _isAllowedCallType(
|
|
417
|
+
bytes memory allowedCall,
|
|
418
|
+
bytes4 requiredCallTypes
|
|
419
|
+
) internal pure returns (bool) {
|
|
372
420
|
// extract callType
|
|
373
421
|
//
|
|
374
422
|
// <offset> = 0
|
|
@@ -392,7 +440,9 @@ abstract contract LSP6ExecuteModule {
|
|
|
392
440
|
bytes32 permissionRequired
|
|
393
441
|
) internal pure virtual {
|
|
394
442
|
if (!LSP6Utils.hasPermission(addressPermissions, permissionRequired)) {
|
|
395
|
-
string memory permissionErrorString = LSP6Utils.getPermissionName(
|
|
443
|
+
string memory permissionErrorString = LSP6Utils.getPermissionName(
|
|
444
|
+
permissionRequired
|
|
445
|
+
);
|
|
396
446
|
revert NotAuthorised(controller, permissionErrorString);
|
|
397
447
|
}
|
|
398
448
|
}
|
|
@@ -11,11 +11,16 @@ import {_PERMISSION_CHANGEOWNER} from "../LSP6Constants.sol";
|
|
|
11
11
|
import {NotAuthorised} from "../LSP6Errors.sol";
|
|
12
12
|
|
|
13
13
|
abstract contract LSP6OwnershipModule {
|
|
14
|
-
function _verifyOwnershipPermissions(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
if (
|
|
14
|
+
function _verifyOwnershipPermissions(
|
|
15
|
+
address controllerAddress,
|
|
16
|
+
bytes32 controllerPermissions
|
|
17
|
+
) internal pure {
|
|
18
|
+
if (
|
|
19
|
+
!LSP6Utils.hasPermission(
|
|
20
|
+
controllerPermissions,
|
|
21
|
+
_PERMISSION_CHANGEOWNER
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
19
24
|
string memory permissionErrorString = LSP6Utils.getPermissionName(
|
|
20
25
|
_PERMISSION_CHANGEOWNER
|
|
21
26
|
);
|