Skip to content

Commit 53a12d7

Browse files
authored
chore: clearer error message (#1602)
**Motivation:** We used the `KeyAlreadyRegistered` error when an operator is already registered as well as when a key already registered. This is not a descriptive error message. **Modifications:** Add `OperatorAlreadyRegistered` message **Result:** More descriptive code
1 parent 723e1bb commit 53a12d7

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/contracts/interfaces/IKeyRegistrar.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ interface IKeyRegistrarErrors {
1111
/// @dev We prevent duplicate key registrations to maintain global key uniqueness and avoid conflicting operator-key mappings
1212
error KeyAlreadyRegistered();
1313

14+
/// @notice Error thrown when an operator is already registered
15+
/// @dev Error code: 0x42ee68b5
16+
/// @dev We prevent duplicate operator registrations to prevent re-registrations with a new key
17+
error OperatorAlreadyRegistered();
18+
1419
/// @notice Error thrown when the key format is invalid
1520
/// @dev Error code: 0xd1091181
1621
/// @dev We enforce proper key formats (20 bytes for ECDSA, valid G1/G2 points for BN254) to ensure cryptographic validity and prevent malformed key data
@@ -115,7 +120,7 @@ interface IKeyRegistrar is IKeyRegistrarErrors, IKeyRegistrarEvents, ISemVerMixi
115120
* @dev Reverts for:
116121
* - InvalidPermissions: Caller is not the operator or authorized via the PermissionController
117122
* - OperatorSetNotConfigured: The operator set is not configured
118-
* - KeyAlreadyRegistered: The operator is already registered for the operatorSet in the KeyRegistrar
123+
* - OperatorAlreadyRegistered: The operator is already registered for the operatorSet in the KeyRegistrar
119124
* - InvalidKeyFormat: For ECDSA: The key is not exactly 20 bytes
120125
* - ZeroAddress: For ECDSA: The key is the zero address
121126
* - KeyAlreadyRegistered: For ECDSA: The key is already registered globally by hash

src/contracts/permissions/KeyRegistrar.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ contract KeyRegistrar is KeyRegistrarStorage, PermissionControllerMixin, Signatu
7373
require(curveType != CurveType.NONE, OperatorSetNotConfigured());
7474

7575
// Check if the operator is already registered to the operatorSet
76-
require(!_operatorKeyInfo[operatorSet.key()][operator].isRegistered, KeyAlreadyRegistered());
76+
require(!_operatorKeyInfo[operatorSet.key()][operator].isRegistered, OperatorAlreadyRegistered());
7777

7878
// Register key based on curve type - both now require signature verification
7979
if (curveType == CurveType.ECDSA) {

src/test/unit/KeyRegistrarUnit.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ contract KeyRegistrarUnitTests_registerKey_ECDSA is KeyRegistrarUnitTests {
287287
keyRegistrar.registerKey(operator1, operatorSet, ecdsaKey1, signature);
288288

289289
vm.prank(operator1);
290-
vm.expectRevert(KeyAlreadyRegistered.selector);
290+
vm.expectRevert(OperatorAlreadyRegistered.selector);
291291
keyRegistrar.registerKey(operator1, operatorSet, ecdsaKey1, signature);
292292
}
293293

@@ -475,9 +475,9 @@ contract KeyRegistrarUnitTests_registerKey_BN254 is KeyRegistrarUnitTests {
475475
vm.prank(operator1);
476476
keyRegistrar.registerKey(operator1, operatorSet, bn254Key1, signature);
477477

478-
// Try to register the same key again
478+
// Try to register the same operator again
479479
vm.prank(operator1);
480-
vm.expectRevert(KeyAlreadyRegistered.selector);
480+
vm.expectRevert(OperatorAlreadyRegistered.selector);
481481
keyRegistrar.registerKey(operator1, operatorSet, bn254Key1, signature);
482482
}
483483

0 commit comments

Comments
 (0)