Skip to content

Commit

Permalink
more gas efficient approach
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 24, 2024
1 parent b16defb commit dc49577
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/contracts/src/core/permission/PermissionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1030,30 +1030,27 @@ abstract contract PermissionManager is Initializable {
return isRoot;
}

// Check either caller is delegated or an owner.
uint256 delegationFlags = _permission.delegations[_who];
uint256 ownerFlags = _permission.owners[_who];
uint256 flags = delegationFlags | ownerFlags;

if (
_operation == PermissionLib.Operation.Grant ||
_operation == PermissionLib.Operation.GrantWithCondition
) {
if (_checkFlags(flags, GRANT_OWNER_FLAG)) {
if (_checkFlags(delegationFlags, GRANT_OWNER_FLAG)) {
_permission.delegations[_who] = delegationFlags ^ GRANT_OWNER_FLAG;
}
if (_checkFlags(delegationFlags, GRANT_OWNER_FLAG)) {
_permission.delegations[_who] = delegationFlags ^ GRANT_OWNER_FLAG;
return true;
} else if (_checkFlags(_permission.owners[_who], GRANT_OWNER_FLAG)) {
return true;
}

return isRoot && _permission.grantCounter == 0;
}

if (_operation == PermissionLib.Operation.Revoke) {
if (_checkFlags(flags, REVOKE_OWNER_FLAG)) {
if (_checkFlags(delegationFlags, REVOKE_OWNER_FLAG)) {
_permission.delegations[_who] = delegationFlags ^ REVOKE_OWNER_FLAG;
}
if (_checkFlags(delegationFlags, REVOKE_OWNER_FLAG)) {
_permission.delegations[_who] = delegationFlags ^ REVOKE_OWNER_FLAG;
return true;
} else if (_checkFlags(_permission.owners[_who], REVOKE_OWNER_FLAG)) {
return true;
}

Expand Down

0 comments on commit dc49577

Please sign in to comment.