@erc6900/reference-implementation 0.8.1 → 1.0.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.
Potentially problematic release.
This version of @erc6900/reference-implementation might be problematic. Click here for more details.
- package/package.json +5 -26
- package/preinstall.js +110 -0
- package/LICENSE +0 -21
- package/README.md +0 -76
- package/src/account/AccountExecutor.sol +0 -20
- package/src/account/AccountFactory.sol +0 -126
- package/src/account/AccountStorage.sol +0 -99
- package/src/account/AccountStorageInitializable.sol +0 -67
- package/src/account/ModularAccountView.sol +0 -66
- package/src/account/ModuleManagerInternals.sol +0 -325
- package/src/account/ReferenceModularAccount.sol +0 -769
- package/src/account/SemiModularAccount.sol +0 -214
- package/src/account/SemiModularAccount7702.sol +0 -38
- package/src/helpers/CollectReturnData.sol +0 -14
- package/src/helpers/Constants.sol +0 -11
- package/src/helpers/EmptyCalldataSlice.sol +0 -12
- package/src/helpers/ValidationResHelpers.sol +0 -50
- package/src/interfaces/IERC6900Account.sol +0 -127
- package/src/interfaces/IERC6900AccountView.sol +0 -52
- package/src/interfaces/IERC6900ExecutionHookModule.sol +0 -26
- package/src/interfaces/IERC6900ExecutionModule.sol +0 -37
- package/src/interfaces/IERC6900Module.sol +0 -24
- package/src/interfaces/IERC6900ValidationHookModule.sol +0 -46
- package/src/interfaces/IERC6900ValidationModule.sol +0 -53
- package/src/libraries/HookConfigLib.sol +0 -135
- package/src/libraries/KnownSelectorsLib.sol +0 -65
- package/src/libraries/ModuleEntityLib.sol +0 -37
- package/src/libraries/ModuleStorageLib.sol +0 -62
- package/src/libraries/SparseCalldataSegmentLib.sol +0 -95
- package/src/libraries/ValidationConfigLib.sol +0 -119
- package/src/modules/BaseModule.sol +0 -54
- package/src/modules/ModuleEIP712.sol +0 -29
- package/src/modules/ReplaySafeWrapper.sol +0 -38
- package/src/modules/TokenReceiverModule.sol +0 -87
- package/src/modules/permissions/AllowlistModule.sol +0 -156
- package/src/modules/permissions/ERC20TokenLimitModule.sol +0 -145
- package/src/modules/permissions/NativeTokenLimitModule.sol +0 -154
- package/src/modules/validation/ISingleSignerValidationModule.sol +0 -22
- package/src/modules/validation/SingleSignerValidationModule.sol +0 -138
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.20;
|
|
3
|
-
|
|
4
|
-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
5
|
-
|
|
6
|
-
import {collectReturnData} from "../helpers/CollectReturnData.sol";
|
|
7
|
-
import {MAX_VALIDATION_ASSOC_HOOKS} from "../helpers/Constants.sol";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
HookConfig,
|
|
11
|
-
IERC6900Account,
|
|
12
|
-
ModuleEntity,
|
|
13
|
-
ValidationConfig,
|
|
14
|
-
ValidationFlags
|
|
15
|
-
} from "../interfaces/IERC6900Account.sol";
|
|
16
|
-
|
|
17
|
-
import {ExecutionManifest, ManifestExecutionHook} from "../interfaces/IERC6900ExecutionModule.sol";
|
|
18
|
-
import {IERC6900Module} from "../interfaces/IERC6900Module.sol";
|
|
19
|
-
import {HookConfigLib} from "../libraries/HookConfigLib.sol";
|
|
20
|
-
import {KnownSelectorsLib} from "../libraries/KnownSelectorsLib.sol";
|
|
21
|
-
import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol";
|
|
22
|
-
import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol";
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
AccountStorage,
|
|
26
|
-
ExecutionStorage,
|
|
27
|
-
ValidationStorage,
|
|
28
|
-
getAccountStorage,
|
|
29
|
-
toModuleEntity,
|
|
30
|
-
toSetValue
|
|
31
|
-
} from "./AccountStorage.sol";
|
|
32
|
-
|
|
33
|
-
abstract contract ModuleManagerInternals is IERC6900Account {
|
|
34
|
-
using EnumerableSet for EnumerableSet.Bytes32Set;
|
|
35
|
-
using ModuleEntityLib for ModuleEntity;
|
|
36
|
-
using ValidationConfigLib for ValidationConfig;
|
|
37
|
-
using HookConfigLib for HookConfig;
|
|
38
|
-
|
|
39
|
-
error ArrayLengthMismatch();
|
|
40
|
-
error Erc4337FunctionNotAllowed(bytes4 selector);
|
|
41
|
-
error ExecutionFunctionAlreadySet(bytes4 selector);
|
|
42
|
-
error IModuleFunctionNotAllowed(bytes4 selector);
|
|
43
|
-
error InterfaceNotSupported(address module);
|
|
44
|
-
error NativeFunctionNotAllowed(bytes4 selector);
|
|
45
|
-
error NullModule();
|
|
46
|
-
error ExecutionHookAlreadySet(HookConfig hookConfig);
|
|
47
|
-
error ModuleInstallCallbackFailed(address module, bytes revertReason);
|
|
48
|
-
error ModuleNotInstalled(address module);
|
|
49
|
-
error PreValidationHookLimitExceeded();
|
|
50
|
-
error ValidationAlreadySet(bytes4 selector, ModuleEntity validationFunction);
|
|
51
|
-
|
|
52
|
-
// Storage update operations
|
|
53
|
-
|
|
54
|
-
function _setExecutionFunction(
|
|
55
|
-
bytes4 selector,
|
|
56
|
-
bool skipRuntimeValidation,
|
|
57
|
-
bool allowGlobalValidation,
|
|
58
|
-
address module
|
|
59
|
-
) internal {
|
|
60
|
-
ExecutionStorage storage _executionStorage = getAccountStorage().executionStorage[selector];
|
|
61
|
-
|
|
62
|
-
if (_executionStorage.module != address(0)) {
|
|
63
|
-
revert ExecutionFunctionAlreadySet(selector);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Make sure incoming execution function does not collide with any native functions (data are stored on the
|
|
67
|
-
// account implementation contract)
|
|
68
|
-
if (KnownSelectorsLib.isNativeFunction(selector)) {
|
|
69
|
-
revert NativeFunctionNotAllowed(selector);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Make sure incoming execution function is not a function in IERC6900Module
|
|
73
|
-
if (KnownSelectorsLib.isIModuleFunction(selector)) {
|
|
74
|
-
revert IModuleFunctionNotAllowed(selector);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Also make sure it doesn't collide with functions defined by ERC-4337
|
|
78
|
-
// and called by the entry point. This prevents a malicious module from
|
|
79
|
-
// sneaking in a function with the same selector as e.g.
|
|
80
|
-
// `validatePaymasterUserOp` and turning the account into their own
|
|
81
|
-
// personal paymaster.
|
|
82
|
-
if (KnownSelectorsLib.isErc4337Function(selector)) {
|
|
83
|
-
revert Erc4337FunctionNotAllowed(selector);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_executionStorage.module = module;
|
|
87
|
-
_executionStorage.skipRuntimeValidation = skipRuntimeValidation;
|
|
88
|
-
_executionStorage.allowGlobalValidation = allowGlobalValidation;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function _removeExecutionFunction(bytes4 selector) internal {
|
|
92
|
-
ExecutionStorage storage _executionStorage = getAccountStorage().executionStorage[selector];
|
|
93
|
-
|
|
94
|
-
_executionStorage.module = address(0);
|
|
95
|
-
_executionStorage.skipRuntimeValidation = false;
|
|
96
|
-
_executionStorage.allowGlobalValidation = false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function _removeValidationFunction(ModuleEntity validationFunction) internal {
|
|
100
|
-
ValidationStorage storage _validationStorage = getAccountStorage().validationStorage[validationFunction];
|
|
101
|
-
_validationStorage.validationFlags = ValidationFlags.wrap(0);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function _addExecHooks(EnumerableSet.Bytes32Set storage hooks, HookConfig hookConfig) internal {
|
|
105
|
-
if (!hooks.add(toSetValue(hookConfig))) {
|
|
106
|
-
revert ExecutionHookAlreadySet(hookConfig);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function _removeExecHooks(EnumerableSet.Bytes32Set storage hooks, HookConfig hookConfig) internal {
|
|
111
|
-
hooks.remove(toSetValue(hookConfig));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _installExecution(
|
|
115
|
-
address module,
|
|
116
|
-
ExecutionManifest calldata manifest,
|
|
117
|
-
bytes calldata moduleInstallData
|
|
118
|
-
) internal {
|
|
119
|
-
AccountStorage storage _storage = getAccountStorage();
|
|
120
|
-
|
|
121
|
-
if (module == address(0)) {
|
|
122
|
-
revert NullModule();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Update components according to the manifest.
|
|
126
|
-
uint256 length = manifest.executionFunctions.length;
|
|
127
|
-
for (uint256 i = 0; i < length; ++i) {
|
|
128
|
-
bytes4 selector = manifest.executionFunctions[i].executionSelector;
|
|
129
|
-
bool skipRuntimeValidation = manifest.executionFunctions[i].skipRuntimeValidation;
|
|
130
|
-
bool allowGlobalValidation = manifest.executionFunctions[i].allowGlobalValidation;
|
|
131
|
-
_setExecutionFunction(selector, skipRuntimeValidation, allowGlobalValidation, module);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
length = manifest.executionHooks.length;
|
|
135
|
-
for (uint256 i = 0; i < length; ++i) {
|
|
136
|
-
ManifestExecutionHook memory mh = manifest.executionHooks[i];
|
|
137
|
-
EnumerableSet.Bytes32Set storage execHooks =
|
|
138
|
-
_storage.executionStorage[mh.executionSelector].executionHooks;
|
|
139
|
-
HookConfig hookConfig = HookConfigLib.packExecHook({
|
|
140
|
-
_module: module,
|
|
141
|
-
_entityId: mh.entityId,
|
|
142
|
-
_hasPre: mh.isPreHook,
|
|
143
|
-
_hasPost: mh.isPostHook
|
|
144
|
-
});
|
|
145
|
-
_addExecHooks(execHooks, hookConfig);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
length = manifest.interfaceIds.length;
|
|
149
|
-
for (uint256 i = 0; i < length; ++i) {
|
|
150
|
-
_storage.supportedIfaces[manifest.interfaceIds[i]] += 1;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
_onInstall(module, moduleInstallData);
|
|
154
|
-
|
|
155
|
-
emit ExecutionInstalled(module, manifest);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function _uninstallExecution(address module, ExecutionManifest calldata manifest, bytes calldata uninstallData)
|
|
159
|
-
internal
|
|
160
|
-
{
|
|
161
|
-
AccountStorage storage _storage = getAccountStorage();
|
|
162
|
-
|
|
163
|
-
// Remove components according to the manifest, in reverse order (by component type) of their installation.
|
|
164
|
-
|
|
165
|
-
uint256 length = manifest.executionHooks.length;
|
|
166
|
-
for (uint256 i = 0; i < length; ++i) {
|
|
167
|
-
ManifestExecutionHook memory mh = manifest.executionHooks[i];
|
|
168
|
-
EnumerableSet.Bytes32Set storage execHooks =
|
|
169
|
-
_storage.executionStorage[mh.executionSelector].executionHooks;
|
|
170
|
-
HookConfig hookConfig = HookConfigLib.packExecHook({
|
|
171
|
-
_module: module,
|
|
172
|
-
_entityId: mh.entityId,
|
|
173
|
-
_hasPre: mh.isPreHook,
|
|
174
|
-
_hasPost: mh.isPostHook
|
|
175
|
-
});
|
|
176
|
-
_removeExecHooks(execHooks, hookConfig);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
length = manifest.executionFunctions.length;
|
|
180
|
-
for (uint256 i = 0; i < length; ++i) {
|
|
181
|
-
bytes4 selector = manifest.executionFunctions[i].executionSelector;
|
|
182
|
-
_removeExecutionFunction(selector);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
length = manifest.interfaceIds.length;
|
|
186
|
-
for (uint256 i = 0; i < length; ++i) {
|
|
187
|
-
_storage.supportedIfaces[manifest.interfaceIds[i]] -= 1;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Clear the module storage for the account.
|
|
191
|
-
bool onUninstallSuccess = _onUninstall(module, uninstallData);
|
|
192
|
-
|
|
193
|
-
emit ExecutionUninstalled(module, onUninstallSuccess, manifest);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function _onInstall(address module, bytes calldata data) internal {
|
|
197
|
-
if (data.length > 0) {
|
|
198
|
-
// solhint-disable-next-line no-empty-blocks
|
|
199
|
-
try IERC6900Module(module).onInstall(data) {}
|
|
200
|
-
catch {
|
|
201
|
-
bytes memory revertReason = collectReturnData();
|
|
202
|
-
revert ModuleInstallCallbackFailed(module, revertReason);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function _onUninstall(address module, bytes calldata data) internal returns (bool onUninstallSuccess) {
|
|
208
|
-
onUninstallSuccess = true;
|
|
209
|
-
if (data.length > 0) {
|
|
210
|
-
// Clear the module storage for the account.
|
|
211
|
-
// solhint-disable-next-line no-empty-blocks
|
|
212
|
-
try IERC6900Module(module).onUninstall(data) {}
|
|
213
|
-
catch {
|
|
214
|
-
onUninstallSuccess = false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function _installValidation(
|
|
220
|
-
ValidationConfig validationConfig,
|
|
221
|
-
bytes4[] calldata selectors,
|
|
222
|
-
bytes calldata installData,
|
|
223
|
-
bytes[] calldata hooks
|
|
224
|
-
) internal {
|
|
225
|
-
ValidationStorage storage _validationStorage =
|
|
226
|
-
getAccountStorage().validationStorage[validationConfig.moduleEntity()];
|
|
227
|
-
(ModuleEntity moduleEntity, ValidationFlags validationFlags) = validationConfig.unpack();
|
|
228
|
-
|
|
229
|
-
for (uint256 i = 0; i < hooks.length; ++i) {
|
|
230
|
-
HookConfig hookConfig = HookConfig.wrap(bytes25(hooks[i][:25]));
|
|
231
|
-
bytes calldata hookData = hooks[i][25:];
|
|
232
|
-
|
|
233
|
-
if (hookConfig.isValidationHook()) {
|
|
234
|
-
_validationStorage.validationHooks.push(hookConfig);
|
|
235
|
-
|
|
236
|
-
// Avoid collision between reserved index and actual indices
|
|
237
|
-
if (_validationStorage.validationHooks.length > MAX_VALIDATION_ASSOC_HOOKS) {
|
|
238
|
-
revert PreValidationHookLimitExceeded();
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
_onInstall(hookConfig.module(), hookData);
|
|
242
|
-
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
// Hook is an execution hook
|
|
246
|
-
_addExecHooks(_validationStorage.executionHooks, hookConfig);
|
|
247
|
-
|
|
248
|
-
_onInstall(hookConfig.module(), hookData);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
for (uint256 i = 0; i < selectors.length; ++i) {
|
|
252
|
-
bytes4 selector = selectors[i];
|
|
253
|
-
if (!_validationStorage.selectors.add(toSetValue(selector))) {
|
|
254
|
-
revert ValidationAlreadySet(selector, moduleEntity);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
_validationStorage.validationFlags = validationFlags;
|
|
259
|
-
|
|
260
|
-
_onInstall(validationConfig.module(), installData);
|
|
261
|
-
emit ValidationInstalled(validationConfig.module(), validationConfig.entityId());
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function _uninstallValidation(
|
|
265
|
-
ModuleEntity validationFunction,
|
|
266
|
-
bytes calldata uninstallData,
|
|
267
|
-
bytes[] calldata hookUninstallDatas
|
|
268
|
-
) internal {
|
|
269
|
-
ValidationStorage storage _validationStorage = getAccountStorage().validationStorage[validationFunction];
|
|
270
|
-
bool onUninstallSuccess = true;
|
|
271
|
-
|
|
272
|
-
_removeValidationFunction(validationFunction);
|
|
273
|
-
|
|
274
|
-
// Send `onUninstall` to hooks
|
|
275
|
-
if (hookUninstallDatas.length > 0) {
|
|
276
|
-
// If any uninstall data is provided, assert it is of the correct length.
|
|
277
|
-
if (
|
|
278
|
-
hookUninstallDatas.length
|
|
279
|
-
!= _validationStorage.validationHooks.length + _validationStorage.executionHooks.length()
|
|
280
|
-
) {
|
|
281
|
-
revert ArrayLengthMismatch();
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Hook uninstall data is provided in the order of pre validation hooks, then execution hooks.
|
|
285
|
-
uint256 hookIndex = 0;
|
|
286
|
-
for (uint256 i = 0; i < _validationStorage.validationHooks.length; ++i) {
|
|
287
|
-
bytes calldata hookData = hookUninstallDatas[hookIndex];
|
|
288
|
-
(address hookModule,) =
|
|
289
|
-
ModuleEntityLib.unpack(_validationStorage.validationHooks[i].moduleEntity());
|
|
290
|
-
onUninstallSuccess = onUninstallSuccess && _onUninstall(hookModule, hookData);
|
|
291
|
-
hookIndex++;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
for (uint256 i = 0; i < _validationStorage.executionHooks.length(); ++i) {
|
|
295
|
-
bytes calldata hookData = hookUninstallDatas[hookIndex];
|
|
296
|
-
(address hookModule,) =
|
|
297
|
-
ModuleEntityLib.unpack(toModuleEntity(_validationStorage.executionHooks.at(i)));
|
|
298
|
-
onUninstallSuccess = onUninstallSuccess && _onUninstall(hookModule, hookData);
|
|
299
|
-
hookIndex++;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Clear all stored hooks
|
|
304
|
-
delete _validationStorage.validationHooks;
|
|
305
|
-
|
|
306
|
-
EnumerableSet.Bytes32Set storage executionHooks = _validationStorage.executionHooks;
|
|
307
|
-
uint256 executionHookLen = executionHooks.length();
|
|
308
|
-
for (uint256 i = 0; i < executionHookLen; ++i) {
|
|
309
|
-
bytes32 executionHook = executionHooks.at(0);
|
|
310
|
-
executionHooks.remove(executionHook);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// Clear selectors
|
|
314
|
-
uint256 selectorLen = _validationStorage.selectors.length();
|
|
315
|
-
for (uint256 i = 0; i < selectorLen; ++i) {
|
|
316
|
-
bytes32 selectorSetValue = _validationStorage.selectors.at(0);
|
|
317
|
-
_validationStorage.selectors.remove(selectorSetValue);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
(address module, uint32 entityId) = ModuleEntityLib.unpack(validationFunction);
|
|
321
|
-
onUninstallSuccess = onUninstallSuccess && _onUninstall(module, uninstallData);
|
|
322
|
-
|
|
323
|
-
emit ValidationUninstalled(module, entityId, onUninstallSuccess);
|
|
324
|
-
}
|
|
325
|
-
}
|