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