Skip to content

Commit

Permalink
fix: remove account from 1271 interface
Browse files Browse the repository at this point in the history
  • Loading branch information
highskore committed Jan 11, 2025
1 parent 683ee6e commit 84f9aa0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 36 deletions.
2 changes: 1 addition & 1 deletion contracts/base/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ abstract contract ModuleManager is Storage, EIP712, IModuleManagerEventsAndError
// If no pre-validation hook is installed, return the original hash and signature
if (preValidationHook == address(0)) return (hash, signature);
// Otherwise, call the pre-validation hook and return the updated hash and signature
else return IPreValidationHookERC1271(preValidationHook).preValidationHookERC1271(address(this), msg.sender, hash, signature);
else return IPreValidationHookERC1271(preValidationHook).preValidationHookERC1271(msg.sender, hash, signature);
}

/// @dev Calls the pre-validation hook for ERC-4337.
Expand Down
12 changes: 2 additions & 10 deletions contracts/interfaces/modules/IPreValidationHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ import { IModule } from "./IModule.sol";
interface IPreValidationHookERC1271 is IModule {
/// @notice Performs pre-validation checks for isValidSignature
/// @dev This method is called before the validation of a signature on a validator within isValidSignature
/// @param account The account to validate the signature for
/// @param sender The original sender of the request
/// @param hash The hash of signed data
/// @param data The signature data to validate
/// @return hookHash The hash after applying the pre-validation hook
/// @return hookSignature The signature after applying the pre-validation hook
function preValidationHookERC1271(
address account,
address sender,
bytes32 hash,
bytes calldata data
)
external
view
returns (bytes32 hookHash, bytes memory hookSignature);
function preValidationHookERC1271(address sender, bytes32 hash, bytes calldata data) external view returns (bytes32 hookHash, bytes memory hookSignature);
}

/// @title Nexus - IPreValidationHookERC4337 Interface
Expand All @@ -42,5 +33,6 @@ interface IPreValidationHookERC4337 is IModule {
bytes32 userOpHash
)
external
view
returns (bytes32 hookHash, bytes memory hookSignature);
}
12 changes: 2 additions & 10 deletions contracts/mocks/Mock7739PreValidationHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ contract Mock7739PreValidationHook is IPreValidationHookERC1271 {
return forwarder == prevalidationHookMultiplexer;
}

function preValidationHookERC1271(
address account,
address,
bytes32 hash,
bytes calldata data
)
external
view
returns (bytes32 hookHash, bytes memory hookSignature)
{
function preValidationHookERC1271(address, bytes32 hash, bytes calldata data) external view returns (bytes32 hookHash, bytes memory hookSignature) {
address account = _msgSender();
// Check flag in first byte
if (data[0] == 0x00) {
return wrapFor7739Validation(account, hash, _erc1271UnwrapSignature(data[1:]));
Expand Down
11 changes: 1 addition & 10 deletions contracts/mocks/MockPreValidationHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ contract MockPreValidationHook is IPreValidationHookERC1271, IPreValidationHookE
return true;
}

function preValidationHookERC1271(
address,
address,
bytes32 hash,
bytes calldata data
)
external
pure
returns (bytes32 hookHash, bytes memory hookSignature)
{
function preValidationHookERC1271(address, bytes32 hash, bytes calldata data) external pure returns (bytes32 hookHash, bytes memory hookSignature) {
return (hash, data);
}

Expand Down
19 changes: 15 additions & 4 deletions contracts/mocks/MockPreValidationHookMultiplexer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ contract MockPreValidationHookMultiplexer is IPreValidationHookERC1271, IPreVali
bytes32 userOpHash
)
external
view
returns (bytes32 hookHash, bytes memory hookSignature)
{
HookConfig storage config = accountConfig[MODULE_TYPE_PREVALIDATION_HOOK_ERC4337][msg.sender];
Expand All @@ -79,8 +80,12 @@ contract MockPreValidationHookMultiplexer is IPreValidationHookERC1271, IPreVali

for (uint256 i = 0; i < config.hooks.length; i++) {
bytes memory subHookData = abi.encodeWithSelector(IPreValidationHookERC4337.preValidationHookERC4337.selector, op, missingAccountFunds, hookHash);
(bool success, bytes memory result) = config.hooks[i].call(abi.encodePacked(subHookData, msg.sender));
require(success, SubHookFailed(config.hooks[i]));
(bool success, bytes memory result) = config.hooks[i].staticcall(abi.encodePacked(subHookData, msg.sender));
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
(hookHash, hookSignature) = abi.decode(result, (bytes32, bytes));
op.signature = hookSignature;
}
Expand All @@ -89,7 +94,6 @@ contract MockPreValidationHookMultiplexer is IPreValidationHookERC1271, IPreVali
}

function preValidationHookERC1271(
address account,
address sender,
bytes32 hash,
bytes calldata signature
Expand All @@ -108,7 +112,14 @@ contract MockPreValidationHookMultiplexer is IPreValidationHookERC1271, IPreVali
hookSignature = signature;

for (uint256 i = 0; i < config.hooks.length; i++) {
(hookHash, hookSignature) = IPreValidationHookERC1271(config.hooks[i]).preValidationHookERC1271(account, sender, hookHash, hookSignature);
bytes memory subHookData = abi.encodeWithSelector(IPreValidationHookERC1271.preValidationHookERC1271.selector, sender, hookHash, hookSignature);
(bool success, bytes memory result) = config.hooks[i].staticcall(abi.encodePacked(subHookData, msg.sender));
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
(hookHash, hookSignature) = abi.decode(result, (bytes32, bytes));
}

return (hookHash, hookSignature);
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/MockResourceLockPreValidationHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ contract MockResourceLockPreValidationHook is IPreValidationHookERC4337, IPreVal
}

function preValidationHookERC1271(
address account,
address sender,
bytes32 hash,
bytes calldata data
Expand All @@ -101,6 +100,7 @@ contract MockResourceLockPreValidationHook is IPreValidationHookERC4337, IPreVal
override
returns (bytes32 hookHash, bytes memory hookSignature)
{
address account = _msgSender();
require(notResourceLocked(account, sender), SenderIsResourceLocked());
return (hash, data);
}
Expand Down

0 comments on commit 84f9aa0

Please sign in to comment.