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

Redundant check of owner() != address(0) #194

Open
code423n4 opened this issue Nov 24, 2021 · 1 comment
Open

Redundant check of owner() != address(0) #194

code423n4 opened this issue Nov 24, 2021 · 1 comment
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

By the time MixinRoles._initializeMixinRoles() is called, there are no roles configured yet, therefore the check of !isLockManager(sender) and !isKeyGranter(sender) is redundant.

https://github.com/code-423n4/2021-11-unlock/blob/ec41eada1dd116bcccc5603ce342257584bec783/smart-contracts/contracts/mixins/MixinRoles.sol#L22-L36

  function _initializeMixinRoles(address sender) internal {

    // for admin mamangers to add other lock admins
    _setRoleAdmin(LOCK_MANAGER_ROLE, LOCK_MANAGER_ROLE);

    // for lock managers to add/remove key granters
    _setRoleAdmin(KEY_GRANTER_ROLE, LOCK_MANAGER_ROLE);

    if (!isLockManager(sender)) {
      _setupRole(LOCK_MANAGER_ROLE, sender);  
    }
    if (!isKeyGranter(sender)) {
      _setupRole(KEY_GRANTER_ROLE, sender);
    }
  }

Recommendation

Change to:

  function _initializeMixinRoles(address sender) internal {

    // for admin mamangers to add other lock admins
    _setRoleAdmin(LOCK_MANAGER_ROLE, LOCK_MANAGER_ROLE);

    // for lock managers to add/remove key granters
    _setRoleAdmin(KEY_GRANTER_ROLE, LOCK_MANAGER_ROLE);

    _setupRole(LOCK_MANAGER_ROLE, sender);

    _setupRole(KEY_GRANTER_ROLE, sender);
  }
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 24, 2021
code423n4 added a commit that referenced this issue Nov 24, 2021
@0xleastwood
Copy link
Collaborator

This seems right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants