Skip to content

Commit

Permalink
Merge branch 'cantina/109' into cantina/63
Browse files Browse the repository at this point in the history
  • Loading branch information
simplemachine92 committed Jan 8, 2025
2 parents a29c32b + 13f5ac0 commit 5f06bf9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/JBPermissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract JBPermissions is IJBPermissions {
// --------------------------- custom errors ------------------------- //
//*********************************************************************//

error JBPermissions_CantSetRootPermissionForWildcardProject();
error JBPermissions_NoZeroPermission();
error JBPermissions_PermissionIdOutOfBounds(uint256 permissionId);
error JBPermissions_Unauthorized();
Expand Down Expand Up @@ -231,6 +232,12 @@ contract JBPermissions is IJBPermissions {
)
) revert JBPermissions_Unauthorized();

// ROOT permission cannot be set for a wildcard project ID.
if (
permissionsData.projectId == WILDCARD_PROJECT_ID
&& _includesPermission({permissions: packed, permissionId: JBPermissionIds.ROOT})
) revert JBPermissions_CantSetRootPermissionForWildcardProject();

// Store the new value.
permissionsOf[permissionsData.operator][account][permissionsData.projectId] = packed;

Expand Down
23 changes: 23 additions & 0 deletions test/TestPermissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ contract TestPermissions_Local is TestBaseWorkflow, JBTest {

// Check if all the items in `check_permissions` also exist in `set_permissions`.
bool _shouldHavePermissions = true;
bool _containsRoot;
for (uint256 _i; _i < _u8_check_permissions.length; _i++) {
bool _exists;
_check_permissions[_i] = _u8_check_permissions[_i];
for (uint256 _j; _j < _u8_set_permissions.length; _j++) {
// We update this lots of times unnecesarily but no need to optimize this.
_set_permissions[_j] = _u8_set_permissions[_j % 256];

// Update if we find root value.
if (_u8_set_permissions[_j] == 1) _containsRoot = true;

// If we find this item we break and mark the flag.
if (_u8_check_permissions[_i] == _u8_set_permissions[_j]) {
_exists = true;
Expand All @@ -178,6 +183,10 @@ contract TestPermissions_Local is TestBaseWorkflow, JBTest {
}
}

if (_containsRoot && _projectId == 0) {
vm.expectRevert(JBPermissions.JBPermissions_CantSetRootPermissionForWildcardProject.selector);
}

// Set the permissions.
vm.prank(_account);
_permissions.setPermissionsFor(
Expand All @@ -190,6 +199,20 @@ contract TestPermissions_Local is TestBaseWorkflow, JBTest {
);
}

function testSetRootWildcardProjectId(address _account, address _operator) public {
uint8[] memory _set_permissions = new uint8[](1);
_set_permissions[0] = JBPermissionIds.ROOT;

// Set the permissions.
vm.prank(_account);

vm.expectRevert(JBPermissions.JBPermissions_CantSetRootPermissionForWildcardProject.selector);
_permissions.setPermissionsFor(
_account,
JBPermissionsData({operator: _operator, projectId: 0, /* wildcard */ permissionIds: _set_permissions})
);
}

function testBasicAccessSetup() public {
address zeroOwner = makeAddr("zeroOwner");
address token = address(usdcToken());
Expand Down

0 comments on commit 5f06bf9

Please sign in to comment.