@lukso/lsp-smart-contracts 0.8.0 → 0.8.1
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/CONTRIBUTING.md +8 -0
- package/README.md +21 -21
- package/artifacts/LSP0ERC725Account.json +2 -2
- package/artifacts/LSP0ERC725AccountInit.json +2 -2
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
- package/artifacts/LSP6KeyManager.json +2 -2
- package/artifacts/LSP6KeyManagerInit.json +2 -2
- package/artifacts/LSP7CappedSupply.json +5 -0
- package/artifacts/LSP7CappedSupplyInitAbstract.json +5 -0
- package/artifacts/LSP7CompatibleERC20.json +5 -0
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +5 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +7 -2
- package/artifacts/LSP7CompatibleERC20MintableInit.json +7 -2
- package/artifacts/LSP7DigitalAsset.json +5 -0
- package/artifacts/LSP7DigitalAssetInitAbstract.json +5 -0
- package/artifacts/LSP7Mintable.json +7 -2
- package/artifacts/LSP7MintableInit.json +7 -2
- package/artifacts/LSP8CappedSupply.json +5 -0
- package/artifacts/LSP8CappedSupplyInitAbstract.json +5 -0
- package/artifacts/LSP8CompatibleERC721.json +5 -0
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +5 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +7 -2
- package/artifacts/LSP8CompatibleERC721MintableInit.json +7 -2
- package/artifacts/LSP8IdentifiableDigitalAsset.json +5 -0
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +5 -0
- package/artifacts/LSP8Mintable.json +7 -2
- package/artifacts/LSP8MintableInit.json +7 -2
- package/artifacts/LSP9Vault.json +2 -2
- package/artifacts/LSP9VaultInit.json +2 -2
- package/artifacts/UniversalProfile.json +2 -2
- package/artifacts/UniversalProfileInit.json +2 -2
- package/common/constants.d.ts +738 -0
- package/common/constants.js +785 -0
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +87 -28
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +3 -5
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +2 -4
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +7 -7
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +44 -734
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +229 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +606 -0
- package/contracts/LSP6KeyManager/LSP6Utils.sol +31 -1
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +2 -6
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +5 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +7 -13
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -3
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +1 -3
- package/contracts/LSP9Vault/LSP9VaultCore.sol +85 -25
- package/module/constants.d.ts +738 -0
- package/module/constants.js +782 -0
- package/package.json +26 -4
- package/constants.js +0 -856
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.5;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {LSP6Utils} from "../LSP6Utils.sol";
|
|
9
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
10
|
+
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
11
|
+
|
|
12
|
+
// constants
|
|
13
|
+
import {
|
|
14
|
+
_PERMISSION_TRANSFERVALUE,
|
|
15
|
+
_PERMISSION_SUPER_TRANSFERVALUE,
|
|
16
|
+
_PERMISSION_DEPLOY,
|
|
17
|
+
_PERMISSION_CALL,
|
|
18
|
+
_PERMISSION_SUPER_CALL,
|
|
19
|
+
_PERMISSION_STATICCALL,
|
|
20
|
+
_PERMISSION_SUPER_STATICCALL,
|
|
21
|
+
_PERMISSION_DELEGATECALL,
|
|
22
|
+
_PERMISSION_SUPER_DELEGATECALL
|
|
23
|
+
} from "../LSP6Constants.sol";
|
|
24
|
+
import {
|
|
25
|
+
OPERATION_0_CALL,
|
|
26
|
+
OPERATION_1_CREATE,
|
|
27
|
+
OPERATION_2_CREATE2,
|
|
28
|
+
OPERATION_3_STATICCALL,
|
|
29
|
+
OPERATION_4_DELEGATECALL
|
|
30
|
+
} from "@erc725/smart-contracts/contracts/constants.sol";
|
|
31
|
+
|
|
32
|
+
// errors
|
|
33
|
+
import {
|
|
34
|
+
DelegateCallDisallowedViaKeyManager,
|
|
35
|
+
NoCallsAllowed,
|
|
36
|
+
NotAllowedCall,
|
|
37
|
+
InvalidEncodedAllowedCalls,
|
|
38
|
+
InvalidWhitelistedCall,
|
|
39
|
+
NotAuthorised
|
|
40
|
+
} from "../LSP6Errors.sol";
|
|
41
|
+
|
|
42
|
+
abstract contract LSP6ExecuteModule {
|
|
43
|
+
using ERC165Checker for address;
|
|
44
|
+
using LSP6Utils for *;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @dev verify if `controllerAddress` has the required permissions to interact with other addresses using the controlledContract.
|
|
48
|
+
* @param controlledContract the address of the ERC725 contract where the payload is executed and where the permissions are verified.
|
|
49
|
+
* @param controllerAddress the address who want to run the execute function on the ERC725Account.
|
|
50
|
+
* @param controllerPermissions the permissions of the controller address.
|
|
51
|
+
* @param payload the ABI encoded payload `controlledContract.execute(...)`.
|
|
52
|
+
*/
|
|
53
|
+
function _verifyCanExecute(
|
|
54
|
+
address controlledContract,
|
|
55
|
+
address controllerAddress,
|
|
56
|
+
bytes32 controllerPermissions,
|
|
57
|
+
bytes calldata payload
|
|
58
|
+
) internal view virtual {
|
|
59
|
+
// MUST be one of the ERC725X operation types.
|
|
60
|
+
uint256 operationType = uint256(bytes32(payload[4:36]));
|
|
61
|
+
|
|
62
|
+
// DELEGATECALL is disallowed by default on the LSP6 Key Manager.
|
|
63
|
+
if (operationType == OPERATION_4_DELEGATECALL) {
|
|
64
|
+
revert DelegateCallDisallowedViaKeyManager();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
uint256 value = uint256(bytes32(payload[68:100]));
|
|
68
|
+
|
|
69
|
+
// prettier-ignore
|
|
70
|
+
bool isContractCreation = operationType == OPERATION_1_CREATE || operationType == OPERATION_2_CREATE2;
|
|
71
|
+
bool isCallDataPresent = payload.length > 164;
|
|
72
|
+
|
|
73
|
+
// SUPER operation only applies to contract call, not contract creation
|
|
74
|
+
bool hasSuperOperation = isContractCreation
|
|
75
|
+
? false
|
|
76
|
+
: controllerPermissions.hasPermission(
|
|
77
|
+
_extractSuperPermissionFromOperation(operationType)
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// CHECK if we are doing an empty call, as the receive() or fallback() function
|
|
81
|
+
// of the controlledContract could run some code.
|
|
82
|
+
if (!hasSuperOperation && !isCallDataPresent && value == 0) {
|
|
83
|
+
_requirePermissions(
|
|
84
|
+
controllerAddress,
|
|
85
|
+
controllerPermissions,
|
|
86
|
+
_extractPermissionFromOperation(operationType)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (isCallDataPresent && !hasSuperOperation) {
|
|
91
|
+
_requirePermissions(
|
|
92
|
+
controllerAddress,
|
|
93
|
+
controllerPermissions,
|
|
94
|
+
_extractPermissionFromOperation(operationType)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
bool hasSuperTransferValue = controllerPermissions.hasPermission(
|
|
99
|
+
_PERMISSION_SUPER_TRANSFERVALUE
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
if (value != 0 && !hasSuperTransferValue) {
|
|
103
|
+
_requirePermissions(
|
|
104
|
+
controllerAddress,
|
|
105
|
+
controllerPermissions,
|
|
106
|
+
_PERMISSION_TRANSFERVALUE
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Skip on contract creation (CREATE or CREATE2)
|
|
111
|
+
if (isContractCreation) return;
|
|
112
|
+
|
|
113
|
+
// Skip if caller has SUPER permissions for external calls, with or without calldata (empty calls)
|
|
114
|
+
if (hasSuperOperation && value == 0) return;
|
|
115
|
+
|
|
116
|
+
// Skip if caller has SUPER permission for value transfers
|
|
117
|
+
if (hasSuperTransferValue && !isCallDataPresent && value != 0) return;
|
|
118
|
+
|
|
119
|
+
// Skip if both SUPER permissions are present
|
|
120
|
+
if (hasSuperOperation && hasSuperTransferValue) return;
|
|
121
|
+
|
|
122
|
+
_verifyAllowedCall(controlledContract, controllerAddress, payload);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function _verifyAllowedCall(
|
|
126
|
+
address controlledContract,
|
|
127
|
+
address controllerAddress,
|
|
128
|
+
bytes calldata payload
|
|
129
|
+
) internal view virtual {
|
|
130
|
+
// CHECK for ALLOWED CALLS
|
|
131
|
+
address to = address(bytes20(payload[48:68]));
|
|
132
|
+
|
|
133
|
+
bool containsFunctionCall = payload.length >= 168;
|
|
134
|
+
bytes4 selector;
|
|
135
|
+
if (containsFunctionCall) selector = bytes4(payload[164:168]);
|
|
136
|
+
|
|
137
|
+
bytes memory allowedCalls = ERC725Y(controlledContract).getAllowedCallsFor(
|
|
138
|
+
controllerAddress
|
|
139
|
+
);
|
|
140
|
+
uint256 allowedCallsLength = allowedCalls.length;
|
|
141
|
+
|
|
142
|
+
if (allowedCallsLength == 0) {
|
|
143
|
+
revert NoCallsAllowed(controllerAddress);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
bool isAllowedStandard;
|
|
147
|
+
bool isAllowedAddress;
|
|
148
|
+
bool isAllowedFunction;
|
|
149
|
+
|
|
150
|
+
for (uint256 ii; ii < allowedCallsLength; ii += 30) {
|
|
151
|
+
if (ii + 30 > allowedCallsLength) {
|
|
152
|
+
revert InvalidEncodedAllowedCalls(allowedCalls);
|
|
153
|
+
}
|
|
154
|
+
bytes memory chunk = BytesLib.slice(allowedCalls, ii + 2, 28);
|
|
155
|
+
|
|
156
|
+
if (bytes28(chunk) == 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff) {
|
|
157
|
+
revert InvalidWhitelistedCall(controllerAddress);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
bytes4 allowedStandard = bytes4(chunk);
|
|
161
|
+
address allowedAddress = address(bytes20(bytes28(chunk) << 32));
|
|
162
|
+
bytes4 allowedFunction = bytes4(bytes28(chunk) << 192);
|
|
163
|
+
|
|
164
|
+
isAllowedStandard =
|
|
165
|
+
allowedStandard == 0xffffffff ||
|
|
166
|
+
to.supportsERC165InterfaceUnchecked(allowedStandard);
|
|
167
|
+
isAllowedAddress =
|
|
168
|
+
allowedAddress == 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF ||
|
|
169
|
+
to == allowedAddress;
|
|
170
|
+
isAllowedFunction =
|
|
171
|
+
allowedFunction == 0xffffffff ||
|
|
172
|
+
(containsFunctionCall && (selector == allowedFunction));
|
|
173
|
+
|
|
174
|
+
if (isAllowedStandard && isAllowedAddress && isAllowedFunction) return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
revert NotAllowedCall(controllerAddress, to, selector);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @dev extract the required permission + a descriptive string, based on the `_operationType`
|
|
182
|
+
* being run via ERC725Account.execute(...)
|
|
183
|
+
* @param operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
|
|
184
|
+
* @return permissionsRequired (bytes32) the permission associated with the `_operationType`
|
|
185
|
+
*/
|
|
186
|
+
function _extractPermissionFromOperation(uint256 operationType)
|
|
187
|
+
internal
|
|
188
|
+
pure
|
|
189
|
+
virtual
|
|
190
|
+
returns (bytes32 permissionsRequired)
|
|
191
|
+
{
|
|
192
|
+
if (operationType == OPERATION_0_CALL) return _PERMISSION_CALL;
|
|
193
|
+
else if (operationType == OPERATION_1_CREATE) return _PERMISSION_DEPLOY;
|
|
194
|
+
else if (operationType == OPERATION_2_CREATE2) return _PERMISSION_DEPLOY;
|
|
195
|
+
else if (operationType == OPERATION_3_STATICCALL) return _PERMISSION_STATICCALL;
|
|
196
|
+
else if (operationType == OPERATION_4_DELEGATECALL) return _PERMISSION_DELEGATECALL;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @dev returns the `superPermission` needed for a specific `operationType` of the `execute(..)`
|
|
201
|
+
*/
|
|
202
|
+
function _extractSuperPermissionFromOperation(uint256 operationType)
|
|
203
|
+
internal
|
|
204
|
+
pure
|
|
205
|
+
virtual
|
|
206
|
+
returns (bytes32 superPermission)
|
|
207
|
+
{
|
|
208
|
+
if (operationType == OPERATION_0_CALL) return _PERMISSION_SUPER_CALL;
|
|
209
|
+
else if (operationType == OPERATION_3_STATICCALL) return _PERMISSION_SUPER_STATICCALL;
|
|
210
|
+
else if (operationType == OPERATION_4_DELEGATECALL) return _PERMISSION_SUPER_DELEGATECALL;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @dev revert if `controller`'s `addressPermissions` doesn't contain `permissionsRequired`
|
|
215
|
+
* @param controller the caller address
|
|
216
|
+
* @param addressPermissions the caller's permissions BitArray
|
|
217
|
+
* @param permissionRequired the required permission
|
|
218
|
+
*/
|
|
219
|
+
function _requirePermissions(
|
|
220
|
+
address controller,
|
|
221
|
+
bytes32 addressPermissions,
|
|
222
|
+
bytes32 permissionRequired
|
|
223
|
+
) internal pure virtual {
|
|
224
|
+
if (!LSP6Utils.hasPermission(addressPermissions, permissionRequired)) {
|
|
225
|
+
string memory permissionErrorString = LSP6Utils.getPermissionName(permissionRequired);
|
|
226
|
+
revert NotAuthorised(controller, permissionErrorString);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.5;
|
|
3
|
+
|
|
4
|
+
// libraries
|
|
5
|
+
import {LSP6Utils} from "../LSP6Utils.sol";
|
|
6
|
+
|
|
7
|
+
// constants
|
|
8
|
+
import {_PERMISSION_CHANGEOWNER} from "../LSP6Constants.sol";
|
|
9
|
+
|
|
10
|
+
// errors
|
|
11
|
+
import {NotAuthorised} from "../LSP6Errors.sol";
|
|
12
|
+
|
|
13
|
+
abstract contract LSP6OwnershipModule {
|
|
14
|
+
function _verifyOwnershipPermissions(address controllerAddress, bytes32 controllerPermissions)
|
|
15
|
+
internal
|
|
16
|
+
pure
|
|
17
|
+
{
|
|
18
|
+
if (!LSP6Utils.hasPermission(controllerPermissions, _PERMISSION_CHANGEOWNER)) {
|
|
19
|
+
string memory permissionErrorString = LSP6Utils.getPermissionName(
|
|
20
|
+
_PERMISSION_CHANGEOWNER
|
|
21
|
+
);
|
|
22
|
+
revert NotAuthorised(controllerAddress, permissionErrorString);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|