Skip to content

Commit

Permalink
fix: [spearbit-99] Correctly set post-only hook flag (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-alchemy authored Jan 3, 2024
1 parent 96f5fea commit 3e8944f
Showing 1 changed file with 10 additions and 12 deletions.
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

0 comments on commit 3e8944f

Please sign in to comment.