Skip to content

Commit

Permalink
Merge pull request #168 from dantaik/_hashBLSPubKey
Browse files Browse the repository at this point in the history
add _hashBLSPubKey() function
  • Loading branch information
AnshuJalan authored Oct 3, 2024
2 parents 1ee5fc1 + abadd09 commit 1cc86b6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions SmartContracts/src/avs/PreconfRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ contract PreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializable
// revert ValidatorSignatureExpired();
// }

// Point compress the public key just how it is done on the consensus layer
uint256[2] memory compressedPubKey = addValidatorParams[i].pubkey.compress();
// Use the hash for ease of mapping
bytes32 pubKeyHash = keccak256(abi.encodePacked(compressedPubKey));

bytes32 pubKeyHash = _hashBLSPubKey(addValidatorParams[i].pubkey);
Validator memory validator = validators[pubKeyHash];

// Update the validator if it has no preconfer assigned, or if it has stopped proposing
Expand Down Expand Up @@ -162,11 +158,7 @@ contract PreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializable
*/
function removeValidators(RemoveValidatorParam[] calldata removeValidatorParams) external {
for (uint256 i; i < removeValidatorParams.length; ++i) {
// Point compress the public key just how it is done on the consensus layer
uint256[2] memory compressedPubKey = removeValidatorParams[i].pubkey.compress();
// Use the hash for ease of mapping
bytes32 pubKeyHash = keccak256(abi.encodePacked(compressedPubKey));

bytes32 pubKeyHash = _hashBLSPubKey(removeValidatorParams[i].pubkey);
Validator memory validator = validators[pubKeyHash];

// Revert if the validator is not active (or already removed, but waiting to stop proposing)
Expand Down Expand Up @@ -238,4 +230,9 @@ contract PreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializable
{
return abi.encodePacked(block.chainid, validatorOp, expiry, preconfer);
}

function _hashBLSPubKey(BLS12381.G1Point calldata pubkey) internal pure returns (bytes32) {
uint256[2] memory compressedPubKey = pubkey.compress();
return keccak256(abi.encodePacked(compressedPubKey));
}
}

0 comments on commit 1cc86b6

Please sign in to comment.