@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.
Files changed (108) hide show
  1. package/artifacts/Create2Factory.json +2 -2
  2. package/artifacts/LSP0ERC725Account.json +8 -8
  3. package/artifacts/LSP0ERC725AccountInit.json +13 -8
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +18 -2
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +18 -2
  6. package/artifacts/LSP4DigitalAssetMetadata.json +10 -0
  7. package/artifacts/LSP4DigitalAssetMetadataInit.json +10 -0
  8. package/artifacts/LSP6KeyManager.json +82 -13
  9. package/artifacts/LSP6KeyManagerInit.json +87 -13
  10. package/artifacts/LSP7CappedSupply.json +10 -0
  11. package/artifacts/LSP7CappedSupplyInit.json +10 -28
  12. package/artifacts/LSP7CompatibleERC20.json +714 -0
  13. package/artifacts/LSP7CompatibleERC20Init.json +760 -0
  14. package/artifacts/LSP7CompatibleERC20Mintable.json +742 -0
  15. package/artifacts/LSP7CompatibleERC20MintableInit.json +783 -0
  16. package/artifacts/LSP7DigitalAsset.json +12 -2
  17. package/artifacts/LSP7DigitalAssetInit.json +17 -2
  18. package/artifacts/LSP7Mintable.json +12 -2
  19. package/artifacts/LSP7MintableInit.json +17 -2
  20. package/artifacts/LSP8CappedSupply.json +10 -0
  21. package/artifacts/LSP8CappedSupplyInit.json +10 -23
  22. package/artifacts/LSP8CompatibleERC721.json +842 -0
  23. package/artifacts/LSP8CompatibleERC721Init.json +883 -0
  24. package/artifacts/LSP8CompatibleERC721Mintable.json +881 -0
  25. package/artifacts/LSP8CompatibleERC721MintableInit.json +922 -0
  26. package/artifacts/LSP8IdentifiableDigitalAsset.json +12 -2
  27. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +17 -2
  28. package/artifacts/LSP8Mintable.json +12 -2
  29. package/artifacts/LSP8MintableInit.json +17 -2
  30. package/artifacts/LSP9Vault.json +9 -9
  31. package/artifacts/LSP9VaultInit.json +14 -9
  32. package/artifacts/UniversalFactory.json +2 -2
  33. package/artifacts/UniversalProfile.json +8 -8
  34. package/artifacts/UniversalProfileInit.json +13 -8
  35. package/artifacts/UniversalReceiverAddressStore.json +2 -2
  36. package/constants.js +49 -14
  37. package/contracts/Custom/ClaimOwnership.sol +10 -7
  38. package/contracts/Custom/IClaimOwnership.sol +1 -1
  39. package/contracts/Factories/Create2Factory.sol +3 -13
  40. package/contracts/Factories/UniversalFactory.sol +16 -7
  41. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +3 -3
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +28 -19
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +10 -3
  44. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +2 -2
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +12 -3
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +18 -16
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +8 -2
  48. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +18 -4
  49. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
  50. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +69 -73
  51. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
  52. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  53. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +14 -3
  54. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +16 -4
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
  56. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +27 -1
  57. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +15 -15
  58. package/contracts/LSP6KeyManager/LSP6Errors.sol +34 -5
  59. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +5 -3
  60. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +224 -234
  61. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +10 -3
  62. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +4 -2
  63. package/contracts/LSP6KeyManager/LSP6Utils.sol +22 -26
  64. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +4 -0
  65. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +3 -1
  66. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +11 -0
  67. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +3 -1
  68. package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +6 -6
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +5 -2
  70. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20.sol → LSP7CompatibleERC20.sol} +6 -7
  71. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +21 -16
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +29 -0
  73. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20InitAbstract.sol → LSP7CompatibleERC20InitAbstract.sol} +11 -10
  74. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
  75. package/contracts/LSP7DigitalAsset/{extensions/LSP7CompatibilityForERC20Init.sol → presets/LSP7CompatibleERC20MintableInit.sol} +5 -4
  76. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
  77. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +8 -1
  78. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +1 -1
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +1 -1
  80. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +10 -1
  81. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +3 -1
  82. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +1 -1
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +4 -2
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721.sol → LSP8CompatibleERC721.sol} +12 -11
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +16 -16
  87. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Init.sol → LSP8CompatibleERC721Init.sol} +3 -3
  88. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721InitAbstract.sol → LSP8CompatibleERC721InitAbstract.sol} +13 -9
  89. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +23 -0
  91. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +7 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +3 -1
  94. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  95. package/contracts/LSP9Vault/LSP9Vault.sol +9 -5
  96. package/contracts/LSP9Vault/LSP9VaultCore.sol +37 -26
  97. package/contracts/LSP9Vault/LSP9VaultInit.sol +10 -3
  98. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +8 -4
  99. package/contracts/Legacy/UniversalReceiverAddressStore.sol +3 -1
  100. package/contracts/UniversalProfile.sol +3 -4
  101. package/contracts/UniversalProfileInit.sol +10 -3
  102. package/contracts/UniversalProfileInitAbstract.sol +3 -5
  103. package/contracts/Utils/UtilsLib.sol +6 -34
  104. package/package.json +2 -2
  105. package/artifacts/LSP7CompatibilityForERC20.json +0 -686
  106. package/artifacts/LSP7CompatibilityForERC20Init.json +0 -727
  107. package/artifacts/LSP8CompatibilityForERC721.json +0 -832
  108. 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 {_INTERFACEID_ERC1271, _ERC1271_MAGICVALUE, _ERC1271_FAILVALUE} from "../LSP0ERC725Account/LSP0Constants.sol";
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 _from, uint256 _channel) public view override returns (uint256) {
68
- uint128 nonceId = uint128(_nonceStore[_from][_channel]);
69
- 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;
70
73
  }
