@lukso/lsp-smart-contracts 0.5.0 → 0.6.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 +38 -9
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +398 -0
- package/artifacts/LSP0ERC725AccountInit.json +444 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +21 -5
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +21 -5
- package/artifacts/LSP4Compatibility.json +195 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +179 -0
- package/artifacts/LSP4DigitalAssetMetadataInit.json +241 -0
- package/artifacts/LSP6KeyManager.json +110 -35
- package/artifacts/LSP6KeyManagerInit.json +123 -30
- package/artifacts/LSP7CappedSupply.json +146 -11
- package/artifacts/LSP7CappedSupplyInit.json +167 -57
- package/artifacts/LSP7CompatibleERC20.json +714 -0
- package/artifacts/LSP7CompatibleERC20Init.json +760 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +742 -0
- package/artifacts/LSP7CompatibleERC20MintableInit.json +783 -0
- package/artifacts/LSP7DigitalAsset.json +138 -13
- package/artifacts/LSP7DigitalAssetInit.json +167 -34
- package/artifacts/LSP7Mintable.json +139 -14
- package/artifacts/LSP7MintableInit.json +168 -35
- package/artifacts/LSP8CappedSupply.json +147 -11
- package/artifacts/LSP8CappedSupplyInit.json +176 -37
- package/artifacts/LSP8CompatibleERC721.json +842 -0
- package/artifacts/LSP8CompatibleERC721Init.json +883 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +881 -0
- package/artifacts/LSP8CompatibleERC721MintableInit.json +922 -0
- package/artifacts/LSP8IdentifiableDigitalAsset.json +139 -13
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +176 -19
- package/artifacts/LSP8Mintable.json +151 -14
- package/artifacts/LSP8MintableInit.json +188 -20
- package/artifacts/LSP9Vault.json +374 -0
- package/artifacts/LSP9VaultInit.json +420 -0
- package/artifacts/UniversalFactory.json +127 -0
- package/artifacts/UniversalProfile.json +89 -32
- package/artifacts/UniversalProfileInit.json +133 -32
- package/artifacts/UniversalReceiverAddressStore.json +209 -0
- package/constants.js +535 -0
- package/contracts/Custom/ClaimOwnership.sol +34 -0
- package/contracts/Custom/ERC165Checker.sol +130 -0
- package/contracts/Custom/IClaimOwnership.sol +10 -0
- package/contracts/Factories/Create2Factory.sol +3 -13
- package/contracts/Factories/UniversalFactory.sol +164 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +7 -9
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +108 -55
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +11 -4
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +6 -21
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +10 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +3 -9
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +67 -184
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +58 -6
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +51 -89
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +46 -6
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +62 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +201 -0
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +5 -14
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +22 -8
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +26 -20
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +231 -0
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +28 -25
- package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -25
- package/contracts/LSP6KeyManager/LSP6Errors.sol +66 -0
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +7 -6
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +465 -378
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +13 -5
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +9 -15
- package/contracts/LSP6KeyManager/LSP6Utils.sol +107 -0
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +27 -9
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +73 -95
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +19 -9
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +27 -23
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +7 -9
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +8 -7
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +10 -15
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +67 -0
- package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +36 -50
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +29 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +67 -0
- package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
- package/contracts/LSP7DigitalAsset/{extensions/LSP7CompatibilityForERC20Init.sol → presets/LSP7CompatibleERC20MintableInit.sol} +6 -5
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
- package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
- package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
- package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +11 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +23 -10
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +103 -136
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +17 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +26 -21
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +4 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +13 -20
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +101 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +38 -95
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Init.sol → LSP8CompatibleERC721Init.sol} +4 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +93 -0
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +23 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +11 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +37 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +14 -5
- package/contracts/LSP9Vault/LSP9Vault.sol +20 -38
- package/contracts/LSP9Vault/LSP9VaultCore.sol +123 -92
- package/contracts/LSP9Vault/LSP9VaultInit.sol +12 -4
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +20 -46
- package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +62 -0
- package/contracts/UniversalProfile.sol +11 -7
- package/contracts/UniversalProfileInit.sol +12 -4
- package/contracts/UniversalProfileInitAbstract.sol +12 -20
- package/contracts/Utils/UtilsLib.sol +21 -13
- package/package.json +23 -9
- package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
- package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
- package/artifacts/LSP7CompatibilityForERC20.json +0 -571
- package/artifacts/LSP8CompatibilityForERC721.json +0 -716
- package/constants.ts +0 -356
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +0 -56
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +0 -55
- package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +0 -92
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +0 -90
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
- package/contracts/Utils/ERC725Utils.sol +0 -169
- package/contracts/Utils/LSP2Utils.sol +0 -127
- package/contracts/Utils/LSP6Utils.sol +0 -63
|
@@ -1,202 +1,155 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.6;
|
|
3
3
|
|
|
4
|
-
// modules
|
|
5
|
-
import "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
-
import "@erc725/smart-contracts/contracts/ERC725.sol";
|
|
7
|
-
import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
|
|
8
|
-
|
|
9
4
|
// interfaces
|
|
10
|
-
import "
|
|
5
|
+
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
6
|
+
import {IERC725X} from "@erc725/smart-contracts/contracts/interfaces/IERC725X.sol";
|
|
7
|
+
import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
|
|
8
|
+
|
|
9
|
+
// modules
|
|
10
|
+
import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
|
|
11
|
+
import {IClaimOwnership} from "../Custom/IClaimOwnership.sol";
|
|
12
|
+
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
13
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
11
14
|
|
|
12
15
|
// libraries
|
|
13
|
-
import "
|
|
16
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
17
|
+
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
18
|
+
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
19
|
+
import {ERC165Checker} from "../Custom/ERC165Checker.sol";
|
|
20
|
+
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
21
|
+
import {LSP6Utils} from "./LSP6Utils.sol";
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
import "
|
|
17
|
-
import "
|
|
18
|
-
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
19
|
-
import "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
23
|
+
// errors
|
|
24
|
+
import "./LSP6Errors.sol";
|
|
25
|
+
import {InvalidABIEncodedArray} from "../LSP2ERC725YJSONSchema/LSP2Errors.sol";
|
|
20
26
|
|
|
21
27
|
// constants
|
|
28
|
+
import {
|
|
29
|
+
OPERATION_CALL,
|
|
30
|
+
OPERATION_CREATE,
|
|
31
|
+
OPERATION_CREATE2,
|
|
32
|
+
OPERATION_STATICCALL,
|
|
33
|
+
OPERATION_DELEGATECALL
|
|
34
|
+
} from "@erc725/smart-contracts/contracts/constants.sol";
|
|
35
|
+
import {
|
|
36
|
+
_INTERFACEID_ERC1271,
|
|
37
|
+
_ERC1271_MAGICVALUE,
|
|
38
|
+
_ERC1271_FAILVALUE
|
|
39
|
+
} from "../LSP0ERC725Account/LSP0Constants.sol";
|
|
22
40
|
import "./LSP6Constants.sol";
|
|
23
|
-
import "../LSP0ERC725Account/LSP0Constants.sol";
|
|
24
|
-
import "@erc725/smart-contracts/contracts/constants.sol";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @dev address `from` is not authorised to `permission`
|
|
28
|
-
* @param permission permission required
|
|
29
|
-
* @param from address not-authorised
|
|
30
|
-
*/
|
|
31
|
-
error NotAuthorised(address from, string permission);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @dev address `from` is not authorised to interact with `disallowedAddress` via account
|
|
35
|
-
* @param from address making the request
|
|
36
|
-
* @param disallowedAddress address that `from` is not authorised to call
|
|
37
|
-
*/
|
|
38
|
-
error NotAllowedAddress(address from, address disallowedAddress);
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @dev address `from` is not authorised to run `disallowedFunction` via account
|
|
42
|
-
* @param from address making the request
|
|
43
|
-
* @param disallowedFunction bytes4 function selector that `from` is not authorised to run
|
|
44
|
-
*/
|
|
45
|
-
error NotAllowedFunction(address from, bytes4 disallowedFunction);
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @dev address `from` is not authorised to set the key `disallowedKey` on the account
|
|
49
|
-
* @param from address making the request
|
|
50
|
-
* @param disallowedKey a bytes32 key that `from` is not authorised to set on the ERC725Y storage
|
|
51
|
-
*/
|
|
52
|
-
error NotAllowedERC725YKey(address from, bytes32 disallowedKey);
|
|
53
41
|
|
|
54
42
|
/**
|
|
55
43
|
* @title Core implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
|
|
56
|
-
* @author Fabian Vogelsteller
|
|
44
|
+
* @author Fabian Vogelsteller <frozeman>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
|
|
57
45
|
* @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
|
|
58
46
|
*/
|
|
59
|
-
abstract contract LSP6KeyManagerCore is
|
|
60
|
-
using
|
|
61
|
-
using
|
|
62
|
-
using LSP6Utils for ERC725;
|
|
47
|
+
abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
48
|
+
using LSP2Utils for *;
|
|
49
|
+
using LSP6Utils for *;
|
|
63
50
|
using Address for address;
|
|
64
51
|
using ECDSA for bytes32;
|
|
65
52
|
using ERC165Checker for address;
|
|
66
53
|
|
|
67
|
-
|
|
54
|
+
address public override target;
|
|
68
55
|
mapping(address => mapping(uint256 => uint256)) internal _nonceStore;
|
|
69
56
|
|
|
70
57
|
/**
|
|
71
58
|
* @dev See {IERC165-supportsInterface}.
|
|
72
59
|
*/
|
|
73
|
-
function supportsInterface(bytes4 interfaceId)
|
|
74
|
-
public
|
|
75
|
-
view
|
|
76
|
-
virtual
|
|
77
|
-
override(ERC165Storage)
|
|
78
|
-
returns (bool)
|
|
79
|
-
{
|
|
60
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
80
61
|
return
|
|
81
|
-
interfaceId ==
|
|
62
|
+
interfaceId == _INTERFACEID_LSP6 ||
|
|
63
|
+
interfaceId == _INTERFACEID_ERC1271 ||
|
|
82
64
|
super.supportsInterface(interfaceId);
|
|
83
65
|
}
|
|
84
66
|
|
|
85
67
|
/**
|
|
86
68
|
* @inheritdoc ILSP6KeyManager
|
|
87
69
|
*/
|
|
88
|
-
function getNonce(address
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
override
|
|
92
|
-
returns (uint256)
|
|
93
|
-
{
|
|
94
|
-
uint128 nonceId = uint128(_nonceStore[_from][_channel]);
|
|
95
|
-
return (uint256(_channel) << 128) | nonceId;
|
|
70
|
+
function getNonce(address from, uint256 channelId) public view override returns (uint256) {
|
|
71
|
+
uint128 nonceId = uint128(_nonceStore[from][channelId]);
|
|
72
|
+
return (uint256(channelId) << 128) | nonceId;
|
|
96
73
|
}
|
|
97
74
|
|
|
98
75
|
/**
|
|
99
76
|
* @inheritdoc IERC1271
|
|
100
77
|
*/
|
|
101
|
-
function isValidSignature(bytes32
|
|
78
|
+
function isValidSignature(bytes32 dataHash, bytes memory signature)
|
|
102
79
|
public
|
|
103
80
|
view
|
|
104
81
|
override
|
|
105
82
|
returns (bytes4 magicValue)
|
|
106
83
|
{
|
|
107
|
-
address recoveredAddress =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
?
|
|
112
|
-
:
|
|
84
|
+
address recoveredAddress = dataHash.recover(signature);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
ERC725Y(target).getPermissionsFor(recoveredAddress).hasPermission(_PERMISSION_SIGN)
|
|
88
|
+
? _ERC1271_MAGICVALUE
|
|
89
|
+
: _ERC1271_FAILVALUE
|
|
90
|
+
);
|
|
113
91
|
}
|
|
114
92
|
|
|
115
93
|
/**
|
|
116
94
|
* @inheritdoc ILSP6KeyManager
|
|
117
95
|
*/
|
|
118
|
-
function execute(bytes calldata
|
|
119
|
-
|
|
120
|
-
payable
|
|
121
|
-
override
|
|
122
|
-
returns (bytes memory)
|
|
123
|
-
{
|
|
124
|
-
_verifyPermissions(msg.sender, _data);
|
|
96
|
+
function execute(bytes calldata payload) public payable override returns (bytes memory) {
|
|
97
|
+
_verifyPermissions(msg.sender, payload);
|
|
125
98
|
|
|
126
99
|
// solhint-disable avoid-low-level-calls
|
|
127
|
-
(bool success, bytes memory
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// solhint-disable no-inline-assembly
|
|
137
|
-
assembly {
|
|
138
|
-
result_ := add(result_, 0x04)
|
|
139
|
-
}
|
|
140
|
-
revert(abi.decode(result_, (string)));
|
|
141
|
-
}
|
|
100
|
+
(bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
|
|
101
|
+
payload
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
bytes memory result = Address.verifyCallResult(
|
|
105
|
+
success,
|
|
106
|
+
returnData,
|
|
107
|
+
"LSP6: Unknow Error occured when calling the linked target contract"
|
|
108
|
+
);
|
|
142
109
|
|
|
143
|
-
emit Executed(msg.value,
|
|
144
|
-
return
|
|
110
|
+
emit Executed(msg.value, bytes4(payload));
|
|
111
|
+
return result.length != 0 ? abi.decode(result, (bytes)) : result;
|
|
145
112
|
}
|
|
146
113
|
|
|
147
114
|
/**
|
|
148
115
|
* @inheritdoc ILSP6KeyManager
|
|
149
116
|
*/
|
|
150
117
|
function executeRelayCall(
|
|
151
|
-
|
|
152
|
-
uint256
|
|
153
|
-
bytes calldata
|
|
154
|
-
|
|
155
|
-
) external payable override returns (bytes memory) {
|
|
156
|
-
require(
|
|
157
|
-
_signedFor == address(this),
|
|
158
|
-
"executeRelayCall: Message not signed for this keyManager"
|
|
159
|
-
);
|
|
160
|
-
|
|
118
|
+
bytes memory signature,
|
|
119
|
+
uint256 nonce,
|
|
120
|
+
bytes calldata payload
|
|
121
|
+
) public payable override returns (bytes memory) {
|
|
161
122
|
bytes memory blob = abi.encodePacked(
|
|
123
|
+
block.chainid,
|
|
162
124
|
address(this), // needs to be signed for this keyManager
|
|
163
|
-
|
|
164
|
-
|
|
125
|
+
nonce,
|
|
126
|
+
payload
|
|
165
127
|
);
|
|
166
128
|
|
|
167
|
-
address signer = keccak256(blob).toEthSignedMessageHash().recover(
|
|
168
|
-
_signature
|
|
169
|
-
);
|
|
129
|
+
address signer = keccak256(blob).toEthSignedMessageHash().recover(signature);
|
|
170
130
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
);
|
|
131
|
+
if (!_isValidNonce(signer, nonce)) {
|
|
132
|
+
revert InvalidRelayNonce(signer, nonce, signature);
|
|
133
|
+
}
|
|
175
134
|
|
|
176
135
|
// increase nonce after successful verification
|
|
177
|
-
_nonceStore[signer][
|
|
136
|
+
_nonceStore[signer][nonce >> 128]++;
|
|
178
137
|
|
|
179
|
-
_verifyPermissions(signer,
|
|
138
|
+
_verifyPermissions(signer, payload);
|
|
180
139
|
|
|
181
140
|
// solhint-disable avoid-low-level-calls
|
|
182
|
-
(bool success, bytes memory
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}(_data);
|
|
186
|
-
|
|
187
|
-
if (!success) {
|
|
188
|
-
// solhint-disable reason-string
|
|
189
|
-
if (result_.length < 68) revert();
|
|
190
|
-
|
|
191
|
-
// solhint-disable no-inline-assembly
|
|
192
|
-
assembly {
|
|
193
|
-
result_ := add(result_, 0x04)
|
|
194
|
-
}
|
|
195
|
-
revert(abi.decode(result_, (string)));
|
|
196
|
-
}
|
|
141
|
+
(bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
|
|
142
|
+
payload
|
|
143
|
+
);
|
|
197
144
|
|
|
198
|
-
|
|
199
|
-
|
|
145
|
+
bytes memory result = Address.verifyCallResult(
|
|
146
|
+
success,
|
|
147
|
+
returnData,
|
|
148
|
+
"LSP6: Unknow Error occured when calling the linked target contract"
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
emit Executed(msg.value, bytes4(payload));
|
|
152
|
+
return result.length != 0 ? abi.decode(result, (bytes)) : result;
|
|
200
153
|
}
|
|
201
154
|
|
|
202
155
|
/**
|
|
@@ -204,359 +157,493 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
|
|
|
204
157
|
* @dev "idx" is a 256bits (unsigned) integer, where:
|
|
205
158
|
* - the 128 leftmost bits = channelId
|
|
206
159
|
* and - the 128 rightmost bits = nonce within the channel
|
|
207
|
-
* @param
|
|
208
|
-
* @param
|
|
160
|
+
* @param from caller address
|
|
161
|
+
* @param idx (channel id + nonce within the channel)
|
|
209
162
|
*/
|
|
210
|
-
function _isValidNonce(address
|
|
211
|
-
internal
|
|
212
|
-
view
|
|
213
|
-
returns (bool)
|
|
214
|
-
{
|
|
163
|
+
function _isValidNonce(address from, uint256 idx) internal view returns (bool) {
|
|
215
164
|
// idx % (1 << 128) = nonce
|
|
216
165
|
// (idx >> 128) = channel
|
|
217
166
|
// equivalent to: return (nonce == _nonceStore[_from][channel]
|
|
218
|
-
return (
|
|
167
|
+
return (idx % (1 << 128)) == (_nonceStore[from][idx >> 128]);
|
|
219
168
|
}
|
|
220
169
|
|
|
221
170
|
/**
|
|
222
|
-
* @dev verify the permissions of the _from address that want to interact with the `
|
|
223
|
-
* @param
|
|
224
|
-
* @param
|
|
171
|
+
* @dev verify the permissions of the _from address that want to interact with the `target`
|
|
172
|
+
* @param from the address making the request
|
|
173
|
+
* @param payload the payload that will be run on `target`
|
|
225
174
|
*/
|
|
226
|
-
function _verifyPermissions(address
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
175
|
+
function _verifyPermissions(address from, bytes calldata payload) internal view {
|
|
176
|
+
bytes4 erc725Function = bytes4(payload[:4]);
|
|
177
|
+
|
|
178
|
+
// get the permissions of the caller
|
|
179
|
+
bytes32 permissions = ERC725Y(target).getPermissionsFor(from);
|
|
231
180
|
|
|
232
|
-
if (
|
|
233
|
-
_verifyCanSetData(_from, _data);
|
|
234
|
-
} else if (erc725Function == account.execute.selector) {
|
|
235
|
-
_verifyCanExecute(_from, _data);
|
|
181
|
+
if (permissions == bytes32(0)) revert NoPermissionsSet(from);
|
|
236
182
|
|
|
237
|
-
|
|
238
|
-
|
|
183
|
+
if (erc725Function == setDataSingleSelector) {
|
|
184
|
+
(bytes32 inputKey, bytes memory inputValue) = abi.decode(payload[4:], (bytes32, bytes));
|
|
239
185
|
|
|
240
|
-
if (
|
|
241
|
-
|
|
186
|
+
if (
|
|
187
|
+
// CHECK for permission keys
|
|
188
|
+
bytes6(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
|
|
189
|
+
bytes16(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX
|
|
190
|
+
) {
|
|
191
|
+
_verifyCanSetPermissions(inputKey, inputValue, from, permissions);
|
|
192
|
+
} else {
|
|
193
|
+
bytes32[] memory wrappedInputKey = new bytes32[](1);
|
|
194
|
+
wrappedInputKey[0] = inputKey;
|
|
195
|
+
|
|
196
|
+
_verifyCanSetData(from, permissions, wrappedInputKey);
|
|
197
|
+
}
|
|
198
|
+
} else if (erc725Function == setDataMultipleSelector) {
|
|
199
|
+
(bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(
|
|
200
|
+
payload[4:],
|
|
201
|
+
(bytes32[], bytes[])
|
|
202
|
+
);
|
|
242
203
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
204
|
+
bool isSettingERC725YKeys = false;
|
|
205
|
+
|
|
206
|
+
// loop through each ERC725Y data keys
|
|
207
|
+
for (uint256 ii = 0; ii < inputKeys.length; ii++) {
|
|
208
|
+
bytes32 key = inputKeys[ii];
|
|
209
|
+
bytes memory value = inputValues[ii];
|
|
210
|
+
|
|
211
|
+
if (
|
|
212
|
+
// CHECK for permission keys
|
|
213
|
+
bytes6(key) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
|
|
214
|
+
bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX
|
|
215
|
+
) {
|
|
216
|
+
_verifyCanSetPermissions(key, value, from, permissions);
|
|
217
|
+
|
|
218
|
+
// "nullify" permission keys
|
|
219
|
+
// to not check them against allowed ERC725Y keys
|
|
220
|
+
inputKeys[ii] = bytes32(0);
|
|
221
|
+
} else {
|
|
222
|
+
// if the key is any other bytes32 key
|
|
223
|
+
isSettingERC725YKeys = true;
|
|
246
224
|
}
|
|
247
225
|
}
|
|
248
|
-
} else if (erc725Function == account.transferOwnership.selector) {
|
|
249
|
-
bytes32 permissions = account.getPermissionsFor(_from);
|
|
250
226
|
|
|
251
|
-
if (
|
|
252
|
-
|
|
227
|
+
if (isSettingERC725YKeys) {
|
|
228
|
+
_verifyCanSetData(from, permissions, inputKeys);
|
|
229
|
+
}
|
|
230
|
+
} else if (erc725Function == IERC725X.execute.selector) {
|
|
231
|
+
_verifyCanExecute(from, permissions, payload);
|
|
232
|
+
} else if (
|
|
233
|
+
erc725Function == OwnableUnset.transferOwnership.selector ||
|
|
234
|
+
erc725Function == IClaimOwnership.claimOwnership.selector
|
|
235
|
+
) {
|
|
236
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEOWNER);
|
|
253
237
|
} else {
|
|
254
|
-
revert(
|
|
238
|
+
revert InvalidERC725Function(erc725Function);
|
|
255
239
|
}
|
|
256
240
|
}
|
|
257
241
|
|
|
258
242
|
/**
|
|
259
243
|
* @dev verify if `_from` has the required permissions to set some keys
|
|
260
244
|
* on the linked ERC725Account
|
|
261
|
-
* @param
|
|
262
|
-
* @param
|
|
245
|
+
* @param from the address who want to set the keys
|
|
246
|
+
* @param permissions the permissions
|
|
247
|
+
* @param inputKeys the data keys being set
|
|
263
248
|
* containing a list of keys-value pairs
|
|
264
249
|
*/
|
|
265
|
-
function _verifyCanSetData(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
250
|
+
function _verifyCanSetData(
|
|
251
|
+
address from,
|
|
252
|
+
bytes32 permissions,
|
|
253
|
+
bytes32[] memory inputKeys
|
|
254
|
+
) internal view {
|
|
255
|
+
// Skip if caller has SUPER permissions
|
|
256
|
+
if (permissions.hasPermission(_PERMISSION_SUPER_SETDATA)) return;
|
|
270
257
|
|
|
271
|
-
(
|
|
272
|
-
_data[4:],
|
|
273
|
-
(bytes32[], bytes[])
|
|
274
|
-
);
|
|
258
|
+
_requirePermissions(from, permissions, _PERMISSION_SETDATA);
|
|
275
259
|
|
|
276
|
-
|
|
260
|
+
_verifyAllowedERC725YKeys(from, inputKeys);
|
|
261
|
+
}
|
|
277
262
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
263
|
+
function _verifyCanSetPermissions(
|
|
264
|
+
bytes32 key,
|
|
265
|
+
bytes memory value,
|
|
266
|
+
address from,
|
|
267
|
+
bytes32 permissions
|
|
268
|
+
) internal view {
|
|
269
|
+
// prettier-ignore
|
|
270
|
+
if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
|
|
271
|
+
|
|
272
|
+
// key = AddressPermissions:Permissions:<address>
|
|
273
|
+
_verifyCanSetBytes32Permissions(key, from, permissions);
|
|
274
|
+
|
|
275
|
+
} else if (key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
|
|
281
276
|
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
277
|
+
// key = AddressPermissions[]
|
|
278
|
+
_verifyCanSetPermissionsArray(key, value, from, permissions);
|
|
279
|
+
|
|
280
|
+
} else if (bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
|
|
286
281
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
282
|
+
// key = AddressPermissions[index]
|
|
283
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
284
|
+
|
|
285
|
+
} else if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX) {
|
|
286
|
+
|
|
287
|
+
bool isClearingArray = value.length == 0;
|
|
288
|
+
|
|
289
|
+
// AddressPermissions:AllowedAddresses:<address>
|
|
290
|
+
if (!isClearingArray && !LSP2Utils.isEncodedArrayOfAddresses(value)) {
|
|
291
|
+
revert InvalidABIEncodedArray(value, "address");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
bytes memory storedAllowedAddresses = ERC725Y(target).getData(key);
|
|
295
|
+
|
|
296
|
+
if (storedAllowedAddresses.length == 0) {
|
|
297
|
+
|
|
298
|
+
_requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
|
|
290
299
|
|
|
291
|
-
// if the key is any other bytes32 key
|
|
292
300
|
} else {
|
|
293
|
-
|
|
301
|
+
|
|
302
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
303
|
+
|
|
294
304
|
}
|
|
295
|
-
}
|
|
296
305
|
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
306
|
+
} else if (
|
|
307
|
+
bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX ||
|
|
308
|
+
bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX
|
|
309
|
+
) {
|
|
310
|
+
bool isClearingArray = value.length == 0;
|
|
311
|
+
|
|
312
|
+
// AddressPermissions:AllowedFunctions:<address>
|
|
313
|
+
// AddressPermissions:AllowedStandards:<address>
|
|
314
|
+
if (!isClearingArray && !LSP2Utils.isBytes4EncodedArray(value)) {
|
|
315
|
+
revert InvalidABIEncodedArray(value, "bytes4");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
bytes memory storedAllowedBytes4 = ERC725Y(target).getData(key);
|
|
319
|
+
|
|
320
|
+
if (storedAllowedBytes4.length == 0) {
|
|
321
|
+
|
|
322
|
+
_requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
|
|
323
|
+
|
|
324
|
+
} else {
|
|
325
|
+
|
|
326
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
} else if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX) {
|
|
331
|
+
|
|
332
|
+
bool isClearingArray = value.length == 0;
|
|
333
|
+
|
|
334
|
+
// AddressPermissions:AllowedERC725YKeys:<address>
|
|
335
|
+
if (!isClearingArray && !LSP2Utils.isEncodedArray(value)) {
|
|
336
|
+
revert InvalidABIEncodedArray(value, "bytes32");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
bytes memory storedAllowedERC725YKeys = ERC725Y(target).getData(key);
|
|
340
|
+
|
|
341
|
+
if (storedAllowedERC725YKeys.length == 0) {
|
|
342
|
+
|
|
343
|
+
_requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
|
|
344
|
+
|
|
345
|
+
} else {
|
|
346
|
+
|
|
347
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
348
|
+
|
|
349
|
+
}
|
|
300
350
|
|
|
301
|
-
_verifyAllowedERC725YKeys(_from, inputKeys);
|
|
302
351
|
}
|
|
303
352
|
}
|
|
304
353
|
|
|
305
|
-
function
|
|
306
|
-
bytes32
|
|
307
|
-
address
|
|
308
|
-
bytes32
|
|
354
|
+
function _verifyCanSetBytes32Permissions(
|
|
355
|
+
bytes32 key,
|
|
356
|
+
address from,
|
|
357
|
+
bytes32 callerPermissions
|
|
309
358
|
) internal view {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (bytes32(ERC725Y(account).getDataSingle(_key)) == bytes32(0)) {
|
|
313
|
-
// if nothing is stored under this key,
|
|
359
|
+
if (bytes32(ERC725Y(target).getData(key)) == bytes32(0)) {
|
|
360
|
+
// if there is nothing stored under this data key,
|
|
314
361
|
// we are trying to ADD permissions for a NEW address
|
|
315
|
-
|
|
316
|
-
revert NotAuthorised(_from, "ADDPERMISSIONS");
|
|
362
|
+
_requirePermissions(from, callerPermissions, _PERMISSION_ADDPERMISSIONS);
|
|
317
363
|
} else {
|
|
318
|
-
// if there are already
|
|
364
|
+
// if there are already some permissions stored under this data key,
|
|
319
365
|
// we are trying to CHANGE the permissions of an address
|
|
320
366
|
// (that has already some EXISTING permissions set)
|
|
321
|
-
|
|
322
|
-
revert NotAuthorised(_from, "CHANGEPERMISSIONS");
|
|
367
|
+
_requirePermissions(from, callerPermissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
323
368
|
}
|
|
324
369
|
}
|
|
325
370
|
|
|
326
|
-
function
|
|
327
|
-
|
|
328
|
-
|
|
371
|
+
function _verifyCanSetPermissionsArray(
|
|
372
|
+
bytes32 key,
|
|
373
|
+
bytes memory value,
|
|
374
|
+
address from,
|
|
375
|
+
bytes32 permissions
|
|
329
376
|
) internal view {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
_ADDRESS_ALLOWEDERC725YKEYS,
|
|
333
|
-
bytes20(_from)
|
|
334
|
-
)
|
|
335
|
-
);
|
|
377
|
+
uint256 arrayLength = uint256(bytes32(ERC725Y(target).getData(key)));
|
|
378
|
+
uint256 newLength = uint256(bytes32(value));
|
|
336
379
|
|
|
337
|
-
|
|
338
|
-
|
|
380
|
+
if (newLength > arrayLength) {
|
|
381
|
+
_requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
|
|
382
|
+
} else {
|
|
383
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
339
386
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
(bytes32[])
|
|
343
|
-
);
|
|
387
|
+
function _verifyAllowedERC725YKeys(address from, bytes32[] memory inputKeys) internal view {
|
|
388
|
+
bytes memory allowedERC725YKeysEncoded = ERC725Y(target).getAllowedERC725YKeysFor(from);
|
|
344
389
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
390
|
+
// whitelist any ERC725Y key
|
|
391
|
+
if (
|
|
392
|
+
// if nothing in the list
|
|
393
|
+
allowedERC725YKeysEncoded.length == 0 ||
|
|
394
|
+
// if not correctly abi-encoded array
|
|
395
|
+
!LSP2Utils.isEncodedArray(allowedERC725YKeysEncoded)
|
|
396
|
+
) return;
|
|
348
397
|
|
|
349
|
-
|
|
398
|
+
bytes32[] memory allowedERC725YKeys = abi.decode(allowedERC725YKeysEncoded, (bytes32[]));
|
|
350
399
|
|
|
351
|
-
|
|
352
|
-
bytes32
|
|
400
|
+
uint256 zeroBytesCount;
|
|
401
|
+
bytes32 mask;
|
|
353
402
|
|
|
354
403
|
// loop through each allowed ERC725Y key retrieved from storage
|
|
355
404
|
for (uint256 ii = 0; ii < allowedERC725YKeys.length; ii++) {
|
|
356
|
-
//
|
|
357
|
-
|
|
358
|
-
(allowedKeySlice, sliceLength) = _extractKeySlice(
|
|
359
|
-
allowedERC725YKeys[ii]
|
|
360
|
-
);
|
|
405
|
+
// required to know which part of the input key to compare against the allowed key
|
|
406
|
+
zeroBytesCount = _countTrailingZeroBytes(allowedERC725YKeys[ii]);
|
|
361
407
|
|
|
362
408
|
// loop through each keys given as input
|
|
363
|
-
for (uint256 jj = 0; jj <
|
|
364
|
-
// skip permissions keys that have been "nulled"
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
409
|
+
for (uint256 jj = 0; jj < inputKeys.length; jj++) {
|
|
410
|
+
// skip permissions keys that have been previously checked and "nulled"
|
|
411
|
+
if (inputKeys[jj] == bytes32(0)) continue;
|
|
412
|
+
|
|
413
|
+
// use a bitmask to discard the last `n` bytes of the input key (where `n` = `zeroBytesCount`)
|
|
414
|
+
// and compare only the relevant parts of each ERC725Y keys
|
|
415
|
+
//
|
|
416
|
+
// for an allowed key = 0xcafecafecafecafecafecafecafecafe00000000000000000000000000000000
|
|
417
|
+
//
|
|
418
|
+
// |------compare this part-------|------discard this part--------|
|
|
419
|
+
// v v v
|
|
420
|
+
// mask = 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000
|
|
421
|
+
// & input key = 0xcafecafecafecafecafecafecafecafe00000000000000000000000011223344
|
|
422
|
+
//
|
|
423
|
+
mask = bytes32(type(uint256).max) << (8 * zeroBytesCount);
|
|
424
|
+
|
|
425
|
+
if (allowedERC725YKeys[ii] == (inputKeys[jj] & mask)) {
|
|
426
|
+
// if the input key matches the allowed key
|
|
427
|
+
// make it null to mark it as allowed
|
|
428
|
+
inputKeys[jj] = bytes32(0);
|
|
429
|
+
}
|
|
382
430
|
}
|
|
383
|
-
|
|
384
|
-
// if after checking all the keys given as input we did not find any not allowed key
|
|
385
|
-
// stop checking the other allowed ERC725Y keys
|
|
386
|
-
if (isAllowedKey == true) break;
|
|
387
431
|
}
|
|
388
432
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
433
|
+
for (uint256 ii = 0; ii < inputKeys.length; ii++) {
|
|
434
|
+
if (inputKeys[ii] != bytes32(0)) revert NotAllowedERC725YKey(from, inputKeys[ii]);
|
|
435
|
+
}
|
|
392
436
|
}
|
|
393
437
|
|
|
394
438
|
/**
|
|
395
|
-
* @dev verify if `
|
|
439
|
+
* @dev verify if `from` has the required permissions to make an external call
|
|
396
440
|
* via the linked ERC725Account
|
|
397
|
-
* @param
|
|
398
|
-
* @param
|
|
441
|
+
* @param from the address who want to run the execute function on the ERC725Account
|
|
442
|
+
* @param permissions the permissions of the caller
|
|
443
|
+
* @param payload the ABI encoded payload `target.execute(...)`
|
|
399
444
|
*/
|
|
400
|
-
function _verifyCanExecute(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
uint256 value = uint256(bytes32(_data[68:100]));
|
|
445
|
+
function _verifyCanExecute(
|
|
446
|
+
address from,
|
|
447
|
+
bytes32 permissions,
|
|
448
|
+
bytes calldata payload
|
|
449
|
+
) internal view {
|
|
450
|
+
uint256 operationType = uint256(bytes32(payload[4:36]));
|
|
451
|
+
require(operationType < 5, "LSP6KeyManager: invalid operation type");
|
|
408
452
|
|
|
453
|
+
// TODO: if re-enable delegatecall, add check to ensure owner() + initialized() are not overriden after delegatecall
|
|
409
454
|
require(
|
|
410
|
-
operationType !=
|
|
411
|
-
"
|
|
455
|
+
operationType != OPERATION_DELEGATECALL,
|
|
456
|
+
"LSP6KeyManager: operation DELEGATECALL is currently disallowed"
|
|
412
457
|
);
|
|
413
458
|
|
|
414
|
-
(
|
|
415
|
-
bytes32 permissionRequired,
|
|
416
|
-
string memory operationName
|
|
417
|
-
) = _extractPermissionFromOperation(operationType);
|
|
459
|
+
uint256 value = uint256(bytes32(payload[68:100]));
|
|
418
460
|
|
|
419
|
-
|
|
420
|
-
|
|
461
|
+
// prettier-ignore
|
|
462
|
+
bool isContractCreation = operationType == OPERATION_CREATE || operationType == OPERATION_CREATE2;
|
|
463
|
+
bool isCallDataPresent = payload.length > 164;
|
|
421
464
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
465
|
+
// SUPER operation only applies to contract call, not contract creation
|
|
466
|
+
bool hasSuperOperation = isContractCreation
|
|
467
|
+
? false
|
|
468
|
+
: permissions.hasPermission(_extractSuperPermissionFromOperation(operationType));
|
|
469
|
+
|
|
470
|
+
if (isCallDataPresent) {
|
|
471
|
+
// prettier-ignore
|
|
472
|
+
hasSuperOperation || _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
|
|
476
|
+
|
|
477
|
+
if (value > 0) {
|
|
478
|
+
// prettier-ignore
|
|
479
|
+
hasSuperTransferValue || _requirePermissions(from, permissions, _PERMISSION_TRANSFERVALUE);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// Skip on contract creation (CREATE or CREATE2)
|
|
483
|
+
if (isContractCreation) return;
|
|
484
|
+
|
|
485
|
+
// Skip if caller has SUPER permissions for operations
|
|
486
|
+
if (hasSuperOperation && isCallDataPresent && value == 0) return;
|
|
487
|
+
|
|
488
|
+
// Skip if caller has SUPER permission for value transfers
|
|
489
|
+
if (hasSuperTransferValue && !isCallDataPresent && value > 0) return;
|
|
490
|
+
|
|
491
|
+
// Skip if both SUPER permissions are present
|
|
492
|
+
if (hasSuperOperation && hasSuperTransferValue) return;
|
|
493
|
+
|
|
494
|
+
// CHECK for ALLOWED ADDRESSES
|
|
495
|
+
address to = address(bytes20(payload[48:68]));
|
|
496
|
+
_verifyAllowedAddress(from, to);
|
|
497
|
+
|
|
498
|
+
if (to.code.length > 0) {
|
|
499
|
+
// CHECK for ALLOWED STANDARDS
|
|
500
|
+
_verifyAllowedStandard(from, to);
|
|
501
|
+
|
|
502
|
+
// CHECK for ALLOWED FUNCTIONS
|
|
503
|
+
// extract bytes4 function selector from payload passed to ERC725X.execute(...)
|
|
504
|
+
if (payload.length >= 168) _verifyAllowedFunction(from, bytes4(payload[164:168]));
|
|
427
505
|
}
|
|
428
506
|
}
|
|
429
507
|
|
|
430
508
|
/**
|
|
431
|
-
* @dev
|
|
432
|
-
*
|
|
433
|
-
* @param
|
|
509
|
+
* @dev extract the required permission + a descriptive string, based on the `_operationType`
|
|
510
|
+
* being run via ERC725Account.execute(...)
|
|
511
|
+
* @param operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
|
|
512
|
+
* @return permissionsRequired (bytes32) the permission associated with the `_operationType`
|
|
434
513
|
*/
|
|
435
|
-
function
|
|
436
|
-
|
|
514
|
+
function _extractPermissionFromOperation(uint256 operationType)
|
|
515
|
+
internal
|
|
516
|
+
pure
|
|
517
|
+
returns (bytes32 permissionsRequired)
|
|
518
|
+
{
|
|
519
|
+
if (operationType == OPERATION_CALL) return _PERMISSION_CALL;
|
|
520
|
+
else if (operationType == OPERATION_CREATE) return _PERMISSION_DEPLOY;
|
|
521
|
+
else if (operationType == OPERATION_CREATE2) return _PERMISSION_DEPLOY;
|
|
522
|
+
else if (operationType == OPERATION_STATICCALL) return _PERMISSION_STATICCALL;
|
|
523
|
+
else if (operationType == OPERATION_DELEGATECALL) return _PERMISSION_DELEGATECALL;
|
|
524
|
+
}
|
|
437
525
|
|
|
438
|
-
|
|
439
|
-
|
|
526
|
+
function _extractSuperPermissionFromOperation(uint256 operationType)
|
|
527
|
+
internal
|
|
528
|
+
pure
|
|
529
|
+
returns (bytes32 superPermission)
|
|
530
|
+
{
|
|
531
|
+
if (operationType == OPERATION_CALL) return _PERMISSION_SUPER_CALL;
|
|
532
|
+
else if (operationType == OPERATION_STATICCALL) return _PERMISSION_SUPER_STATICCALL;
|
|
533
|
+
else if (operationType == OPERATION_DELEGATECALL) return _PERMISSION_SUPER_DELEGATECALL;
|
|
534
|
+
}
|
|
440
535
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
536
|
+
/**
|
|
537
|
+
* @dev verify if `from` is authorised to interact with address `to` via the linked ERC725Account
|
|
538
|
+
* @param from the caller address
|
|
539
|
+
* @param to the address to interact with
|
|
540
|
+
*/
|
|
541
|
+
function _verifyAllowedAddress(address from, address to) internal view {
|
|
542
|
+
bytes memory allowedAddresses = ERC725Y(target).getAllowedAddressesFor(from);
|
|
543
|
+
|
|
544
|
+
// whitelist any address
|
|
545
|
+
if (
|
|
546
|
+
// if nothing in the list
|
|
547
|
+
allowedAddresses.length == 0 ||
|
|
548
|
+
// if not correctly abi-encoded array of address[]
|
|
549
|
+
!LSP2Utils.isEncodedArrayOfAddresses(allowedAddresses)
|
|
550
|
+
) return;
|
|
551
|
+
|
|
552
|
+
address[] memory allowedAddressesList = abi.decode(allowedAddresses, (address[]));
|
|
445
553
|
|
|
446
554
|
for (uint256 ii = 0; ii < allowedAddressesList.length; ii++) {
|
|
447
|
-
if (
|
|
555
|
+
if (to == allowedAddressesList[ii]) return;
|
|
448
556
|
}
|
|
449
|
-
revert NotAllowedAddress(
|
|
557
|
+
revert NotAllowedAddress(from, to);
|
|
450
558
|
}
|
|
451
559
|
|
|
452
560
|
/**
|
|
453
|
-
* @dev if `
|
|
454
|
-
* verify that `
|
|
455
|
-
* @param
|
|
456
|
-
* @param
|
|
561
|
+
* @dev if `from` is restricted to interact with contracts that implement a specific interface,
|
|
562
|
+
* verify that `to` implements one of these interface.
|
|
563
|
+
* @param from the caller address
|
|
564
|
+
* @param to the address of the contract to interact with
|
|
457
565
|
*/
|
|
458
|
-
function _verifyAllowedStandard(address
|
|
459
|
-
bytes memory allowedStandards = ERC725Y(
|
|
460
|
-
LSP2Utils.generateBytes20MappingWithGroupingKey(
|
|
461
|
-
_ADDRESS_ALLOWEDSTANDARDS,
|
|
462
|
-
bytes20(_from)
|
|
463
|
-
)
|
|
464
|
-
);
|
|
566
|
+
function _verifyAllowedStandard(address from, address to) internal view {
|
|
567
|
+
bytes memory allowedStandards = ERC725Y(target).getAllowedStandardsFor(from);
|
|
465
568
|
|
|
466
|
-
// whitelist any standard interface (ERC165)
|
|
467
|
-
if (
|
|
569
|
+
// whitelist any standard interface (ERC165)
|
|
570
|
+
if (
|
|
571
|
+
// if nothing in the list
|
|
572
|
+
allowedStandards.length == 0 ||
|
|
573
|
+
// if not correctly abi-encoded array of bytes4[]
|
|
574
|
+
!LSP2Utils.isBytes4EncodedArray(allowedStandards)
|
|
575
|
+
) return;
|
|
468
576
|
|
|
469
|
-
bytes4[] memory allowedStandardsList = abi.decode(
|
|
470
|
-
allowedStandards,
|
|
471
|
-
(bytes4[])
|
|
472
|
-
);
|
|
577
|
+
bytes4[] memory allowedStandardsList = abi.decode(allowedStandards, (bytes4[]));
|
|
473
578
|
|
|
474
579
|
for (uint256 ii = 0; ii < allowedStandardsList.length; ii++) {
|
|
475
|
-
if (
|
|
580
|
+
if (to.supportsERC165Interface(allowedStandardsList[ii])) return;
|
|
476
581
|
}
|
|
477
|
-
revert(
|
|
582
|
+
revert NotAllowedStandard(from, to);
|
|
478
583
|
}
|
|
479
584
|
|
|
480
585
|
/**
|
|
481
|
-
* @dev verify if `
|
|
482
|
-
* to run a specific function `
|
|
483
|
-
* @param
|
|
484
|
-
* @param
|
|
586
|
+
* @dev verify if `from` is authorised to use the linked ERC725Account
|
|
587
|
+
* to run a specific function `functionSelector` at a target contract
|
|
588
|
+
* @param from the caller address
|
|
589
|
+
* @param functionSelector the bytes4 function selector of the function to run
|
|
485
590
|
* at the target contract
|
|
486
591
|
*/
|
|
487
|
-
function _verifyAllowedFunction(address
|
|
488
|
-
|
|
489
|
-
view
|
|
490
|
-
{
|
|
491
|
-
bytes memory allowedFunctions = account.getAllowedFunctionsFor(_from);
|
|
592
|
+
function _verifyAllowedFunction(address from, bytes4 functionSelector) internal view {
|
|
593
|
+
bytes memory allowedFunctions = ERC725Y(target).getAllowedFunctionsFor(from);
|
|
492
594
|
|
|
493
|
-
// whitelist any function
|
|
494
|
-
if (
|
|
595
|
+
// whitelist any function
|
|
596
|
+
if (
|
|
597
|
+
// if nothing in the list
|
|
598
|
+
allowedFunctions.length == 0 ||
|
|
599
|
+
// if not correctly abi-encoded array of bytes4[]
|
|
600
|
+
!LSP2Utils.isBytes4EncodedArray(allowedFunctions)
|
|
601
|
+
) return;
|
|
495
602
|
|
|
496
|
-
bytes4[] memory allowedFunctionsList = abi.decode(
|
|
497
|
-
allowedFunctions,
|
|
498
|
-
(bytes4[])
|
|
499
|
-
);
|
|
603
|
+
bytes4[] memory allowedFunctionsList = abi.decode(allowedFunctions, (bytes4[]));
|
|
500
604
|
|
|
501
605
|
for (uint256 ii = 0; ii < allowedFunctionsList.length; ii++) {
|
|
502
|
-
if (
|
|
606
|
+
if (functionSelector == allowedFunctionsList[ii]) return;
|
|
503
607
|
}
|
|
504
|
-
revert NotAllowedFunction(
|
|
608
|
+
revert NotAllowedFunction(from, functionSelector);
|
|
505
609
|
}
|
|
506
610
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
bytes32 _addressPermission
|
|
516
|
-
) internal pure returns (bool) {
|
|
517
|
-
return
|
|
518
|
-
(_requiredPermission & _addressPermission) == _requiredPermission
|
|
519
|
-
? true
|
|
520
|
-
: false;
|
|
611
|
+
function _countTrailingZeroBytes(bytes32 key) internal pure returns (uint256) {
|
|
612
|
+
uint256 index = 31;
|
|
613
|
+
|
|
614
|
+
// CHECK each bytes of the key, starting from the end (right to left)
|
|
615
|
+
// skip each empty bytes `0x00` to find the first non-empty byte
|
|
616
|
+
while (key[index] == 0x00 && index != 0) index--;
|
|
617
|
+
|
|
618
|
+
return 32 - (index + 1);
|
|
521
619
|
}
|
|
522
620
|
|
|
523
|
-
function
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
{
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
if (_key[index] != 0x00) {
|
|
532
|
-
// stop as soon as we find a non-empty byte
|
|
533
|
-
sliceLength_ = index + 1;
|
|
534
|
-
keySlice_ = BytesLib.slice(bytes.concat(_key), 0, sliceLength_);
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
621
|
+
function _requirePermissions(
|
|
622
|
+
address from,
|
|
623
|
+
bytes32 addressPermissions,
|
|
624
|
+
bytes32 permissionRequired
|
|
625
|
+
) internal pure returns (bool) {
|
|
626
|
+
if (!addressPermissions.hasPermission(permissionRequired)) {
|
|
627
|
+
string memory permissionErrorString = _getPermissionErrorString(permissionRequired);
|
|
628
|
+
revert NotAuthorised(from, permissionErrorString);
|
|
537
629
|
}
|
|
538
630
|
}
|
|
539
631
|
|
|
540
|
-
|
|
541
|
-
* @dev extract the required permission + a descriptive string, based on the `_operationType`
|
|
542
|
-
* being run via ERC725Account.execute(...)
|
|
543
|
-
* @param _operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
|
|
544
|
-
* @return bytes32 the permission associated with the `_operationType`
|
|
545
|
-
* @return string the opcode associated with `_operationType`
|
|
546
|
-
*/
|
|
547
|
-
function _extractPermissionFromOperation(uint256 _operationType)
|
|
632
|
+
function _getPermissionErrorString(bytes32 permission)
|
|
548
633
|
internal
|
|
549
634
|
pure
|
|
550
|
-
returns (
|
|
635
|
+
returns (string memory errorMessage)
|
|
551
636
|
{
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
);
|
|
556
|
-
|
|
557
|
-
if (
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
if (
|
|
637
|
+
if (permission == _PERMISSION_CHANGEOWNER) return "TRANSFEROWNERSHIP";
|
|
638
|
+
if (permission == _PERMISSION_CHANGEPERMISSIONS) return "CHANGEPERMISSIONS";
|
|
639
|
+
if (permission == _PERMISSION_ADDPERMISSIONS) return "ADDPERMISSIONS";
|
|
640
|
+
if (permission == _PERMISSION_SETDATA) return "SETDATA";
|
|
641
|
+
if (permission == _PERMISSION_CALL) return "CALL";
|
|
642
|
+
if (permission == _PERMISSION_STATICCALL) return "STATICCALL";
|
|
643
|
+
if (permission == _PERMISSION_DELEGATECALL) return "DELEGATECALL";
|
|
644
|
+
// TODO: add support to display CREATE or CREATE2 in the revert error
|
|
645
|
+
if (permission == _PERMISSION_DEPLOY) return "DEPLOY";
|
|
646
|
+
if (permission == _PERMISSION_TRANSFERVALUE) return "TRANSFERVALUE";
|
|
647
|
+
if (permission == _PERMISSION_SIGN) return "SIGN";
|
|
561
648
|
}
|
|
562
649
|
}
|