Skip to content

Commit

Permalink
fix: revert before reaching postCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
leekt committed Jun 10, 2024
1 parent d191610 commit d46551f
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions src/Kernel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,42 +181,36 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
bytes memory result;
if (address(config.hook) == address(0)) {
revert InvalidSelector();
} else {
// action installed
bytes memory context;
if (
address(config.hook) != address(1) && address(config.hook) != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF
) {
context = _doPreHook(config.hook, msg.value, msg.data);
} else if (address(config.hook) == 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) {
// for selector manager, address(0) for the hook will default to type(address).max,
// and this will only allow entrypoints to interact
if (msg.sender != address(entrypoint)) {
revert InvalidCaller();
}
}
// execute action
if (config.callType == CALLTYPE_SINGLE) {
(success, result) = ExecLib.doFallback2771Call(config.target);
} else if (config.callType == CALLTYPE_DELEGATECALL) {
(success, result) = ExecLib.executeDelegatecall(config.target, msg.data);
} else {
revert NotSupportedCallType();
}
if (
address(config.hook) != address(1) && address(config.hook) != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF
) {
_doPostHook(config.hook, context);
}
// action installed
bytes memory context;
if (address(config.hook) != address(1) && address(config.hook) != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) {
context = _doPreHook(config.hook, msg.value, msg.data);
} else if (address(config.hook) == 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) {
// for selector manager, address(0) for the hook will default to type(address).max,
// and this will only allow entrypoints to interact
if (msg.sender != address(entrypoint)) {
revert InvalidCaller();
}
}
// execute action
if (config.callType == CALLTYPE_SINGLE) {
(success, result) = ExecLib.doFallback2771Call(config.target);
} else if (config.callType == CALLTYPE_DELEGATECALL) {
(success, result) = ExecLib.executeDelegatecall(config.target, msg.data);
} else {
revert NotSupportedCallType();
}
if (!success) {
assembly {
revert(add(result, 0x20), mload(result))
}
} else {
assembly {
return(add(result, 0x20), mload(result))
}
}
if (address(config.hook) != address(1) && address(config.hook) != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF) {
_doPostHook(config.hook, context);
}
assembly {
return(add(result, 0x20), mload(result))
}
}

Expand Down Expand Up @@ -289,10 +283,11 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
context = _doPreHook(hook, msg.value, userOp.callData[4:]);
}
(bool success, bytes memory ret) = ExecLib.executeDelegatecall(address(this), userOp.callData[4:]);
if (!success) {
revert ExecutionReverted();
}
if (address(hook) != address(1)) {
_doPostHook(hook, context);
} else if (!success) {
revert ExecutionReverted();
}
}

Expand Down

0 comments on commit d46551f

Please sign in to comment.