From 0f4e8dcbc80cfae256c33e566954347d182bab89 Mon Sep 17 00:00:00 2001 From: G-Deps <65987352+G-Deps@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:54:18 -0300 Subject: [PATCH] Typo Typo on ModuleManager --- src/core/ModuleManager.sol | 192 +++++++++++++++++++++++-------------- 1 file changed, 120 insertions(+), 72 deletions(-) diff --git a/src/core/ModuleManager.sol b/src/core/ModuleManager.sol index 9580234..669ef89 100644 --- a/src/core/ModuleManager.sol +++ b/src/core/ModuleManager.sol @@ -1,11 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.21; -import { SentinelListLib, SENTINEL } from "sentinellist/SentinelList.sol"; -import { - CallType, CALLTYPE_SINGLE, CALLTYPE_DELEGATECALL, CALLTYPE_STATIC -} from "../lib/ModeLib.sol"; -import { AccountBase } from "./AccountBase.sol"; +import {SentinelListLib, SENTINEL} from "sentinellist/SentinelList.sol"; +import {CallType, CALLTYPE_SINGLE, CALLTYPE_DELEGATECALL, CALLTYPE_STATIC} from "../lib/ModeLib.sol"; +import {AccountBase} from "./AccountBase.sol"; import "../interfaces/IERC7579Module.sol"; import "forge-std/interfaces/IERC165.sol"; import "./Receiver.sol"; @@ -36,7 +34,7 @@ abstract contract ModuleManager is AccountBase, Receiver { /// @custom:storage-location erc7201:modulemanager.storage.msa struct ModuleManagerStorage { // linked list of validators. List is initialized by initializeAccount() - SentinelListLib.SentinelList $valdiators; + SentinelListLib.SentinelList $validators; // linked list of executors. List is initialized by initializeAccount() SentinelListLib.SentinelList $executors; // single fallback handler for all fallbacks @@ -44,7 +42,12 @@ abstract contract ModuleManager is AccountBase, Receiver { mapping(bytes4 selector => FallbackHandler fallbackHandler) $fallbacks; } - function $moduleManager() internal pure virtual returns (ModuleManagerStorage storage $ims) { + function $moduleManager() + internal + pure + virtual + returns (ModuleManagerStorage storage $ims) + { bytes32 position = MODULEMANAGER_STORAGE_LOCATION; assembly { $ims.slot := position @@ -52,48 +55,64 @@ abstract contract ModuleManager is AccountBase, Receiver { } modifier onlyExecutorModule() { - SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; + SentinelListLib.SentinelList storage $executors = $moduleManager() + .$executors; if (!$executors.contains(msg.sender)) revert InvalidModule(msg.sender); _; } modifier onlyValidatorModule(address validator) { - SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; - if (!$valdiators.contains(validator)) revert InvalidModule(validator); + SentinelListLib.SentinelList storage $validators = $moduleManager() + .$validators; + if (!$validators.contains(validator)) revert InvalidModule(validator); _; } function _initModuleManager() internal virtual { ModuleManagerStorage storage $ims = $moduleManager(); $ims.$executors.init(); - $ims.$valdiators.init(); + $ims.$validators.init(); } function isAlreadyInitialized() internal view virtual returns (bool) { ModuleManagerStorage storage $ims = $moduleManager(); - return $ims.$valdiators.alreadyInitialized(); + return $ims.$validators.alreadyInitialized(); } ///////////////////////////////////////////////////// // Manage Validators //////////////////////////////////////////////////// - function _installValidator(address validator, bytes calldata data) internal virtual { - SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; - $valdiators.push(validator); + function _installValidator( + address validator, + bytes calldata data + ) internal virtual { + SentinelListLib.SentinelList storage $validators = $moduleManager() + .$validators; + $validators.push(validator); IValidator(validator).onInstall(data); } - function _uninstallValidator(address validator, bytes calldata data) internal { + function _uninstallValidator( + address validator, + bytes calldata data + ) internal { // TODO: check if its the last validator. this might brick the account - SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; - (address prev, bytes memory disableModuleData) = abi.decode(data, (address, bytes)); - $valdiators.pop(prev, validator); + SentinelListLib.SentinelList storage $validators = $moduleManager() + .$validators; + (address prev, bytes memory disableModuleData) = abi.decode( + data, + (address, bytes) + ); + $validators.pop(prev, validator); IValidator(validator).onUninstall(disableModuleData); } - function _isValidatorInstalled(address validator) internal view virtual returns (bool) { - SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; - return $valdiators.contains(validator); + function _isValidatorInstalled( + address validator + ) internal view virtual returns (bool) { + SentinelListLib.SentinelList storage $validators = $moduleManager() + .$validators; + return $validators.contains(validator); } /** @@ -103,14 +122,10 @@ abstract contract ModuleManager is AccountBase, Receiver { function getValidatorsPaginated( address cursor, uint256 size - ) - external - view - virtual - returns (address[] memory array, address next) - { - SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; - return $valdiators.getEntriesPaginated(cursor, size); + ) external view virtual returns (address[] memory array, address next) { + SentinelListLib.SentinelList storage $validators = $moduleManager() + .$validators; + return $validators.getEntriesPaginated(cursor, size); } ///////////////////////////////////////////////////// @@ -118,20 +133,31 @@ abstract contract ModuleManager is AccountBase, Receiver { //////////////////////////////////////////////////// function _installExecutor(address executor, bytes calldata data) internal { - SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; + SentinelListLib.SentinelList storage $executors = $moduleManager() + .$executors; $executors.push(executor); IExecutor(executor).onInstall(data); } - function _uninstallExecutor(address executor, bytes calldata data) internal { - SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; - (address prev, bytes memory disableModuleData) = abi.decode(data, (address, bytes)); + function _uninstallExecutor( + address executor, + bytes calldata data + ) internal { + SentinelListLib.SentinelList storage $executors = $moduleManager() + .$executors; + (address prev, bytes memory disableModuleData) = abi.decode( + data, + (address, bytes) + ); $executors.pop(prev, executor); IExecutor(executor).onUninstall(disableModuleData); } - function _isExecutorInstalled(address executor) internal view virtual returns (bool) { - SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; + function _isExecutorInstalled( + address executor + ) internal view virtual returns (bool) { + SentinelListLib.SentinelList storage $executors = $moduleManager() + .$executors; return $executors.contains(executor); } @@ -142,13 +168,9 @@ abstract contract ModuleManager is AccountBase, Receiver { function getExecutorsPaginated( address cursor, uint256 size - ) - external - view - virtual - returns (address[] memory array, address next) - { - SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; + ) external view virtual returns (address[] memory array, address next) { + SentinelListLib.SentinelList storage $executors = $moduleManager() + .$executors; return $executors.getEntriesPaginated(cursor, size); } @@ -156,7 +178,10 @@ abstract contract ModuleManager is AccountBase, Receiver { // Manage Fallback //////////////////////////////////////////////////// - function _installFallbackHandler(address handler, bytes calldata params) internal virtual { + function _installFallbackHandler( + address handler, + bytes calldata params + ) internal virtual { bytes4 selector = bytes4(params[0:4]); CallType calltype = CallType.wrap(bytes1(params[4])); bytes memory initData = params[5:]; @@ -164,17 +189,17 @@ abstract contract ModuleManager is AccountBase, Receiver { if (_isFallbackHandlerInstalled(selector)) { revert("Function selector already used"); } - $moduleManager().$fallbacks[selector] = FallbackHandler(handler, calltype); + $moduleManager().$fallbacks[selector] = FallbackHandler( + handler, + calltype + ); IFallback(handler).onInstall(initData); } function _uninstallFallbackHandler( address handler, bytes calldata deInitData - ) - internal - virtual - { + ) internal virtual { bytes4 selector = bytes4(deInitData[0:4]); bytes memory _deInitData = deInitData[4:]; @@ -182,7 +207,9 @@ abstract contract ModuleManager is AccountBase, Receiver { revert("Function selector not used"); } - FallbackHandler memory activeFallback = $moduleManager().$fallbacks[selector]; + FallbackHandler memory activeFallback = $moduleManager().$fallbacks[ + selector + ]; if (activeFallback.handler != handler) { revert("Function selector not used by this handler"); @@ -190,41 +217,44 @@ abstract contract ModuleManager is AccountBase, Receiver { CallType callType = activeFallback.calltype; - $moduleManager().$fallbacks[selector] = FallbackHandler(address(0), CallType.wrap(0x00)); + $moduleManager().$fallbacks[selector] = FallbackHandler( + address(0), + CallType.wrap(0x00) + ); IFallback(handler).onUninstall(_deInitData); } - function _isFallbackHandlerInstalled(bytes4 functionSig) internal view virtual returns (bool) { - FallbackHandler storage $fallback = $moduleManager().$fallbacks[functionSig]; + function _isFallbackHandlerInstalled( + bytes4 functionSig + ) internal view virtual returns (bool) { + FallbackHandler storage $fallback = $moduleManager().$fallbacks[ + functionSig + ]; return $fallback.handler != address(0); } function _isFallbackHandlerInstalled( bytes4 functionSig, address _handler - ) - internal - view - virtual - returns (bool) - { - FallbackHandler storage $fallback = $moduleManager().$fallbacks[functionSig]; + ) internal view virtual returns (bool) { + FallbackHandler storage $fallback = $moduleManager().$fallbacks[ + functionSig + ]; return $fallback.handler == _handler; } - function getActiveFallbackHandler(bytes4 functionSig) - external - view - virtual - returns (FallbackHandler memory) - { + function getActiveFallbackHandler( + bytes4 functionSig + ) external view virtual returns (FallbackHandler memory) { return $moduleManager().$fallbacks[functionSig]; } // FALLBACK fallback() external payable override(Receiver) receiverFallback { - FallbackHandler storage $fallbackHandler = $moduleManager().$fallbacks[msg.sig]; + FallbackHandler storage $fallbackHandler = $moduleManager().$fallbacks[ + msg.sig + ]; address handler = $fallbackHandler.handler; CallType calltype = $fallbackHandler.calltype; if (handler == address(0)) revert NoFallbackHandler(msg.sig); @@ -245,12 +275,20 @@ abstract contract ModuleManager is AccountBase, Receiver { mstore(senderPtr, shl(96, caller())) // Add 20 bytes for the address appended add the end - let success := - staticcall(gas(), handler, calldataPtr, add(calldatasize(), 20), 0, 0) + let success := staticcall( + gas(), + handler, + calldataPtr, + add(calldatasize(), 20), + 0, + 0 + ) let returnDataPtr := allocate(returndatasize()) returndatacopy(returnDataPtr, 0, returndatasize()) - if iszero(success) { revert(returnDataPtr, returndatasize()) } + if iszero(success) { + revert(returnDataPtr, returndatasize()) + } return(returnDataPtr, returndatasize()) } } @@ -270,11 +308,21 @@ abstract contract ModuleManager is AccountBase, Receiver { mstore(senderPtr, shl(96, caller())) // Add 20 bytes for the address appended add the end - let success := call(gas(), handler, 0, calldataPtr, add(calldatasize(), 20), 0, 0) + let success := call( + gas(), + handler, + 0, + calldataPtr, + add(calldatasize(), 20), + 0, + 0 + ) let returnDataPtr := allocate(returndatasize()) returndatacopy(returnDataPtr, 0, returndatasize()) - if iszero(success) { revert(returnDataPtr, returndatasize()) } + if iszero(success) { + revert(returnDataPtr, returndatasize()) + } return(returnDataPtr, returndatasize()) } }