Skip to content

Commit 47f4b24

Browse files
committed
chore: add sig digest functions to interface (#1464)
**Motivation:** `getBN254KeyRegistrationMessageHash` and `getEDSAKeyRegistrationMessageHash` are not in the `IKeyRegistrar` interface. **Modifications:** - Add functions to interface - Use functions internally **Result:** Cleaner code
1 parent 9940b49 commit 47f4b24

File tree

9 files changed

+164
-32
lines changed

9 files changed

+164
-32
lines changed

pkg/bindings/BN254CertificateVerifier/binding.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/BN254TableCalculator/binding.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/CrossChainRegistry/binding.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/IKeyRegistrar/binding.go

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/KeyRegistrar/binding.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/KeyRegistrarStorage/binding.go

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/OperatorTableUpdater/binding.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/contracts/interfaces/IKeyRegistrar.sol

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,30 @@ interface IKeyRegistrar is IKeyRegistrarErrors, IKeyRegistrarEvents, ISemVerMixi
147147
* @return keyHash The key hash
148148
*/
149149
function getKeyHash(OperatorSet memory operatorSet, address operator) external view returns (bytes32);
150+
151+
/**
152+
* @notice Returns the message hash for ECDSA key registration
153+
* @param operator The operator address
154+
* @param operatorSet The operator set
155+
* @param keyAddress The address of the key
156+
* @return The message hash for signing
157+
*/
158+
function getECDSAKeyRegistrationMessageHash(
159+
address operator,
160+
OperatorSet memory operatorSet,
161+
address keyAddress
162+
) external view returns (bytes32);
163+
164+
/**
165+
* @notice Returns the message hash for BN254 key registration
166+
* @param operator The operator address
167+
* @param operatorSet The operator set
168+
* @param keyData The BN254 key data
169+
* @return The message hash for signing
170+
*/
171+
function getBN254KeyRegistrationMessageHash(
172+
address operator,
173+
OperatorSet memory operatorSet,
174+
bytes calldata keyData
175+
) external view returns (bytes32);
150176
}

src/contracts/permissions/KeyRegistrar.sol

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,8 @@ contract KeyRegistrar is KeyRegistrarStorage, PermissionControllerMixin, Signatu
146146
// Check global uniqueness
147147
require(!globalKeyRegistry[keyHash], KeyAlreadyRegistered());
148148

149-
// Create EIP-712 compliant message hash
150-
bytes32 structHash = keccak256(
151-
abi.encode(ECDSA_KEY_REGISTRATION_TYPEHASH, operator, operatorSet.avs, operatorSet.id, keyAddress)
152-
);
153-
bytes32 signableDigest = _calculateSignableDigest(structHash);
149+
// Get the signable digest for the ECDSA key registration message
150+
bytes32 signableDigest = getECDSAKeyRegistrationMessageHash(operator, operatorSet, keyAddress);
154151

155152
_checkIsValidSignatureNow(keyAddress, signableDigest, signature, type(uint256).max);
156153

@@ -189,10 +186,7 @@ contract KeyRegistrar is KeyRegistrarStorage, PermissionControllerMixin, Signatu
189186
}
190187

191188
// Create EIP-712 compliant message hash
192-
bytes32 structHash = keccak256(
193-
abi.encode(BN254_KEY_REGISTRATION_TYPEHASH, operator, operatorSet.avs, operatorSet.id, keccak256(keyData))
194-
);
195-
bytes32 signableDigest = _calculateSignableDigest(structHash);
189+
bytes32 signableDigest = getBN254KeyRegistrationMessageHash(operator, operatorSet, keyData);
196190

197191
// Decode signature from bytes to G1 point
198192
(uint256 sigX, uint256 sigY) = abi.decode(signature, (uint256, uint256));
@@ -323,36 +317,24 @@ contract KeyRegistrar is KeyRegistrarStorage, PermissionControllerMixin, Signatu
323317
return _getKeyHashForKeyData(keyInfo.keyData, curveType);
324318
}
325319

326-
/**
327-
* @notice Returns the message hash for ECDSA key registration
328-
* @param operator The operator address
329-
* @param operatorSet The operator set
330-
* @param keyAddress The ECDSA key address
331-
* @return The message hash for signing
332-
*/
320+
/// @inheritdoc IKeyRegistrar
333321
function getECDSAKeyRegistrationMessageHash(
334322
address operator,
335323
OperatorSet memory operatorSet,
336324
address keyAddress
337-
) external view returns (bytes32) {
325+
) public view returns (bytes32) {
338326
bytes32 structHash = keccak256(
339327
abi.encode(ECDSA_KEY_REGISTRATION_TYPEHASH, operator, operatorSet.avs, operatorSet.id, keyAddress)
340328
);
341329
return _calculateSignableDigest(structHash);
342330
}
343331

344-
/**
345-
* @notice Returns the message hash for BN254 key registration
346-
* @param operator The operator address
347-
* @param operatorSet The operator set
348-
* @param keyData The BN254 key data
349-
* @return The message hash for signing
350-
*/
332+
/// @inheritdoc IKeyRegistrar
351333
function getBN254KeyRegistrationMessageHash(
352334
address operator,
353335
OperatorSet memory operatorSet,
354336
bytes calldata keyData
355-
) external view returns (bytes32) {
337+
) public view returns (bytes32) {
356338
bytes32 structHash = keccak256(
357339
abi.encode(BN254_KEY_REGISTRATION_TYPEHASH, operator, operatorSet.avs, operatorSet.id, keccak256(keyData))
358340
);

0 commit comments

Comments
 (0)