Skip to content

Commit

Permalink
feat: add calculatePubkeyRegistrationMessageHash
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Dec 18, 2024
1 parent b54d400 commit f9c8ee8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
24 changes: 11 additions & 13 deletions script/utils/OperatorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,31 @@ library OperatorLib {
function registerOperatorFromAVS_OpSet(
Operator memory operator,
address allocationManager,
address registryCoordinator,
address avs,
uint32[] memory operatorSetIds
) internal {

bytes memory registrationParamsData;
IAllocationManager allocationManagerInstance = IAllocationManager(allocationManager);

// Create BLS pubkey registration params

// Get the pubkey registration message hash that needs to be signed
bytes32 pubkeyRegistrationMessageHash = RegistryCoordinator(registryCoordinator).calculatePubkeyRegistrationMessageHash(operator.key.addr);

// Sign the pubkey registration message hash
BN254.G1Point memory signature = signMessage(operator.signingKey, pubkeyRegistrationMessageHash);

IBLSApkRegistry.PubkeyRegistrationParams memory blsParams = IBLSApkRegistry.PubkeyRegistrationParams({
pubkeyG1: operator.signingKey.publicKeyG1,
pubkeyG2: operator.signingKey.publicKeyG2,
pubkeyRegistrationSignature: operator.signingKey.publicKeyG1
pubkeyRegistrationSignature: signature
});

// Get the pubkey registration message hash that needs to be signed
BN254.G1Point memory pubkeyRegistrationMessageHash = BN254.hashToG1(
keccak256(abi.encodePacked(operator.key.addr))
);

// Sign the pubkey registration message hash
BN254.G1Point memory signature = signMessage(operator.signingKey, keccak256(abi.encodePacked(operator.key.addr)));

// Encode the registration data for the registry coordinator
registrationParamsData = abi.encode(
blsParams,
pubkeyRegistrationMessageHash,
signature
"test-socket", // Random socket string
blsParams
);

IAllocationManagerTypes.RegisterParams memory params = IAllocationManagerTypes.RegisterParams({
Expand Down
19 changes: 17 additions & 2 deletions src/RegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,23 @@ contract RegistryCoordinator is
view
returns (BN254.G1Point memory)
{
return BN254.hashToG1(
_hashTypedDataV4(keccak256(abi.encode(PUBKEY_REGISTRATION_TYPEHASH, operator)))
return BN254.hashToG1(calculatePubkeyRegistrationMessageHash(operator));
}

/**
* @notice Returns the message hash that an operator must sign to register their BLS public key.
* @param operator is the address of the operator registering their BLS public key
*/
function calculatePubkeyRegistrationMessageHash(
address operator
) public view returns (bytes32) {
return _hashTypedDataV4(
keccak256(
abi.encode(
PUBKEY_REGISTRATION_TYPEHASH,
operator
)
)
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/OperatorLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ contract OperatorLibTest is Test {
OperatorLib.registerOperatorFromAVS_OpSet(
operators[i],
coreDeployment.allocationManager,
middlewareDeployment.registryCoordinator,
middlewareDeployment.serviceManager,
operatorSetIds
);
vm.stopPrank();
}

}
}

0 comments on commit f9c8ee8

Please sign in to comment.