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 for sherlock issues 46, 43, 42 #10

Merged
merged 11 commits into from
Apr 10, 2023
Merged

Fix for sherlock issues 46, 43, 42 #10

merged 11 commits into from
Apr 10, 2023

Conversation

spengrah
Copy link
Member

Address the following issues by disallowing any modules other than (M)HSG:

sherlock-audit/2023-02-hats-judging#46
sherlock-audit/2023-02-hats-judging#43
sherlock-audit/2023-02-hats-judging#42

@spengrah spengrah changed the base branch from fix/36 to fix/37 March 28, 2023 02:21
@spengrah spengrah marked this pull request as ready for review March 28, 2023 02:22
Comment on lines +505 to +517
(address[] memory modulesWith1, address next) = safe.getModulesPaginated(SENTINEL_OWNERS, 1);
// ensure that there is only one module...
if (
// if the length is 0, we know this module has been removed
// forgefmt: disable-next-line
modulesWith1.length == 0
/* per Safe ModuleManager.sol#137, "If all entries fit into a single page, the next pointer will be 0x1", ie SENTINEL_OWNERS.
Therefore, if `next` is not SENTINEL_OWNERS, we know another module has been added. */
|| next != SENTINEL_OWNERS
) {
revert SignersCannotChangeModules();
} // ...and that the only module is this contract
else if (modulesWith1[0] != address(this)) {
Copy link

Choose a reason for hiding this comment

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

This looks fine. You are checking three conditions with the same error message (and we exit the if early if modulesWith1.length == 0, so the indexing will work), so probably easiest to just stack them into one statement like:

if(
    modulesWith1.length == 0
    || next != SENTINEL_OWNERS
    || modulesWith1[0] != address(this)
) ...

Honestly, I would probably just get a page of 2 modules and simply check:

if(modulesWith1.length != 1 || modulesWIth1[0] != address(this)) ...

But either way works. This solution will accomplish the goal, so marking it as approved.

@spengrah spengrah merged commit e2e106a into fix/37 Apr 10, 2023
@spengrah spengrah deleted the fix/46-43-42 branch April 10, 2023 17:49
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.

2 participants