Skip to content

Commit

Permalink
fix: incorrect accounting of sysAdmins when reassigning system role […
Browse files Browse the repository at this point in the history
…NAY-6]
  • Loading branch information
amarinkovic committed Apr 18, 2023
1 parent 0649519 commit fada081
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/diamonds/nayms/libs/LibACL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ library LibACL {
require(_contextId != "", "invalid context ID");
require(_roleId != "", "invalid role ID");

s.roles[_objectId][_contextId] = _roleId;
bytes32 oldRole = s.roles[_objectId][_contextId];
if(oldRole == LibHelpers._stringToBytes32(LibConstants.ROLE_SYSTEM_ADMIN) && oldRole != _roleId) {
require(s.sysAdmins > 1, "must have at least one system admin");
}

s.roles[_objectId][_contextId] = _roleId;
if (_contextId == LibAdmin._getSystemId() && _roleId == LibHelpers._stringToBytes32(LibConstants.ROLE_SYSTEM_ADMIN)) {
unchecked {
s.sysAdmins += 1;
Expand Down
5 changes: 5 additions & 0 deletions test/T02ACL.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ contract T02ACLTest is D03ProtocolDefaults, MockAccounts {
nayms.unassignRole(account0Id, systemContext);
}

function testReassignLastSystemAdminFails() public {
vm.expectRevert("must have at least one system admin");
nayms.assignRole(account0Id, systemContext, LibConstants.ROLE_BROKER);
}

function testUnassignSystemAdmin() public {
nayms.assignRole(signer1Id, systemContext, LibConstants.ROLE_SYSTEM_ADMIN);

Expand Down

0 comments on commit fada081

Please sign in to comment.