From f1456fc0d3792177f214f6bd9e57273f0e08a9b4 Mon Sep 17 00:00:00 2001 From: zeroknots Date: Wed, 21 Feb 2024 09:32:51 +0700 Subject: [PATCH] chore: cleanup --- accounts/safe7579/src/core/ModuleManager.sol | 21 +-- .../src/core/ValidatorStorageHelper.sol | 124 ------------------ 2 files changed, 1 insertion(+), 144 deletions(-) delete mode 100644 accounts/safe7579/src/core/ValidatorStorageHelper.sol diff --git a/accounts/safe7579/src/core/ModuleManager.sol b/accounts/safe7579/src/core/ModuleManager.sol index dc32a934..6553c48f 100644 --- a/accounts/safe7579/src/core/ModuleManager.sol +++ b/accounts/safe7579/src/core/ModuleManager.sol @@ -7,26 +7,14 @@ import { IModule, IExecutor, IValidator, IFallback } from "erc7579/interfaces/IE import { ExecutionHelper } from "./ExecutionHelper.sol"; import { Receiver } from "erc7579/core/Receiver.sol"; import { AccessControl } from "./AccessControl.sol"; -import { ISafe } from "../interfaces/ISafe.sol"; -import { - ValidatorStorageHelper, ValidatorStorageLib, $validator -} from "./ValidatorStorageHelper.sol"; struct ModuleManagerStorage { // linked list of executors. List is initialized by initializeAccount() SentinelListLib.SentinelList _executors; // single fallback handler for all fallbacks - // account vendors may implement this differently. This is just a reference implementation address fallbackHandler; } -// // keccak256("modulemanager.storage.msa"); -// bytes32 constant MODULEMANAGER_STORAGE_LOCATION = -// 0xf88ce1fdb7fb1cbd3282e49729100fa3f2d6ee9f797961fe4fb1871cea89ea02; -// -// // keccak256("modulemanager.validator.storage.msa") -// bytes32 constant VALIDATOR_STORAGE_LOCATION = -// 0x7ab08468dcbe2bcd9b34ba12d148d0310762840a62884f0cdee905ee43538c87; /** * @title ModuleManager * Contract that implements ERC7579 Module compatibility for Safe accounts @@ -42,7 +30,6 @@ abstract contract ModuleManager is AccessControl, Receiver, ExecutionHelper { error InitializerError(); error ValidatorStorageHelperError(); - ValidatorStorageHelper internal immutable VALIDATOR_STORAGE; mapping(address smartAccount => ModuleManagerStorage) private $moduleManager; @@ -73,9 +60,6 @@ abstract contract ModuleManager is AccessControl, Receiver, ExecutionHelper { //////////////////////////////////////////////////// /** * install and initialize validator module - * @dev this function Write into the Safe account storage (validator linked) list via - * ValidatorStorageHelper DELEGATECALL - * the onInstall call to the module(ERC7579), will be executed from the Safe */ function _installValidator(address validator, bytes memory data) internal virtual { $validators.push({ account: msg.sender, newEntry: validator }); @@ -92,8 +76,6 @@ abstract contract ModuleManager is AccessControl, Receiver, ExecutionHelper { /** * Uninstall and de-initialize validator module * @dev this function Write into the Safe account storage (validator linked) list via - * ValidatorStorageHelper DELEGATECALL - * the onUninstall call to the module (ERC7579), will be executed from the Safe */ function _uninstallValidator(address validator, bytes memory data) internal { (address prev, bytes memory disableModuleData) = abi.decode(data, (address, bytes)); @@ -176,11 +158,11 @@ abstract contract ModuleManager is AccessControl, Receiver, ExecutionHelper { SentinelListLib.SentinelList storage $executors = $moduleManager[msg.sender]._executors; return $executors.contains(executor); } + /** * THIS IS NOT PART OF THE STANDARD * Helper Function to access linked list */ - function getExecutorsPaginated( address cursor, uint256 size @@ -197,7 +179,6 @@ abstract contract ModuleManager is AccessControl, Receiver, ExecutionHelper { ///////////////////////////////////////////////////// // Manage Fallback //////////////////////////////////////////////////// - function _installFallbackHandler(address handler, bytes calldata initData) internal virtual { ModuleManagerStorage storage $mms = $moduleManager[msg.sender]; $mms.fallbackHandler = handler; diff --git a/accounts/safe7579/src/core/ValidatorStorageHelper.sol b/accounts/safe7579/src/core/ValidatorStorageHelper.sol deleted file mode 100644 index 5be8995a..00000000 --- a/accounts/safe7579/src/core/ValidatorStorageHelper.sol +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.23; - -import { SentinelListLib, SENTINEL } from "sentinellist/SentinelList.sol"; -import { IValidator } from "erc7579/interfaces/IERC7579Module.sol"; -import { ISafe } from "../interfaces/ISafe.sol"; - -struct ValidatorStorage { - // linked list of validators. List is initialized by initializeAccount() - SentinelListLib.SentinelList _validators; -} - -// keccak256("modulemanager.storage.msa"); -// TODO: change this -bytes32 constant VALIDATORMANAGER_STORAGE_LOCATION = - 0xf88ce1fdb7fb1cbd3282e49729100fa3f2d6ee9f797961fe4fb1871cea89ea02; - -function $validator() pure returns (ValidatorStorage storage $validators) { - bytes32 position = VALIDATORMANAGER_STORAGE_LOCATION; - // solhint-disable-next-line no-inline-assembly - assembly { - $validators.slot := position - } -} - -/** - * @title ValidatorStorage - Storage for ModuleManager - * Due to the storage restrictions of ERC4337, - * storing a linked list outside of the ERC-4337 UserOp.sender account is not possible - * In order to make storage of the linked list possible, the Safe account with DELEGATECALL - * the functions within ModuleStorage and thus write into its own storage. - * ModuleStorage is using MODULEMANAGER_STORAGE_LOCATION to store data, to ensure no storage slot - * conflicts - */ -contract ValidatorStorageHelper { - using SentinelListLib for SentinelListLib.SentinelList; - - error Unauthorized(); - - // Ensures that the functions are only interacted with via delegatecall - modifier onlyDelegateCall() { - // TODO: - // if (msg.sender != address(this)) revert Unauthorized(); - _; - } - - /** - * Initializes the module manager storage - * Due to the nature of SentinelListLib, - * a linked list first has to be initialized before it can be used - */ - function initModuleManager() external virtual onlyDelegateCall { - ValidatorStorage storage $v = $validator(); - $v._validators.init(); - } - ///////////////////////////////////////////////////// - // Manage Validators - //////////////////////////////////////////////////// - - /** - * Installs Validator to ModuleStorage - * @param validator address of ERC7579 Validator module - * @param data init data that will be passed to Validator Module - */ - function installValidator( - address validator, - bytes calldata data - ) - external - virtual - onlyDelegateCall - { - SentinelListLib.SentinelList storage $validators = $validator()._validators; - $validators.push(validator); - IValidator(validator).onInstall(data); - } - - /** - * Uninstalls Validator module from ModuleStorage - * @param validator address of ERC7579 Validator Module - * @param data deinitialization data that will be passed to the validator module - */ - function uninstallValidator(address validator, bytes calldata data) external onlyDelegateCall { - SentinelListLib.SentinelList storage _validators = $validator()._validators; - (address prev, bytes memory disableModuleData) = abi.decode(data, (address, bytes)); - _validators.pop(prev, validator); - IValidator(validator).onUninstall(disableModuleData); - } -} - -library ValidatorStorageLib { - using ValidatorStorageLib for SentinelListLib.SentinelList; - - function getSlot( - SentinelListLib.SentinelList storage linkedList, - address key - ) - internal - pure - returns (bytes32 hash) - { - bytes32 slot; - // solhint-disable-next-line no-inline-assembly - assembly { - slot := linkedList.slot - mstore(0, key) - mstore(0x20, slot) - hash := keccak256(0, 0x40) - } - } - - function getNextEntry( - SentinelListLib.SentinelList storage $validators, - address key - ) - internal - view - returns (address next) - { - bytes32 slot = $validators.getSlot(key); - bytes32 value = bytes32(ISafe(msg.sender).getStorageAt(uint256(slot), 1)); - next = address(uint160(uint256(value))); - } -}