71
74
 
72
75
  /**
73
76
  * @inheritdoc IERC1271
74
77
  */
75
- function isValidSignature(bytes32 _hash, bytes memory _signature)
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 = _hash.recover(_signature);
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 _calldata) external payable override returns (bytes memory) {
94
- _verifyPermissions(msg.sender, _calldata);
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 result) = target.call{value: msg.value, gas: gasleft()}(
98
- _calldata
100
+ (bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
101
+ payload
99
102
  );
100
103
 
101
- if (!success) {
102
- ErrorHandlerLib.revertWithParsedError(result);
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(_calldata));
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 _signature,
114
- uint256 _nonce,
115
- bytes calldata _calldata
116
- ) external payable override returns (bytes memory) {
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
- _nonce,
121
- _calldata
125
+ nonce,
126
+ payload
122
127
  );
123
128
 
124
- address signer = keccak256(blob).toEthSignedMessageHash().recover(_signature);
129
+ address signer = keccak256(blob).toEthSignedMessageHash().recover(signature);
125
130
 
126
- require(_isValidNonce(signer, _nonce), "executeRelayCall: Invalid nonce");
131
+ if (!_isValidNonce(signer, nonce)) {
132
+ revert InvalidRelayNonce(signer, nonce, signature);
133
+ }
127
134
 
128
135
  // increase nonce after successful verification
129
- _nonceStore[signer][_nonce >> 128]++;
136
+ _nonceStore[signer][nonce >> 128]++;
130
137
 
131
- _verifyPermissions(signer, _calldata);
138
+ _verifyPermissions(signer, payload);
132
139
 
133
140
  // solhint-disable avoid-low-level-calls
