Skip to content

Commit

Permalink
correcting bit shift when checking for flag validity
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Leonard authored and Robert Leonard committed Oct 2, 2023
1 parent 0faea7f commit a63e2ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/DidRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ contract DIDRegistry is IDidRegistry, Initializable, UUPSUpgradeable, OwnableUpg
function addVerificationMethod(address didIdentifier, VerificationMethod calldata verificationMethod) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public {

require(!_doesFragmentExist(didIdentifier, verificationMethod.fragment), "Fragment already exist");
require(_isValidFlag(verificationMethod.flags), "Attempted to add unsupported flag");

// Apply a bitmask on the verificationMethodFlags
bool hasOwnershipFlag = _hasFlag(verificationMethod.flags, VerificationMethodFlagBitMask.OWNERSHIP_PROOF);
Expand Down Expand Up @@ -360,6 +361,6 @@ contract DIDRegistry is IDidRegistry, Initializable, UUPSUpgradeable, OwnableUpg

function _isValidFlag(uint16 flags) internal pure returns(bool) {
// Shifts the input flag by the amount of flags avalible.
return uint16(type(VerificationMethodFlagBitMask).max) >> uint16(flags) == 0;
return uint16(flags) >> (uint16(type(VerificationMethodFlagBitMask).max) + 1) == 0;
}
}
4 changes: 2 additions & 2 deletions test/DidRegistryVerificationMethodTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ contract DidRegistryVerificationMethodTest is DidRegistryTest {
didRegistry.updateVerificationMethodFlags(user, 'default', uint16(uint16(1) << uint16(DIDRegistry.VerificationMethodFlagBitMask.DID_DOC_HIDDEN)));
}

function test__revert_should_not_allow_adding_unknown_flag_to_verification_method() public {
function test_revert_should_not_allow_adding_unknown_flag_to_verification_method() public {
address user = vm.addr(1);

vm.startPrank(user); // Send transaction as the user
Expand All @@ -171,7 +171,7 @@ contract DidRegistryVerificationMethodTest is DidRegistryTest {
DIDRegistry.VerificationMethod memory defaultVerificationMethod = didState.verificationMethods[0];

// Add none supported flag
uint16 newFlags = defaultVerificationMethod.flags & uint16(uint16(1) << uint16(type(DIDRegistry.VerificationMethodFlagBitMask).max) + 1);
uint16 newFlags = defaultVerificationMethod.flags | uint16(uint16(1) << uint16(type(DIDRegistry.VerificationMethodFlagBitMask).max) + 2);

vm.expectRevert("Attempted to add unsupported flag");
didRegistry.updateVerificationMethodFlags(user, defaultVerificationMethod.fragment, newFlags);
Expand Down

0 comments on commit a63e2ab

Please sign in to comment.