Skip to content

Commit

Permalink
refactor: remove NativeFunctionDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik committed Nov 25, 2024
1 parent 5fe65eb commit 61ee983
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/account/ModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract ModularAccount is ModularAccountBase {
}

/// @dev Overrides ModularAccountView.
function _isNativeFunction(uint32 selector) internal view override returns (bool) {
function _isNativeFunction(uint32 selector) internal pure override returns (bool) {
return super._isNativeFunction(selector) || selector == uint32(this.initializeWithValidation.selector);
}
}
45 changes: 28 additions & 17 deletions src/account/ModularAccountView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@ import {
ValidationDataView
} from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol";
import {IAccountExecute} from "@eth-infinitism/account-abstraction/interfaces/IAccountExecute.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import {NativeFunctionDelegate} from "../helpers/NativeFunctionDelegate.sol";
import {IModularAccountBase} from "../interfaces/IModularAccountBase.sol";
import {MemManagementLib} from "../libraries/MemManagementLib.sol";
import {ValidationLocatorLib} from "../libraries/ValidationLocatorLib.sol";
import {AccountBase} from "./AccountBase.sol";
import {ExecutionStorage, ValidationStorage, getAccountStorage} from "./AccountStorage.sol";

/// @title Modular Account View
/// @author Alchemy
/// @notice This abstract contract implements the two view functions to get validation and execution data for an
/// account.
abstract contract ModularAccountView is IModularAccountView {
NativeFunctionDelegate internal immutable _NATIVE_FUNCTION_DELEGATE;

constructor() {
_NATIVE_FUNCTION_DELEGATE = new NativeFunctionDelegate();
}

/// @inheritdoc IModularAccountView
function getExecutionData(bytes4 selector) external view override returns (ExecutionDataView memory data) {
ExecutionStorage storage executionStorage = getAccountStorage().executionStorage[selector];
Expand Down Expand Up @@ -80,8 +78,29 @@ abstract contract ModularAccountView is IModularAccountView {
data.selectors = selectors;
}

function _isNativeFunction(uint32 selector) internal view virtual returns (bool) {
return _NATIVE_FUNCTION_DELEGATE.isNativeFunction(selector);
function _isNativeFunction(uint32 selector) internal pure virtual returns (bool) {
return (
_isGlobalValidationAllowedNativeFunction(selector)
|| selector == uint32(AccountBase.entryPoint.selector)
|| selector == uint32(AccountBase.validateUserOp.selector)
|| selector == uint32(IERC1155Receiver.onERC1155BatchReceived.selector)
|| selector == uint32(IERC1155Receiver.onERC1155Received.selector)
|| selector == uint32(IERC1271.isValidSignature.selector)
|| selector == uint32(IERC165.supportsInterface.selector)
|| selector == uint32(IERC721Receiver.onERC721Received.selector)
|| selector == uint32(IModularAccount.accountId.selector)
|| selector == uint32(IModularAccountView.getExecutionData.selector)
|| selector == uint32(IModularAccountView.getValidationData.selector)
|| selector == uint32(UUPSUpgradeable.proxiableUUID.selector)
);
}

/// @dev Check whether a function is a native function that allows global validation.
function _isGlobalValidationAllowedNativeFunction(uint32 selector) internal pure virtual returns (bool) {
return (
_isWrappedNativeFunction(selector) || selector == uint32(IAccountExecute.executeUserOp.selector)
|| selector == uint32(IModularAccount.executeWithRuntimeValidation.selector)
);
}

/// @dev Check whether a function is a native function that has the `wrapNativeFunction` modifier applied,
Expand All @@ -98,12 +117,4 @@ abstract contract ModularAccountView is IModularAccountView {
|| selector == uint32(UUPSUpgradeable.upgradeToAndCall.selector)
);
}

/// @dev Check whether a function is a native function that allows global validation.
function _isGlobalValidationAllowedNativeFunction(uint32 selector) internal pure virtual returns (bool) {
return (
_isWrappedNativeFunction(selector) || selector == uint32(IAccountExecute.executeUserOp.selector)
|| selector == uint32(IModularAccount.executeWithRuntimeValidation.selector)
);
}
}
12 changes: 6 additions & 6 deletions src/account/SemiModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,6 @@ abstract contract SemiModularAccountBase is ModularAccountBase {
return _storage.fallbackSigner;
}

/// @dev Overrides ModularAccountView.
function _isNativeFunction(uint32 selector) internal view virtual override returns (bool) {
return super._isNativeFunction(selector) || selector == uint32(this.updateFallbackSignerData.selector)
|| selector == uint32(this.getFallbackSignerData.selector);
}

/// @notice Returns the replay-safe hash generated from the passed typed data hash for 1271 validation.
/// @param hash The typed data hash to wrap in a replay-safe hash.
/// @return The replay-safe hash, to be used for 1271 signature generation.
Expand Down Expand Up @@ -273,6 +267,12 @@ abstract contract SemiModularAccountBase is ModularAccountBase {
return res;
}

/// @dev Overrides ModularAccountView.
function _isNativeFunction(uint32 selector) internal pure virtual override returns (bool) {
return super._isNativeFunction(selector) || selector == uint32(this.updateFallbackSignerData.selector)
|| selector == uint32(this.getFallbackSignerData.selector);
}

/// @dev Overrides ModularAccountView.
function _isWrappedNativeFunction(uint32 selector) internal pure virtual override returns (bool) {
return
Expand Down
2 changes: 1 addition & 1 deletion src/account/SemiModularAccountStorageOnly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract SemiModularAccountStorageOnly is SemiModularAccountBase {
}

/// @dev Overrides SemiModularAccountBase.
function _isNativeFunction(uint32 selector) internal view override returns (bool) {
function _isNativeFunction(uint32 selector) internal pure override returns (bool) {
return super._isNativeFunction(selector) || selector == uint32(this.initialize.selector);
}
}
51 changes: 0 additions & 51 deletions src/helpers/NativeFunctionDelegate.sol

This file was deleted.

0 comments on commit 61ee983

Please sign in to comment.