134
- (bool success, bytes memory result) = target.call{value: msg.value, gas: gasleft()}(
135
- _calldata
141
+ (bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
142
+ payload
136
143
  );
137
144
 
138
- if (!success) {
139
- ErrorHandlerLib.revertWithParsedError(result);
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(_calldata));
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 _from caller address
152
- * @param _idx (channel id + nonce within the channel)
160
+ * @param from caller address
161
+ * @param idx (channel id + nonce within the channel)
153
162
  */
154
- function _isValidNonce(address _from, uint256 _idx) internal view returns (bool) {
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 (_idx % (1 << 128)) == (_nonceStore[_from][_idx >> 128]);
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 _from the address making the request
164
- * @param _calldata the payload that will be run on `target`
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 _from, bytes calldata _calldata) internal view {
167
- bytes4 erc725Function = bytes4(_calldata[:4]);
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(_from);
179
+ bytes32 permissions = ERC725Y(target).getPermissionsFor(from);
171
180
 
172
- if (permissions == bytes32(0)) revert NoPermissionsSet(_from);
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
- bytes32[] memory inputKeys = new bytes32[](1);
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
- (bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(_calldata[4:], (bytes32[], bytes[]));
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, _from, permissions);
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(_from, permissions, inputKeys);
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("_verifyPermissions: invalid ERC725 selector");
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 _from the address who want to set the keys
247
- * @param _permissions the permissions
248
- * @param _inputKeys the data keys being set
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 _from,
253
- bytes32 _permissions,
254
- bytes32[] memory _inputKeys
251
+ address from,
252
+ bytes32 permissions,
253
+ bytes32[] memory inputKeys
255
254
  ) internal view {
256
255
  // Skip if caller has SUPER permissions
257
- if (_permissions.hasPermission(_PERMISSION_SUPER_SETDATA)) return;
256
+ if (permissions.hasPermission(_PERMISSION_SUPER_SETDATA)) return;
258
257
 
259
- _requirePermissions(_from, _permissions, _PERMISSION_SETDATA);
258
+ _requirePermissions(from, permissions, _PERMISSION_SETDATA);
260
259
 
261
- _verifyAllowedERC725YKeys(_from, _inputKeys);
260
+ _verifyAllowedERC725YKeys(from, inputKeys);
262
261
  }
263
262
 
264
263
  function _verifyCanSetPermissions(
265
- bytes32 _key,
266
- bytes memory _value,
267
- address _from,
268
- bytes32 _permissions
264
+ bytes32 key,
265
+ bytes memory value,
266
+ address from,
267
+ bytes32 permissions
269
268
  ) internal view {
270
269
  // prettier-ignore
271
- if (bytes12(_key) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
270
+ if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
272
271
 
273
272
  // key = AddressPermissions:Permissions:<address>
274
- _verifyCanSetBytes32Permissions(_key, _from, _permissions);
273
+ _verifyCanSetBytes32Permissions(key, from, permissions);
275
274
 
276
- } else if (_key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
275
+ } else if (key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
277
276
 
278
277
  // key = AddressPermissions[]
279
- _verifyCanSetPermissionsArray(_key, _value, _from, _permissions);
278
+ _verifyCanSetPermissionsArray(key, value, from, permissions);
280
279
 
281
- } else if (bytes16(_key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
280
+ } else if (bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
282
281
 
283
282
  // key = AddressPermissions[index]
284
- _requirePermissions(_from, _permissions, _PERMISSION_CHANGEPERMISSIONS);
283
+ _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
284
+
285
+ } else if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX) {
285
286
 
286
- } else if (bytes12(_key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX) {
287
+ bool isClearingArray = value.length == 0;
287
288
 
288
289
  // AddressPermissions:AllowedAddresses:<address>
289
- require(
290
- LSP2Utils.isEncodedArrayOfAddresses(_value),
291
- "LSP6KeyManager: invalid ABI encoded array of addresses"
292
- );
290
+ if (!isClearingArray && !LSP2Utils.isEncodedArrayOfAddresses(value)) {
291
+ revert InvalidABIEncodedArray(value, "address");
292
+ }
293
293
 
294
- bytes memory storedAllowedAddresses = ERC725Y(target).getData(_key);
294
+ bytes memory storedAllowedAddresses = ERC725Y(target).getData(key);
295
295
 
296
296
  if (storedAllowedAddresses.length == 0) {
297
297
 
298
- _requirePermissions(_from, _permissions, _PERMISSION_ADDPERMISSIONS);
298
+ _requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
299
299
 
300
300
  } else {
301
301
 
302
- _requirePermissions(_from, _permissions, _PERMISSION_CHANGEPERMISSIONS);
302
+ _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
303
303
 
304
304
  }
305
305
 
306
306
  } else if (
307
- bytes12(_key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX ||
308
- bytes12(_key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX
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
- require(
314
- LSP2Utils.isBytes4EncodedArray(_value),
315
- "LSP6KeyManager: invalid ABI encoded array of bytes4"
316
- );
314
+ if (!isClearingArray && !LSP2Utils.isBytes4EncodedArray(value)) {
315
+ revert InvalidABIEncodedArray(value, "bytes4");
316
+ }
317
317
 
318
- bytes memory storedAllowedBytes4 = ERC725Y(target).getData(_key);
318
+ bytes memory storedAllowedBytes4 = ERC725Y(target).getData(key);
319
319
 
320
320
  if (storedAllowedBytes4.length == 0) {
321
321
 
322
- _requirePermissions(_from, _permissions, _PERMISSION_ADDPERMISSIONS);
322
+ _requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
323
323
 
324
324
  } else {
325
325
 
326
- _requirePermissions(_from, _permissions, _PERMISSION_CHANGEPERMISSIONS);
326
+ _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
327
327
 
328
328
  }
329
329
 
330
- } else if (bytes12(_key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX) {
330
+ } else if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX) {
331
+
332
+ bool isClearingArray = value.length == 0;
331
333
 
332
334
  // AddressPermissions:AllowedERC725YKeys:<address>
333
- require(
334
- LSP2Utils.isEncodedArray(_value),
335
- "LSP6KeyManager: invalid ABI encoded array of bytes32"
336
- );
335
+ if (!isClearingArray && !LSP2Utils.isEncodedArray(value)) {
336
+ revert InvalidABIEncodedArray(value, "bytes32");
337
+ }
337
338
 
338
- bytes memory storedAllowedERC725YKeys = ERC725Y(target).getData(_key);
339
+ bytes memory storedAllowedERC725YKeys = ERC725Y(target).getData(key);
339
340
 
340
341
  if (storedAllowedERC725YKeys.length == 0) {
341
342
 
342
- _requirePermissions(_from, _permissions, _PERMISSION_ADDPERMISSIONS);
343
+ _requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
343
344
 
344
345
  } else {
345
346
 
346
- _requirePermissions(_from, _permissions, _PERMISSION_CHANGEPERMISSIONS);
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 _key,
355
- address _from,
356
- bytes32 _callerPermissions
355
+ bytes32 key,
356
+ address from,
357
+ bytes32 callerPermissions
357
358
  ) internal view {
358
- if (bytes32(ERC725Y(target).getData(_key)) == bytes32(0)) {
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(_from, _callerPermissions, _PERMISSION_ADDPERMISSIONS);
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(_from, _callerPermissions, _PERMISSION_CHANGEPERMISSIONS);
367
+ _requirePermissions(from, callerPermissions, _PERMISSION_CHANGEPERMISSIONS);
367
368
  }
368
369
  }
369
370
 
370
371
  function _verifyCanSetPermissionsArray(
371
- bytes32 _key,
372
- bytes memory _value,
373
- address _from,
374
- bytes32 _permissions
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(_key)));
377
- uint256 newLength = uint256(bytes32(_value));
377
+ uint256 arrayLength = uint256(bytes32(ERC725Y(target).getData(key)));
378
+ uint256 newLength = uint256(bytes32(value));
378
379
 
379
380
  if (newLength > arrayLength) {
380
- _requirePermissions(_from, _permissions, _PERMISSION_ADDPERMISSIONS);
381
+ _requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
381
382
  } else {
382
- _requirePermissions(_from, _permissions, _PERMISSION_CHANGEPERMISSIONS);
383
+ _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
383
384
  }
384
385
  }
385
386
 
386
- function _verifyAllowedERC725YKeys(address _from, bytes32[] memory _inputKeys) internal view {
387
- bytes memory allowedERC725YKeysEncoded = ERC725Y(target).getAllowedERC725YKeysFor(_from);
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 = _countZeroBytes(allowedERC725YKeys[ii]);
406
+ zeroBytesCount = _countTrailingZeroBytes(allowedERC725YKeys[ii]);
406
407
 
407
408
  // loop through each keys given as input
408
- for (uint256 jj = 0; jj < _inputKeys.length; jj++) {
409
- // skip permissions keys that have been previously "nulled"
410
- if (_inputKeys[jj] == bytes32(0)) continue;
411
-
412
- // solhint-disable no-inline-assembly
413
- assembly {
414
- // use a bitmask to discard the last `n` bytes of the input key
415
- // so to compare only the relevant parts of each ERC725Y keys
416
- //
417
- // `n = zeroBytesCount`
418
- //
419
- // eg:
420
- //
421
- // allowed key = 0xcafecafecafecafecafecafecafecafe00000000000000000000000000000000
422
- //
423
- // compare this part
424
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
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
- _inputKeys[jj] = bytes32(0);
428
+ inputKeys[jj] = bytes32(0);
439
429
  }
440
430
  }
441
431
  }
442
432
 
443
- for (uint256 ii = 0; ii < _inputKeys.length; ii++) {
444
- if (_inputKeys[ii] != bytes32(0)) revert NotAllowedERC725YKey(_from, _inputKeys[ii]);
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 `_from` has the required permissions to make an external call
439
+ * @dev verify if `from` has the required permissions to make an external call
450
440
  * via the linked ERC725Account
451
- * @param _from the address who want to run the execute function on the ERC725Account
452
- * @param _permissions the permissions of the caller
453
- * @param _calldata the ABI encoded payload `target.execute(...)`
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 _from,
457
- bytes32 _permissions,
458
- bytes calldata _calldata
446
+ address from,
447
+ bytes32 permissions,
448
+ bytes calldata payload
459
449
  ) internal view {
460
- uint256 operationType = uint256(bytes32(_calldata[4:36]));
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(_calldata[68:100]));
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 = _calldata.length > 164;
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
- : _permissions.hasPermission(_extractSuperPermissionFromOperation(operationType));
468
+ : permissions.hasPermission(_extractSuperPermissionFromOperation(operationType));
479
469
 
480
470
  if (isCallDataPresent) {
481
471
  // prettier-ignore
482
- hasSuperOperation || _requirePermissions(_from, _permissions, _extractPermissionFromOperation(operationType));
472
+ hasSuperOperation || _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
483
473
  }
484
474
 
485
- bool hasSuperTransferValue = _permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
475
+ bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
486
476
 
487
477
  if (value > 0) {
488
478
  // prettier-ignore
489
- hasSuperTransferValue || _requirePermissions(_from, _permissions, _PERMISSION_TRANSFERVALUE);
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(_calldata[48:68]));
506
- _verifyAllowedAddress(_from, to);
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(_from, to);
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 (_calldata.length >= 168) _verifyAllowedFunction(_from, bytes4(_calldata[164:168]));
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 _operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
522
- * @return permissionsRequired_ (bytes32) the permission associated with the `_operationType`
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 _operationType)
514
+ function _extractPermissionFromOperation(uint256 operationType)
525
515
  internal
526
516
  pure
527
- returns (bytes32 permissionsRequired_)
517
+ returns (bytes32 permissionsRequired)
528
518
  {
529
- if (_operationType == OPERATION_CALL) return _PERMISSION_CALL;
530
- else if (_operationType == OPERATION_CREATE) return _PERMISSION_DEPLOY;
531
- else if (_operationType == OPERATION_CREATE2) return _PERMISSION_DEPLOY;
532
- else if (_operationType == OPERATION_STATICCALL) return _PERMISSION_STATICCALL;
533
- else if (_operationType == OPERATION_DELEGATECALL) return _PERMISSION_DELEGATECALL;
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 _operationType)
526
+ function _extractSuperPermissionFromOperation(uint256 operationType)
537
527
  internal
538
528
  pure
539
- returns (bytes32 superPermission_)
529
+ returns (bytes32 superPermission)
540
530
  {
541
- if (_operationType == OPERATION_CALL) return _PERMISSION_SUPER_CALL;
542
- else if (_operationType == OPERATION_STATICCALL) return _PERMISSION_SUPER_STATICCALL;
543
- else if (_operationType == OPERATION_DELEGATECALL) return _PERMISSION_SUPER_DELEGATECALL;
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 `_from` is authorised to interact with address `_to` via the linked ERC725Account
548
- * @param _from the caller address
549
- * @param _to the address to interact with
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 _from, address _to) internal view {
552
- bytes memory allowedAddresses = ERC725Y(target).getAllowedAddressesFor(_from);
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 (_to == allowedAddressesList[ii]) return;
555
+ if (to == allowedAddressesList[ii]) return;
566
556
  }
567
- revert NotAllowedAddress(_from, _to);
557
+ revert NotAllowedAddress(from, to);
568
558
  }
569
559
 
570
560
  /**
571
- * @dev if `_from` is restricted to interact with contracts that implement a specific interface,
572
- * verify that `_to` implements one of these interface.
573
- * @param _from the caller address
574
- * @param _to the address of the contract to interact with
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 _from, address _to) internal view {
577
- bytes memory allowedStandards = ERC725Y(target).getAllowedStandardsFor(_from);
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 (_to.supportsERC165Interface(allowedStandardsList[ii])) return;
580
+ if (to.supportsERC165Interface(allowedStandardsList[ii])) return;
591
581
  }
592
- revert("Not Allowed Standards");
582
+ revert NotAllowedStandard(from, to);
593
583
  }
594
584
 
595
585
  /**
596
- * @dev verify if `_from` is authorised to use the linked ERC725Account
597
- * to run a specific function `_functionSelector` at a target contract
598
- * @param _from the caller address
599
- * @param _functionSelector the bytes4 function selector of the function to run
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 _from, bytes4 _functionSelector) internal view {
603
- bytes memory allowedFunctions = ERC725Y(target).getAllowedFunctionsFor(_from);
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 (_functionSelector == allowedFunctionsList[ii]) return;
606
+ if (functionSelector == allowedFunctionsList[ii]) return;
617
607
  }
618
- revert NotAllowedFunction(_from, _functionSelector);
608
+ revert NotAllowedFunction(from, functionSelector);
619
609
  }
620
610
 
621
- function _countZeroBytes(bytes32 _key) internal pure returns (uint256) {
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 the empty bytes `0x00` to find the first non-empty bytes
626
- while (_key[index] == 0x00) index--;
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 _from,
633
- bytes32 _addressPermissions,
634
- bytes32 _permissionRequired
622
+ address from,
623
+ bytes32 addressPermissions,
624
+ bytes32 permissionRequired
635
625
  ) internal pure returns (bool) {
636
- if (!_addressPermissions.hasPermission(_permissionRequired)) {
637
- string memory permissionErrorString = _getPermissionErrorString(_permissionRequired);
638
- revert NotAuthorised(_from, permissionErrorString);
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 _permission)
632
+ function _getPermissionErrorString(bytes32 permission)
643
633
  internal
644
634
  pure
645
635
  returns (string memory errorMessage)
646
636
  {
647
- if (_permission == _PERMISSION_CHANGEOWNER) return "TRANSFEROWNERSHIP";
648
- if (_permission == _PERMISSION_CHANGEPERMISSIONS) return "CHANGEPERMISSIONS";
649
- if (_permission == _PERMISSION_ADDPERMISSIONS) return "ADDPERMISSIONS";
650
- if (_permission == _PERMISSION_SETDATA) return "SETDATA";
651
- if (_permission == _PERMISSION_CALL) return "CALL";
652
- if (_permission == _PERMISSION_STATICCALL) return "STATICCALL";
653
- if (_permission == _PERMISSION_DELEGATECALL) return "DELEGATECALL";
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 (_permission == _PERMISSION_DEPLOY) return "DEPLOY";
656
- if (_permission == _PERMISSION_TRANSFERVALUE) return "TRANSFERVALUE";
657
- if (_permission == _PERMISSION_SIGN) return "SIGN";
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
  }