diff --git a/src/MSAAdvanced.sol b/src/MSAAdvanced.sol index 3abfbca..7970c17 100644 --- a/src/MSAAdvanced.sol +++ b/src/MSAAdvanced.sol @@ -163,6 +163,8 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager { onlyEntryPointOrSelf withHook { + if (!IModule(module).isModuleType(moduleTypeId)) revert MismatchModuleTypeId(moduleTypeId); + if (moduleTypeId == MODULE_TYPE_VALIDATOR) _installValidator(module, initData); else if (moduleTypeId == MODULE_TYPE_EXECUTOR) _installExecutor(module, initData); else if (moduleTypeId == MODULE_TYPE_FALLBACK) _installFallbackHandler(module, initData); diff --git a/src/MSABasic.sol b/src/MSABasic.sol index 5896045..367f6bb 100644 --- a/src/MSABasic.sol +++ b/src/MSABasic.sol @@ -108,6 +108,8 @@ contract MSABasic is IMSA, ExecutionHelper, ModuleManager { payable onlyEntryPointOrSelf { + if (!IModule(module).isModuleType(moduleTypeId)) revert MismatchModuleTypeId(moduleTypeId); + if (moduleTypeId == MODULE_TYPE_VALIDATOR) _installValidator(module, initData); else if (moduleTypeId == MODULE_TYPE_EXECUTOR) _installExecutor(module, initData); else if (moduleTypeId == MODULE_TYPE_FALLBACK) _installFallbackHandler(module, initData); diff --git a/src/interfaces/IMSA.sol b/src/interfaces/IMSA.sol index efc9b75..5766cbd 100644 --- a/src/interfaces/IMSA.sol +++ b/src/interfaces/IMSA.sol @@ -15,6 +15,8 @@ interface IMSA is IERC7579Account, IERC4337Account { error UnsupportedExecType(ExecType execType); // Error thrown when account initialization fails error AccountInitializationFailed(); + // Error thrown when account installs/unistalls module with mismatched input `moduleTypeId` + error MismatchModuleTypeId(uint256 moduleTypeId); /** * @dev Initializes the account. Function might be called directly, or by a Factory diff --git a/test/mocks/MockFallback.sol b/test/mocks/MockFallback.sol index 8ddefa5..b1a2f08 100644 --- a/test/mocks/MockFallback.sol +++ b/test/mocks/MockFallback.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.23; -import { IFallback } from "src/interfaces/IERC7579Module.sol"; +import { IFallback, MODULE_TYPE_FALLBACK } from "src/interfaces/IERC7579Module.sol"; import { IERC7579Account, Execution } from "src/interfaces/IERC7579Account.sol"; import { ExecutionLib } from "src/lib/ExecutionLib.sol"; import { ModeLib } from "src/lib/ModeLib.sol"; @@ -65,7 +65,9 @@ contract MockFallback is IFallback { function onUninstall(bytes calldata data) external override { } - function isModuleType(uint256 typeID) external view override returns (bool) { } + function isModuleType(uint256 typeID) external view override returns (bool) { + return typeID == MODULE_TYPE_FALLBACK; + } function isInitialized(address smartAccount) external view override returns (bool) { } }