@lukso/lsp-smart-contracts 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -8
- package/artifacts/LSP0ERC725Account.json +90 -50
- package/artifacts/LSP0ERC725AccountInit.json +90 -50
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +31 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
- package/artifacts/LSP4Compatibility.json +39 -40
- package/artifacts/LSP4DigitalAssetMetadata.json +39 -40
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +39 -40
- package/artifacts/LSP6KeyManager.json +107 -8
- package/artifacts/LSP6KeyManagerInit.json +119 -20
- package/artifacts/LSP7CappedSupply.json +78 -38
- package/artifacts/LSP7CappedSupplyInitAbstract.json +78 -38
- package/artifacts/LSP7CompatibleERC20.json +78 -38
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +78 -38
- package/artifacts/LSP7CompatibleERC20Mintable.json +80 -40
- package/artifacts/LSP7CompatibleERC20MintableInit.json +80 -40
- package/artifacts/LSP7DigitalAsset.json +78 -38
- package/artifacts/LSP7DigitalAssetInitAbstract.json +78 -38
- package/artifacts/LSP7Mintable.json +80 -40
- package/artifacts/LSP7MintableInit.json +80 -40
- package/artifacts/LSP8CappedSupply.json +39 -40
- package/artifacts/LSP8CappedSupplyInitAbstract.json +39 -40
- package/artifacts/LSP8CompatibleERC721.json +42 -43
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +42 -43
- package/artifacts/LSP8CompatibleERC721Mintable.json +44 -45
- package/artifacts/LSP8CompatibleERC721MintableInit.json +44 -45
- package/artifacts/LSP8IdentifiableDigitalAsset.json +39 -40
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +39 -40
- package/artifacts/LSP8Mintable.json +41 -42
- package/artifacts/LSP8MintableInit.json +41 -42
- package/artifacts/LSP9Vault.json +73 -55
- package/artifacts/LSP9VaultInit.json +73 -55
- package/artifacts/UniversalProfile.json +90 -50
- package/artifacts/UniversalProfileInit.json +90 -50
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +62 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +36 -6
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +605 -219
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +31 -5
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +37 -3
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +71 -60
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -7
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +41 -84
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +129 -77
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +45 -16
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
- package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +83 -0
- package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
- package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +76 -66
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +12 -3
- package/contracts/LSP6KeyManager/LSP6Constants.sol +9 -3
- package/contracts/LSP6KeyManager/LSP6Errors.sol +22 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +172 -29
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +270 -100
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +187 -67
- package/contracts/LSP6KeyManager/LSP6Utils.sol +31 -20
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +79 -30
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +27 -29
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
- package/contracts/LSP9Vault/ILSP9Vault.sol +27 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Vault.sol +11 -8
- package/contracts/LSP9Vault/LSP9VaultCore.sol +96 -71
- package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +19 -7
- package/contracts/UniversalProfileInitAbstract.sol +5 -0
- package/devdocs/Create2Factory.json +16 -0
- package/devdocs/LSP0ERC725Account.json +200 -0
- package/devdocs/LSP0ERC725AccountInit.json +203 -0
- package/devdocs/LSP11BasicSocialRecovery.json +146 -0
- package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
- package/devdocs/LSP16UniversalFactory.json +51 -0
- package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
- package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
- package/devdocs/LSP4Compatibility.json +79 -0
- package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
- package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
- package/devdocs/LSP6KeyManager.json +257 -0
- package/devdocs/LSP6KeyManagerInit.json +260 -0
- package/devdocs/LSP7CappedSupply.json +211 -0
- package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
- package/devdocs/LSP7CompatibleERC20.json +225 -0
- package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
- package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
- package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
- package/devdocs/LSP7DigitalAsset.json +210 -0
- package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
- package/devdocs/LSP7Mintable.json +219 -0
- package/devdocs/LSP7MintableInit.json +220 -0
- package/devdocs/LSP8CappedSupply.json +232 -0
- package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
- package/devdocs/LSP8CompatibleERC721.json +298 -0
- package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
- package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
- package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
- package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
- package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
- package/devdocs/LSP8Mintable.json +242 -0
- package/devdocs/LSP8MintableInit.json +245 -0
- package/devdocs/LSP9Vault.json +171 -0
- package/devdocs/LSP9VaultInit.json +175 -0
- package/devdocs/UniversalProfile.json +199 -0
- package/devdocs/UniversalProfileInit.json +202 -0
- package/devdocs/UniversalReceiverAddressStore.json +9 -0
- package/dist/constants.cjs.js +31569 -0
- package/dist/constants.d.ts +31681 -0
- package/dist/constants.es.js +31550 -0
- package/package.json +70 -52
- package/userdocs/Create2Factory.json +5 -0
- package/userdocs/LSP0ERC725Account.json +47 -0
- package/userdocs/LSP0ERC725AccountInit.json +47 -0
- package/userdocs/LSP11BasicSocialRecovery.json +29 -0
- package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
- package/userdocs/LSP16UniversalFactory.json +5 -0
- package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
- package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
- package/userdocs/LSP4Compatibility.json +20 -0
- package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
- package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
- package/userdocs/LSP6KeyManager.json +18 -0
- package/userdocs/LSP6KeyManagerInit.json +18 -0
- package/userdocs/LSP7CappedSupply.json +29 -0
- package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
- package/userdocs/LSP7CompatibleERC20.json +35 -0
- package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
- package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
- package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
- package/userdocs/LSP7DigitalAsset.json +29 -0
- package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
- package/userdocs/LSP7Mintable.json +29 -0
- package/userdocs/LSP7MintableInit.json +29 -0
- package/userdocs/LSP8CappedSupply.json +23 -0
- package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
- package/userdocs/LSP8CompatibleERC721.json +29 -0
- package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
- package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
- package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
- package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
- package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
- package/userdocs/LSP8Mintable.json +23 -0
- package/userdocs/LSP8MintableInit.json +23 -0
- package/userdocs/LSP9Vault.json +38 -0
- package/userdocs/LSP9VaultInit.json +38 -0
- package/userdocs/UniversalProfile.json +50 -0
- package/userdocs/UniversalProfileInit.json +50 -0
- package/userdocs/UniversalReceiverAddressStore.json +5 -0
- package/CONTRIBUTING.md +0 -57
- package/common/constants.d.ts +0 -738
- package/common/constants.js +0 -785
- package/contracts/Utils/GasLib.sol +0 -17
- package/module/constants.d.ts +0 -738
- package/module/constants.js +0 -782
|
@@ -18,8 +18,10 @@ import {
|
|
|
18
18
|
_PERMISSION_SUPER_CALL,
|
|
19
19
|
_PERMISSION_STATICCALL,
|
|
20
20
|
_PERMISSION_SUPER_STATICCALL,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
_ALLOWEDCALLS_TRANSFERVALUE,
|
|
22
|
+
_ALLOWEDCALLS_CALL,
|
|
23
|
+
_ALLOWEDCALLS_STATICCALL,
|
|
24
|
+
_ALLOWEDCALLS_DELEGATECALL
|
|
23
25
|
} from "../LSP6Constants.sol";
|
|
24
26
|
import {
|
|
25
27
|
OPERATION_0_CALL,
|
|
@@ -36,7 +38,9 @@ import {
|
|
|
36
38
|
NotAllowedCall,
|
|
37
39
|
InvalidEncodedAllowedCalls,
|
|
38
40
|
InvalidWhitelistedCall,
|
|
39
|
-
NotAuthorised
|
|
41
|
+
NotAuthorised,
|
|
42
|
+
InvalidPayload,
|
|
43
|
+
CallingKeyManagerNotAllowed
|
|
40
44
|
} from "../LSP6Errors.sol";
|
|
41
45
|
|
|
42
46
|
abstract contract LSP6ExecuteModule {
|
|
@@ -46,80 +50,156 @@ abstract contract LSP6ExecuteModule {
|
|
|
46
50
|
/**
|
|
47
51
|
* @dev verify if `controllerAddress` has the required permissions to interact with other addresses using the controlledContract.
|
|
48
52
|
* @param controlledContract the address of the ERC725 contract where the payload is executed and where the permissions are verified.
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
53
|
+
* @param controller the address who want to run the execute function on the ERC725Account.
|
|
54
|
+
* @param permissions the permissions of the controller address.
|
|
51
55
|
* @param payload the ABI encoded payload `controlledContract.execute(...)`.
|
|
52
56
|
*/
|
|
53
57
|
function _verifyCanExecute(
|
|
54
58
|
address controlledContract,
|
|
55
|
-
address
|
|
56
|
-
bytes32
|
|
59
|
+
address controller,
|
|
60
|
+
bytes32 permissions,
|
|
57
61
|
bytes calldata payload
|
|
58
62
|
) internal view virtual {
|
|
63
|
+
// CHECK the offset of `data` is not pointing to the previous parameters
|
|
64
|
+
if (
|
|
65
|
+
bytes32(payload[100:132]) !=
|
|
66
|
+
0x0000000000000000000000000000000000000000000000000000000000000080
|
|
67
|
+
) {
|
|
68
|
+
revert InvalidPayload(payload);
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
// MUST be one of the ERC725X operation types.
|
|
60
72
|
uint256 operationType = uint256(bytes32(payload[4:36]));
|
|
61
73
|
|
|
62
|
-
|
|
74
|
+
address to = address(bytes20(payload[48:68]));
|
|
75
|
+
|
|
76
|
+
// if to is the KeyManager address revert
|
|
77
|
+
if (to == address(this)) {
|
|
78
|
+
revert CallingKeyManagerNotAllowed();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Future versions of the KeyManager willing to allow LSP0 to call the KeyManager
|
|
82
|
+
// may need to implement this check to avoid inconsistent state of reentrancy
|
|
83
|
+
// that may lead to lock the use of the KeyManager
|
|
84
|
+
|
|
85
|
+
// Check to restrict controllers with execute permissions to call lsp20 functions
|
|
86
|
+
// to avoid setting the reentrancy guard to a non-valid state
|
|
87
|
+
|
|
88
|
+
// if (payload.length >= 168 && to == address(this)) {
|
|
89
|
+
// if (
|
|
90
|
+
// bytes4(payload[164:168]) == ILSP20.lsp20VerifyCall.selector ||
|
|
91
|
+
// bytes4(payload[164:168]) == ILSP20.lsp20VerifyCallResult.selector
|
|
92
|
+
// ) {
|
|
93
|
+
// revert CallingLSP20FunctionsOnLSP6NotAllowed();
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
|
|
97
|
+
// if it is a message call
|
|
98
|
+
if (operationType == OPERATION_0_CALL) {
|
|
99
|
+
return _verifyCanCall(controlledContract, controller, permissions, payload);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// if it is a contract creation
|
|
103
|
+
if (operationType == OPERATION_1_CREATE || operationType == OPERATION_2_CREATE2) {
|
|
104
|
+
// required to check for permission TRANSFERVALUE if we are funding
|
|
105
|
+
// the contract on deployment via a payable constructor
|
|
106
|
+
bool isFundingContract = uint256(bytes32(payload[68:100])) != 0;
|
|
107
|
+
|
|
108
|
+
return _verifyCanDeployContract(controller, permissions, isFundingContract);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// if it is a STATICALL
|
|
112
|
+
// we do not check for TRANSFERVALUE permission,
|
|
113
|
+
// as ERC725X will revert if a value is provided with operation type STATICCALL.
|
|
114
|
+
if (operationType == OPERATION_3_STATICCALL) {
|
|
115
|
+
return _verifyCanStaticCall(controlledContract, controller, permissions, payload);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// DELEGATECALL is disallowed by default on the Key Manager.
|
|
63
119
|
if (operationType == OPERATION_4_DELEGATECALL) {
|
|
64
120
|
revert DelegateCallDisallowedViaKeyManager();
|
|
65
121
|
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function _verifyCanDeployContract(
|
|
125
|
+
address controller,
|
|
126
|
+
bytes32 permissions,
|
|
127
|
+
bool isFundingContract
|
|
128
|
+
) internal view virtual {
|
|
129
|
+
_requirePermissions(controller, permissions, _PERMISSION_DEPLOY);
|
|
66
130
|
|
|
67
|
-
|
|
131
|
+
bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
|
|
68
132
|
|
|
69
|
-
//
|
|
70
|
-
|
|
133
|
+
// CHECK if we are funding the contract
|
|
134
|
+
if (isFundingContract && !hasSuperTransferValue) {
|
|
135
|
+
revert NotAuthorised(controller, "SUPER_TRANSFERVALUE");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function _verifyCanStaticCall(
|
|
140
|
+
address controlledContract,
|
|
141
|
+
address controller,
|
|
142
|
+
bytes32 permissions,
|
|
143
|
+
bytes calldata payload
|
|
144
|
+
) internal view virtual {
|
|
145
|
+
bool hasSuperStaticCall = permissions.hasPermission(_PERMISSION_SUPER_STATICCALL);
|
|
146
|
+
|
|
147
|
+
// Skip if caller has SUPER permission for static calls
|
|
148
|
+
if (hasSuperStaticCall) return;
|
|
149
|
+
|
|
150
|
+
_requirePermissions(controller, permissions, _PERMISSION_STATICCALL);
|
|
151
|
+
|
|
152
|
+
_verifyAllowedCall(controlledContract, controller, payload);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function _verifyCanCall(
|
|
156
|
+
address controlledContract,
|
|
157
|
+
address controller,
|
|
158
|
+
bytes32 permissions,
|
|
159
|
+
bytes calldata payload
|
|
160
|
+
) internal view virtual {
|
|
161
|
+
bool isTransferringValue = uint256(bytes32(payload[68:100])) != 0;
|
|
162
|
+
|
|
163
|
+
bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
|
|
164
|
+
|
|
165
|
+
// all the parameters are abi-encoded (padded to 32 bytes words)
|
|
166
|
+
//
|
|
167
|
+
// 4 (ERC725X.execute selector)
|
|
168
|
+
// + 32 (uint256 operationType)
|
|
169
|
+
// + 32 (address to/target)
|
|
170
|
+
// + 32 (uint256 value)
|
|
171
|
+
// + 32 (`data` offset)
|
|
172
|
+
// + 32 (`data` length)
|
|
173
|
+
// --------------------
|
|
174
|
+
// = 164 bytes in total
|
|
71
175
|
bool isCallDataPresent = payload.length > 164;
|
|
72
176
|
|
|
73
|
-
|
|
74
|
-
bool hasSuperOperation = isContractCreation
|
|
75
|
-
? false
|
|
76
|
-
: controllerPermissions.hasPermission(
|
|
77
|
-
_extractSuperPermissionFromOperation(operationType)
|
|
78
|
-
);
|
|
177
|
+
bool hasSuperCall = permissions.hasPermission(_PERMISSION_SUPER_CALL);
|
|
79
178
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (!hasSuperOperation && !isCallDataPresent && value == 0) {
|
|
83
|
-
_requirePermissions(
|
|
84
|
-
controllerAddress,
|
|
85
|
-
controllerPermissions,
|
|
86
|
-
_extractPermissionFromOperation(operationType)
|
|
87
|
-
);
|
|
179
|
+
if (isTransferringValue && !hasSuperTransferValue) {
|
|
180
|
+
_requirePermissions(controller, permissions, _PERMISSION_TRANSFERVALUE);
|
|
88
181
|
}
|
|
89
182
|
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
_extractPermissionFromOperation(operationType)
|
|
95
|
-
);
|
|
183
|
+
// CHECK if we are doing an empty call, as the receive() or fallback() function
|
|
184
|
+
// of the controlledContract could run some code.
|
|
185
|
+
if (!hasSuperCall && !isCallDataPresent && !isTransferringValue) {
|
|
186
|
+
_requirePermissions(controller, permissions, _PERMISSION_CALL);
|
|
96
187
|
}
|
|
97
188
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
if (value != 0 && !hasSuperTransferValue) {
|
|
103
|
-
_requirePermissions(
|
|
104
|
-
controllerAddress,
|
|
105
|
-
controllerPermissions,
|
|
106
|
-
_PERMISSION_TRANSFERVALUE
|
|
107
|
-
);
|
|
189
|
+
if (isCallDataPresent && !hasSuperCall) {
|
|
190
|
+
_requirePermissions(controller, permissions, _PERMISSION_CALL);
|
|
108
191
|
}
|
|
109
192
|
|
|
110
|
-
// Skip on contract creation (CREATE or CREATE2)
|
|
111
|
-
if (isContractCreation) return;
|
|
112
|
-
|
|
113
193
|
// Skip if caller has SUPER permissions for external calls, with or without calldata (empty calls)
|
|
114
|
-
if (
|
|
194
|
+
if (hasSuperCall && !isTransferringValue) return;
|
|
115
195
|
|
|
116
196
|
// Skip if caller has SUPER permission for value transfers
|
|
117
|
-
if (hasSuperTransferValue && !isCallDataPresent &&
|
|
197
|
+
if (hasSuperTransferValue && !isCallDataPresent && isTransferringValue) return;
|
|
118
198
|
|
|
119
199
|
// Skip if both SUPER permissions are present
|
|
120
|
-
if (
|
|
200
|
+
if (hasSuperCall && hasSuperTransferValue) return;
|
|
121
201
|
|
|
122
|
-
_verifyAllowedCall(controlledContract,
|
|
202
|
+
_verifyAllowedCall(controlledContract, controller, payload);
|
|
123
203
|
}
|
|
124
204
|
|
|
125
205
|
function _verifyAllowedCall(
|
|
@@ -127,87 +207,177 @@ abstract contract LSP6ExecuteModule {
|
|
|
127
207
|
address controllerAddress,
|
|
128
208
|
bytes calldata payload
|
|
129
209
|
) internal view virtual {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
210
|
+
(
|
|
211
|
+
uint256 operationType,
|
|
212
|
+
address to,
|
|
213
|
+
uint256 value,
|
|
214
|
+
bytes4 selector,
|
|
215
|
+
bool isEmptyCall
|
|
216
|
+
) = _extractExecuteParameters(payload);
|
|
136
217
|
|
|
218
|
+
// CHECK for ALLOWED CALLS
|
|
137
219
|
bytes memory allowedCalls = ERC725Y(controlledContract).getAllowedCallsFor(
|
|
138
220
|
controllerAddress
|
|
139
221
|
);
|
|
140
|
-
uint256 allowedCallsLength = allowedCalls.length;
|
|
141
222
|
|
|
142
|
-
if (
|
|
223
|
+
if (allowedCalls.length == 0) {
|
|
143
224
|
revert NoCallsAllowed(controllerAddress);
|
|
144
225
|
}
|
|
145
226
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
227
|
+
bytes4 requiredCallTypes = _extractCallType(operationType, value, isEmptyCall);
|
|
228
|
+
|
|
229
|
+
for (uint256 ii; ii < allowedCalls.length; ii += 34) {
|
|
230
|
+
/// @dev structure of an AllowedCall
|
|
231
|
+
//
|
|
232
|
+
/// AllowedCall = 0x00200000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
233
|
+
///
|
|
234
|
+
/// 0020 = hex for '32' bytes long
|
|
235
|
+
/// 0000000n = call type(s)
|
|
236
|
+
/// cafecafecafecafecafecafecafecafecafecafe = address
|
|
237
|
+
/// 5a5a5a5a = standard
|
|
238
|
+
/// f1f1f1f1 = function
|
|
239
|
+
|
|
240
|
+
// CHECK that we can extract an AllowedCall
|
|
241
|
+
if (ii + 34 > allowedCalls.length) {
|
|
152
242
|
revert InvalidEncodedAllowedCalls(allowedCalls);
|
|
153
243
|
}
|
|
154
|
-
bytes memory chunk = BytesLib.slice(allowedCalls, ii + 2, 28);
|
|
155
244
|
|
|
156
|
-
|
|
245
|
+
// extract one AllowedCall at a time
|
|
246
|
+
bytes memory allowedCall = BytesLib.slice(allowedCalls, ii + 2, 32);
|
|
247
|
+
|
|
248
|
+
// 0xxxxxxxxxffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
249
|
+
// (excluding the callTypes) not allowed
|
|
250
|
+
// as equivalent to whitelisting any call (= SUPER permission)
|
|
251
|
+
if (bytes28(bytes32(allowedCall) << 32) == bytes28(type(uint224).max)) {
|
|
157
252
|
revert InvalidWhitelistedCall(controllerAddress);
|
|
158
253
|
}
|
|
159
254
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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;
|
|
255
|
+
if (
|
|
256
|
+
_isAllowedCallType(allowedCall, requiredCallTypes) &&
|
|
257
|
+
_isAllowedAddress(allowedCall, to) &&
|
|
258
|
+
_isAllowedStandard(allowedCall, to) &&
|
|
259
|
+
_isAllowedFunction(allowedCall, selector)
|
|
260
|
+
) return;
|
|
175
261
|
}
|
|
176
262
|
|
|
177
263
|
revert NotAllowedCall(controllerAddress, to, selector);
|
|
178
264
|
}
|
|
179
265
|
|
|
180
266
|
/**
|
|
181
|
-
* @dev extract the
|
|
182
|
-
*
|
|
183
|
-
* @
|
|
184
|
-
* @return permissionsRequired (bytes32) the permission associated with the `_operationType`
|
|
267
|
+
* @dev extract the bytes4 representation of a single bit for the type of call according to the `operationType`
|
|
268
|
+
* @param operationType 0 = CALL, 3 = STATICCALL or 3 = DELEGATECALL
|
|
269
|
+
* @return requiredCallTypes a bytes4 value containing a single 1 bit for the callType
|
|
185
270
|
*/
|
|
186
|
-
function
|
|
271
|
+
function _extractCallType(
|
|
272
|
+
uint256 operationType,
|
|
273
|
+
uint256 value,
|
|
274
|
+
bool isEmptyCall
|
|
275
|
+
) internal pure returns (bytes4 requiredCallTypes) {
|
|
276
|
+
// if there is value being transferred, add the extra bit
|
|
277
|
+
// for the first bit for Value Transfer in the `requiredCallTypes`
|
|
278
|
+
if (value != 0) {
|
|
279
|
+
requiredCallTypes |= _ALLOWEDCALLS_TRANSFERVALUE;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (!isEmptyCall) {
|
|
283
|
+
if (operationType == OPERATION_0_CALL) {
|
|
284
|
+
requiredCallTypes |= _ALLOWEDCALLS_CALL;
|
|
285
|
+
} else if (operationType == OPERATION_3_STATICCALL) {
|
|
286
|
+
requiredCallTypes |= _ALLOWEDCALLS_STATICCALL;
|
|
287
|
+
} else if (operationType == OPERATION_4_DELEGATECALL) {
|
|
288
|
+
requiredCallTypes |= _ALLOWEDCALLS_DELEGATECALL;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function _extractExecuteParameters(bytes calldata executeCalldata)
|
|
187
294
|
internal
|
|
188
295
|
pure
|
|
189
|
-
|
|
190
|
-
|
|
296
|
+
returns (
|
|
297
|
+
uint256,
|
|
298
|
+
address,
|
|
299
|
+
uint256,
|
|
300
|
+
bytes4,
|
|
301
|
+
bool
|
|
302
|
+
)
|
|
191
303
|
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
304
|
+
uint256 operationType = uint256(bytes32(executeCalldata[4:36]));
|
|
305
|
+
|
|
306
|
+
// CHECK that it is a valid address left-padded with `00` on the 12 upper bytes
|
|
307
|
+
if (bytes12(executeCalldata[36:48]) != bytes12(0)) {
|
|
308
|
+
revert InvalidPayload(executeCalldata);
|
|
309
|
+
}
|
|
310
|
+
address to = address(bytes20(executeCalldata[48:68]));
|
|
311
|
+
|
|
312
|
+
uint256 value = uint256(bytes32(executeCalldata[68:100]));
|
|
313
|
+
|
|
314
|
+
// CHECK if there is at least a 4 bytes function selector
|
|
315
|
+
bytes4 selector = executeCalldata.length >= 168
|
|
316
|
+
? bytes4(executeCalldata[164:168])
|
|
317
|
+
: bytes4(0);
|
|
318
|
+
|
|
319
|
+
return (operationType, to, value, selector, executeCalldata.length == 164);
|
|
197
320
|
}
|
|
198
321
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
322
|
+
function _isAllowedAddress(bytes memory allowedCall, address to) internal pure returns (bool) {
|
|
323
|
+
// <offset> = 4 bytes x 8 bits = 32 bits
|
|
324
|
+
//
|
|
325
|
+
// <offset>v----------------address---------------v
|
|
326
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
327
|
+
address allowedAddress = address(bytes20(bytes32(allowedCall) << 32));
|
|
328
|
+
|
|
329
|
+
// ANY address = 0xffffffffffffffffffffffffffffffffffffffff
|
|
330
|
+
return allowedAddress == address(bytes20(type(uint160).max)) || to == allowedAddress;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function _isAllowedStandard(bytes memory allowedCall, address to) internal view returns (bool) {
|
|
334
|
+
// <offset> = 24 bytes x 8 bits = 192 bits
|
|
335
|
+
//
|
|
336
|
+
// standard
|
|
337
|
+
// <----------------<offset>---------------------->v------v
|
|
338
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
339
|
+
bytes4 allowedStandard = bytes4(bytes32(allowedCall) << 192);
|
|
340
|
+
|
|
341
|
+
// ANY Standard = 0xffffffff
|
|
342
|
+
return
|
|
343
|
+
allowedStandard == bytes4(type(uint32).max) ||
|
|
344
|
+
to.supportsERC165InterfaceUnchecked(allowedStandard);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function _isAllowedFunction(bytes memory allowedCall, bytes4 requiredFunction)
|
|
348
|
+
internal
|
|
349
|
+
pure
|
|
350
|
+
returns (bool)
|
|
351
|
+
{
|
|
352
|
+
// <offset> = 28 bytes x 8 bits = 224 bits
|
|
353
|
+
//
|
|
354
|
+
// function
|
|
355
|
+
// <------------------------<offset>---------------------->v------v
|
|
356
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
357
|
+
bytes4 allowedFunction = bytes4(bytes32(allowedCall) << 224);
|
|
358
|
+
|
|
359
|
+
bool isFunctionCall = requiredFunction != bytes4(0);
|
|
360
|
+
|
|
361
|
+
// ANY function = 0xffffffff
|
|
362
|
+
return
|
|
363
|
+
allowedFunction == bytes4(type(uint32).max) ||
|
|
364
|
+
(isFunctionCall && (requiredFunction == allowedFunction));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function _isAllowedCallType(bytes memory allowedCall, bytes4 requiredCallTypes)
|
|
203
368
|
internal
|
|
204
369
|
pure
|
|
205
|
-
|
|
206
|
-
returns (bytes32 superPermission)
|
|
370
|
+
returns (bool)
|
|
207
371
|
{
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
372
|
+
// extract callType
|
|
373
|
+
//
|
|
374
|
+
// <offset> = 0
|
|
375
|
+
//
|
|
376
|
+
// callType
|
|
377
|
+
// v------v
|
|
378
|
+
// 0000000ncafecafecafecafecafecafecafecafecafecafe5a5a5a5af1f1f1f1
|
|
379
|
+
bytes4 allowedCallType = bytes4(allowedCall);
|
|
380
|
+
return (allowedCallType & requiredCallTypes == requiredCallTypes);
|
|
211
381
|
}
|
|
212
382
|
|
|
213
383
|
/**
|