Skip to content

Commit

Permalink
Correctly check flag comparision
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Leonard authored and Robert Leonard committed Aug 17, 2023
1 parent 544dcb9 commit fd6d576
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/DidRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ contract DIDRegistry is IDidRegistry {

VerificationMethod storage vm = didState.verificationMethods[i];

// If trying to change the OWNERSHIP PROOF or PROTECTED flags the keyData must match the message sender
bool isUpdatingOwnershipFlag = _hasFlag(vm.flags, VerificationMethodFlagBitMask.OWNERSHIP_PROOF) != _hasFlag(flags,VerificationMethodFlagBitMask.OWNERSHIP_PROOF);
bool isUpdatingProtectedFlag = _hasFlag(vm.flags, VerificationMethodFlagBitMask.PROTECTED)!= _hasFlag(flags,VerificationMethodFlagBitMask.PROTECTED);

if(isUpdatingOwnershipFlag || isUpdatingProtectedFlag) {
require(address(bytes20(vm.keyData)) == msg.sender, "Only the verification method authority key can set the ownership proof or protected flags");
}

if(_stringCompare(vm.fragment, fragment)) {
// If trying to change the OWNERSHIP PROOF or PROTECTED flags the keyData must match the message sender
bool isUpdatingOwnershipFlag = _hasFlag(vm.flags, VerificationMethodFlagBitMask.OWNERSHIP_PROOF) != _hasFlag(flags,VerificationMethodFlagBitMask.OWNERSHIP_PROOF);
bool isUpdatingProtectedFlag = _hasFlag(vm.flags, VerificationMethodFlagBitMask.PROTECTED)!= _hasFlag(flags,VerificationMethodFlagBitMask.PROTECTED);

if(isUpdatingOwnershipFlag || isUpdatingProtectedFlag) {
require(address(bytes20(vm.keyData)) == msg.sender, "Only the verification method authority key can set the ownership proof or protected flags");
}

uint16 oldFlags = didState.verificationMethods[i].flags;
didState.verificationMethods[i].flags = flags;

Expand Down
4 changes: 2 additions & 2 deletions test/DidRegistryVerificationMethodTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ contract DidRegistryVerificationMethodTest is DidRegistryTest {

vm.expectRevert("Only the verification method authority key can set the ownership proof or protected flags");

bool result = didRegistry.updateVerificationMethodFlags(userTwo, newVm.fragment, newFlags);
bool result = didRegistry.updateVerificationMethodFlags(userTwo, 'default', newFlags);
}

function test_revert_only_authorized_key_can_update_protected_flag_on_verification_methods() public {
Expand Down Expand Up @@ -202,7 +202,7 @@ contract DidRegistryVerificationMethodTest is DidRegistryTest {

vm.expectRevert("Only the verification method authority key can set the ownership proof or protected flags");

bool result = didRegistry.updateVerificationMethodFlags(userTwo, newVm.fragment, newFlags);
bool result = didRegistry.updateVerificationMethodFlags(userTwo, 'default', newFlags);
}

function test_revert_should_not_be_able_to_remove_verification_method_that_does_not_exist() public {
Expand Down

0 comments on commit fd6d576

Please sign in to comment.