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