Skip to content

Commit

Permalink
feat: prototype for ERC 165
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed May 14, 2024
1 parent e043cee commit f784e43
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
libs = ["node_modules"]
fs_permissions = [{ access = "read", path = "out-optimized" }]
allow_paths = ["*", "/"]

Expand Down
2 changes: 1 addition & 1 deletion src/MSAAdvanced.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
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);
Expand Down
5 changes: 5 additions & 0 deletions src/core/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract contract ModuleManager is AccountBase, Receiver {
error InvalidModule(address module);
error NoFallbackHandler(bytes4 selector);
error CannotRemoveLastValidator();
error UnsupportedValidationMethod();

// keccak256("modulemanager.storage.msa");
bytes32 internal constant MODULEMANAGER_STORAGE_LOCATION =
Expand Down Expand Up @@ -80,6 +81,10 @@ abstract contract ModuleManager is AccountBase, Receiver {
function _installValidator(address validator, bytes calldata data) internal virtual {
SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators;
$valdiators.push(validator);
bool supportsEPv07 =
IERC165(validator).supportsInterface(IValidator.validateUserOp.selector);
if (!supportsEPv07) revert UnsupportedValidationMethod();

IValidator(validator).onInstall(data);
}

Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/IERC7579Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.21;

import { PackedUserOperation } from "account-abstraction/interfaces/PackedUserOperation.sol";
import "forge-std/interfaces/IERC165.sol";

uint256 constant VALIDATION_SUCCESS = 0;
uint256 constant VALIDATION_FAILED = 1;
Expand Down Expand Up @@ -47,7 +48,7 @@ interface IModule {
function isInitialized(address smartAccount) external view returns (bool);
}

interface IValidator is IModule {
interface IValidator is IERC165, IModule {
error InvalidTargetAddress(address target);

/**
Expand Down
12 changes: 12 additions & 0 deletions src/modules/SimpleExecutionValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ contract SimpleExecutionValidator is IValidator {
override
returns (bytes4)
{ }

function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
if (interfaceId == type(IERC165).interfaceId) {
return true;
}
if (interfaceId == type(IValidator).interfaceId) {
return true;
}
if (interfaceId == IValidator.validateUserOp.selector) {
return true;
}
}
}
2 changes: 1 addition & 1 deletion test/advanced/MSAAdvanced.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract MSAAdvancedTest is TestBaseUtilAdvanced {
(
ModeLib.encode(
CALLTYPE_DELEGATECALL, EXECTYPE_DEFAULT, MODE_DEFAULT, ModePayload.wrap(0x00)
),
),
abi.encodePacked(address(delegateTarget), sendValue)
)
);
Expand Down
18 changes: 18 additions & 0 deletions test/mocks/MockValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
MODULE_TYPE_VALIDATOR
} from "src/interfaces/IERC7579Module.sol";

import "forge-std/interfaces/IERC165.sol";

contract MockValidator is IValidator {
function onInstall(bytes calldata data) external override { }

Expand Down Expand Up @@ -46,4 +48,20 @@ contract MockValidator is IValidator {
function isInitialized(address smartAccount) external view returns (bool) {
return false;
}

function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
if (interfaceId == type(IERC165).interfaceId) {
return true;
}
if (interfaceId == type(IValidator).interfaceId) {
return true;
}
if (interfaceId == IValidator.validateUserOp.selector) {
return true;
}

if (interfaceId == IValidator.isValidSignatureWithSender.selector) {
return true;
}
}
}

0 comments on commit f784e43

Please sign in to comment.