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