From 154e3e992dc24fdb1a6dcc1e5ad8a37d1aa998eb Mon Sep 17 00:00:00 2001 From: vicnaum Date: Mon, 4 Sep 2023 17:30:40 +0100 Subject: [PATCH] fix: [C4-109-L02] Unlink could be called for any unlinked handles by passing zero --- contracts/namespaces/TokenHandleRegistry.sol | 3 +++ test/namespaces/TokenHandleRegistryTest.t.sol | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/namespaces/TokenHandleRegistry.sol b/contracts/namespaces/TokenHandleRegistry.sol index a9393a3..a32d237 100644 --- a/contracts/namespaces/TokenHandleRegistry.sol +++ b/contracts/namespaces/TokenHandleRegistry.sol @@ -176,6 +176,9 @@ contract TokenHandleRegistry is ITokenHandleRegistry { } function _unlink(uint256 handleId, uint256 profileId, address transactionExecutor) private { + if (handleId == 0 || profileId == 0) { + revert RegistryErrors.DoesNotExist(); + } if ( ILensHandles(LENS_HANDLES).exists(handleId) && ILensHandles(LENS_HANDLES).ownerOf(handleId) != transactionExecutor && diff --git a/test/namespaces/TokenHandleRegistryTest.t.sol b/test/namespaces/TokenHandleRegistryTest.t.sol index 663512b..ce40507 100644 --- a/test/namespaces/TokenHandleRegistryTest.t.sol +++ b/test/namespaces/TokenHandleRegistryTest.t.sol @@ -112,16 +112,16 @@ contract TokenHandleRegistryTest is BaseTest { assertEq(tokenHandleRegistry.resolve(handleId), profileId); assertEq(tokenHandleRegistry.getDefaultHandle(profileId), handleId); - vm.expectRevert(RegistryErrors.NotLinked.selector); + vm.expectRevert(RegistryErrors.DoesNotExist.selector); vm.prank(otherAddress); tokenHandleRegistry.unlink(handleId, 0); - vm.expectRevert(RegistryErrors.NotLinked.selector); + vm.expectRevert(RegistryErrors.DoesNotExist.selector); vm.prank(otherAddress); tokenHandleRegistry.unlink(0, profileId); console.log('0, 0'); - vm.expectRevert(RegistryErrors.NotLinked.selector); + vm.expectRevert(RegistryErrors.DoesNotExist.selector); vm.prank(otherAddress); tokenHandleRegistry.unlink(0, 0); }