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

feat: [v0.8-develop] HookConfig install parameter & internal structure 4/N #109

Merged
merged 6 commits into from
Jul 24, 2024

Conversation

adamegyed
Copy link
Contributor

Motivation

The parameter format of specifying pre-validation hooks and permission hooks separately for install is redundant, and uses inefficient patterns of ABI encoding for its inner fields.

Solution

Much like ValidationConfig, introduce a HookConfig UDVT for holding:

  • Module address
  • Entity ID
  • Hook type
  • Pre/Post hook status

Use this type for installing validation associated hooks (pre-validation + permission hooks).

Use this type for internal encoding / decoding over the memory type ExecutionHook, which was only intended for external view functions.

Also bumps up the fuzzing runs for local testing - this setting is not used by CI, which uses optimized-test-deep.

@adamegyed adamegyed requested a review from a team July 22, 2024 20:04
@adamegyed adamegyed force-pushed the adam/hook-config branch 2 times, most recently from bfebb10 to de4125c Compare July 22, 2024 20:56
Comment on lines +77 to +93
function packExecHook(address _module, uint32 _entityId, bool _hasPre, bool _hasPost)
internal
pure
returns (HookConfig)
{
return HookConfig.wrap(
bytes26(
// module address stored in the first 20 bytes
bytes26(bytes20(_module))
// entityId stored in the 21st - 24th byte
| bytes26(bytes24(uint192(_entityId)))
// | bytes26(_HOOK_TYPE_EXEC) // Can omit because exec type is 0
| bytes26(_hasPre ? _EXEC_HOOK_HAS_PRE : bytes32(0))
| bytes26(_hasPost ? _EXEC_HOOK_HAS_POST : bytes32(0))
)
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this function? Seems duplicated code.
This can be achieved through the above function:

packExecHook(ModuleEntityLib.pack(module, entityId), hasPre, hasPost)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah It's a bit of a duplicate, but it's just for convenience to the caller so they don't have to import two libraries in some cases. I think this function is only linked in some tests, so it doesn't increase the bytecode size for the actual contracts.

@adamegyed adamegyed force-pushed the adam/manifest-remove-validation branch from 04132e0 to 22f26cf Compare July 23, 2024 17:06
Base automatically changed from adam/manifest-remove-validation to v0.8-develop July 23, 2024 19:59
src/account/ModuleManagerInternals.sol Outdated Show resolved Hide resolved
// Post hook has 1 in 1's bit in the 26th byte
bytes32 internal constant _EXEC_HOOK_HAS_POST = bytes32(uint256(1) << 48);

function packValidationHook(ModuleEntity _hookFunction) internal pure returns (HookConfig) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason the function parameters in this library are prefixed with an underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the individual accessor methods like module(), entityId(), etc, are also visible within the other internal functions, so if the parameters would be named with the underscore (i.e. just module), then they would shadow the inner functions. It's not necessarily a bad thing since we don't really need to access those functions, but I just wanted to avoid any variable shadowing to prevent the compiler warning.

src/account/ModuleManagerInternals.sol Outdated Show resolved Hide resolved
src/account/AccountStorage.sol Outdated Show resolved Hide resolved
Copy link
Collaborator

@jaypaik jaypaik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unblocking! I'll look over this again after catching up on the parent PRs.

@adamegyed adamegyed merged commit e36feac into v0.8-develop Jul 24, 2024
3 checks passed
@adamegyed adamegyed deleted the adam/hook-config branch July 24, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants