Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [spearbit-99] Correctly set post-only hook flag #20

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/account/PluginManagerInternals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {

if (preExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
selectorData.hasPreExecHooks = true;
}

if (postExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
} else if (postExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
// Only set this flag if the pre hook is empty and the post hook is non-empty.
selectorData.hasPostOnlyExecHooks = true;
}
}
Expand All @@ -144,14 +143,14 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {
{
SelectorData storage selectorData = _getAccountStorage().selectorData[selector];

(bool shouldClearHasPreHooks, bool shouldClearHasPostHooks) =
(bool shouldClearHasPreHooks, bool shouldClearHasPostOnlyHooks) =
_removeHooks(selectorData.executionHooks, preExecHook, postExecHook);

if (shouldClearHasPreHooks) {
selectorData.hasPreExecHooks = false;
}

if (shouldClearHasPostHooks) {
if (shouldClearHasPostOnlyHooks) {
selectorData.hasPostOnlyExecHooks = false;
}
}
Expand All @@ -178,9 +177,8 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {

if (preExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
permittedCallData.hasPrePermittedCallHooks = true;
}

if (postExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
} else if (postExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
// Only set this flag if the pre hook is empty and the post hook is non-empty.
permittedCallData.hasPostOnlyPermittedCallHooks = true;
}
}
Expand All @@ -194,14 +192,14 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {
PermittedCallData storage permittedCallData =
_getAccountStorage().permittedCalls[_getPermittedCallKey(plugin, selector)];

(bool shouldClearHasPreHooks, bool shouldClearHasPostHooks) =
(bool shouldClearHasPreHooks, bool shouldClearHasPostOnlyHooks) =
_removeHooks(permittedCallData.permittedCallHooks, preExecHook, postExecHook);

if (shouldClearHasPreHooks) {
permittedCallData.hasPrePermittedCallHooks = false;
}

if (shouldClearHasPostHooks) {
if (shouldClearHasPostOnlyHooks) {
permittedCallData.hasPostOnlyPermittedCallHooks = false;
}
}
Expand Down Expand Up @@ -239,7 +237,7 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {

function _removeHooks(HookGroup storage hooks, FunctionReference preExecHook, FunctionReference postExecHook)
internal
returns (bool shouldClearHasPreHooks, bool shouldClearHasPostHooks)
returns (bool shouldClearHasPreHooks, bool shouldClearHasPostOnlyHooks)
{
if (preExecHook != FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE) {
// If decrementing results in removal, this also clears the flag _PRE_EXEC_HOOK_HAS_POST_FLAG.
Expand Down Expand Up @@ -273,7 +271,7 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {
// Update the cached flag value for the post-only exec hooks, as it may change with a removal.
if (hooks.postOnlyHooks.isEmpty()) {
// The "has post only hooks" flag should be disabled
shouldClearHasPostHooks = true;
shouldClearHasPostOnlyHooks = true;
}
}
}
Expand Down