Skip to content

Commit 062ed61

Browse files
authored
Merge pull request #27 from erc7579/feature/hook-changes-back
feat: revert hooks
2 parents 5c3363b + 881022f commit 062ed61

File tree

5 files changed

+14
-50
lines changed

5 files changed

+14
-50
lines changed

src/MSAAdvanced.sol

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
3636
external
3737
payable
3838
onlyEntryPointOrSelf
39+
withHook
3940
{
40-
(address hook, bytes memory hookData) = _preCheck();
4141
(CallType callType, ExecType execType,,) = mode.decode();
4242

4343
// check if calltype is batch or single
@@ -68,9 +68,6 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
6868
} else {
6969
revert UnsupportedCallType(callType);
7070
}
71-
72-
// TODO: add correct data
73-
_postCheck(hook, hookData, true, new bytes(0));
7471
}
7572

7673
/**
@@ -87,11 +84,11 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
8784
external
8885
payable
8986
onlyExecutorModule
87+
withHook
9088
returns (
9189
bytes[] memory returnData // TODO returnData is not used
9290
)
9391
{
94-
(address hook, bytes memory hookData) = _preCheck();
9592
(CallType callType, ExecType execType,,) = mode.decode();
9693

9794
// check if calltype is batch or single
@@ -130,9 +127,6 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
130127
} else {
131128
revert UnsupportedCallType(callType);
132129
}
133-
134-
// TODO: add correct data
135-
_postCheck(hook, hookData, true, new bytes(0));
136130
}
137131

138132
/**
@@ -167,18 +161,14 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
167161
external
168162
payable
169163
onlyEntryPointOrSelf
164+
withHook
170165
{
171-
(address hook, bytes memory hookData) = _preCheck();
172-
173166
if (moduleTypeId == MODULE_TYPE_VALIDATOR) _installValidator(module, initData);
174167
else if (moduleTypeId == MODULE_TYPE_EXECUTOR) _installExecutor(module, initData);
175168
else if (moduleTypeId == MODULE_TYPE_FALLBACK) _installFallbackHandler(module, initData);
176169
else if (moduleTypeId == MODULE_TYPE_HOOK) _installHook(module, initData);
177170
else revert UnsupportedModuleType(moduleTypeId);
178171
emit ModuleInstalled(moduleTypeId, module);
179-
180-
// TODO: add correct data
181-
_postCheck(hook, hookData, true, new bytes(0));
182172
}
183173

184174
/**
@@ -192,9 +182,8 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
192182
external
193183
payable
194184
onlyEntryPointOrSelf
185+
withHook
195186
{
196-
(address hook, bytes memory hookData) = _preCheck();
197-
198187
if (moduleTypeId == MODULE_TYPE_VALIDATOR) {
199188
_uninstallValidator(module, deInitData);
200189
} else if (moduleTypeId == MODULE_TYPE_EXECUTOR) {
@@ -207,9 +196,6 @@ contract MSAAdvanced is IMSA, ExecutionHelper, ModuleManager, HookManager {
207196
revert UnsupportedModuleType(moduleTypeId);
208197
}
209198
emit ModuleUninstalled(moduleTypeId, module);
210-
211-
// TODO: add correct data
212-
_postCheck(hook, hookData, true, new bytes(0));
213199
}
214200

215201
/**

src/core/HookManager.sol

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,14 @@ abstract contract HookManager {
2222
error HookPostCheckFailed();
2323
error HookAlreadyInstalled(address currentHook);
2424

25-
function _preCheck() internal returns (address hook, bytes memory hookData) {
26-
hook = _getHook();
27-
if (hook != address(0)) {
28-
hookData = IHook(hook).preCheck(msg.sender, msg.value, msg.data);
29-
return (hook, hookData);
30-
}
31-
}
32-
33-
function _postCheck(
34-
address hook,
35-
bytes memory hookData,
36-
bool executionSuccess,
37-
bytes memory executionReturnValue
38-
)
39-
internal
40-
{
41-
if (hook != address(0)) {
42-
IHook(hook).postCheck(hookData, executionSuccess, executionReturnValue);
25+
modifier withHook() {
26+
address hook = _getHook();
27+
if (hook == address(0)) {
28+
_;
29+
} else {
30+
bytes memory hookData = IHook(hook).preCheck(msg.sender, msg.value, msg.data);
31+
_;
32+
IHook(hook).postCheck(hookData);
4333
}
4434
}
4535

src/interfaces/IERC7579Account.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pragma solidity ^0.8.21;
33

44
import { CallType, ExecType, ModeCode } from "../lib/ModeLib.sol";
5-
import { PackedUserOperation } from "account-abstraction/interfaces/IAccount.sol";
65

76
struct Execution {
87
address target;

src/interfaces/IERC7579Module.sol

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ interface IHook is IModule {
9191
external
9292
returns (bytes memory hookData);
9393

94-
function postCheck(
95-
bytes calldata hookData,
96-
bool executionSuccess,
97-
bytes calldata executionReturnValue
98-
)
99-
external;
94+
function postCheck(bytes calldata hookData) external;
10095
}
10196

10297
interface IFallback is IModule { }

test/mocks/MockHook.sol

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ contract MockHook is IHook {
1616
external
1717
returns (bytes memory hookData)
1818
{ }
19-
function postCheck(
20-
bytes calldata hookData,
21-
bool executionSuccess,
22-
bytes calldata executionReturnValue
23-
)
24-
external
25-
{ }
19+
function postCheck(bytes calldata hookData) external { }
2620

2721
function isModuleType(uint256 moduleTypeId) external view returns (bool) {
2822
return moduleTypeId == MODULE_TYPE_HOOK;

0 commit comments

Comments
 (0)