Skip to content

Commit

Permalink
added an extra comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsanant committed Jul 17, 2023
1 parent 7fae560 commit c720404
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
33 changes: 17 additions & 16 deletions src/contracts/middleware/BLSRegistryCoordinatorWithIndices.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
address[] public registries;

modifier onlyServiceManagerOwner {
require(msg.sender == serviceManager.owner(), "BLSIndexRegistryCoordinator.onlyServiceManagerOwner: caller is not the service manager owner");
require(msg.sender == serviceManager.owner(), "BLSRegistryCoordinatorWithIndices.onlyServiceManagerOwner: caller is not the service manager owner");
_;
}

Expand All @@ -73,7 +73,7 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
registries.push(address(indexRegistry));

// set the operator set params
require(IVoteWeigher(address(stakeRegistry)).quorumCount() == _operatorSetParams.length, "BLSIndexRegistryCoordinator: operator set params length mismatch");
require(IVoteWeigher(address(stakeRegistry)).quorumCount() == _operatorSetParams.length, "BLSRegistryCoordinatorWithIndices: operator set params length mismatch");
for (uint8 i = 0; i < _operatorSetParams.length; i++) {
_setOperatorSetParams(i, _operatorSetParams[i]);
}
Expand Down Expand Up @@ -104,7 +104,7 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
require(
_operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].nextUpdateBlockNumber == 0 ||
_operatorIdToQuorumBitmapHistory[operatorIds[i]][length - j - 1].nextUpdateBlockNumber > blockNumber,
"BLSRegistryCoordinator.getQuorumBitmapIndicesByOperatorIdsAtBlockNumber: operatorId has no quorumBitmaps at blockNumber"
"BLSRegistryCoordinatorWithIndices.getQuorumBitmapIndicesByOperatorIdsAtBlockNumber: operatorId has no quorumBitmaps at blockNumber"
);
indices[i] = length - j - 1;
break;
Expand All @@ -122,13 +122,13 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
QuorumBitmapUpdate memory quorumBitmapUpdate = _operatorIdToQuorumBitmapHistory[operatorId][index];
require(
quorumBitmapUpdate.updateBlockNumber <= blockNumber,
"BLSRegistryCoordinator.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from after blockNumber"
"BLSRegistryCoordinatorWithIndices.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from after blockNumber"
);
// if the next update is at or before the block number, then the quorum provided index is too early
// if the nex update block number is 0, then this is the latest update
require(
quorumBitmapUpdate.nextUpdateBlockNumber > blockNumber || quorumBitmapUpdate.nextUpdateBlockNumber == 0,
"BLSRegistryCoordinator.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from before blockNumber"
"BLSRegistryCoordinatorWithIndices.getQuorumBitmapByOperatorIdAtBlockNumberByIndex: quorumBitmapUpdate is from before blockNumber"
);
return quorumBitmapUpdate.quorumBitmap;
}
Expand Down Expand Up @@ -194,7 +194,8 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
* while maintaining the limit, the operator chooses another registered opeerator with lower stake to kick.
* @param quorumNumbers are the bytes representing the quorum numbers that the operator is registering for
* @param pubkey is the BLS public key of the operator
* @param operatorKickParams are the parameters for the deregistration of the operator that is being kicked
* @param operatorKickParams are the parameters for the deregistration of the operator that is being kicked from each
* quorum that will be filled after the operator registers.
*/
function registerOperatorWithCoordinator(
bytes calldata quorumNumbers,
Expand Down Expand Up @@ -229,13 +230,13 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
// check the registering operator has more than the kick BIPs of the operator to kick's stake
require(
registeringOperatorStake > operatorToKickStake * operatorSetParam.kickBIPsOfOperatorStake / BIPS_DENOMINATOR,
"BLSIndexRegistryCoordinator.registerOperatorWithCoordinator: registering operator has less than kickBIPsOfOperatorStake"
"BLSRegistryCoordinatorWithIndices.registerOperatorWithCoordinator: registering operator has less than kickBIPsOfOperatorStake"
);

// check the that the operator to kick has less than the kick BIPs of the total stake
require(
operatorToKickStake < totalStakeForQuorum * operatorSetParam.kickBIPsOfTotalStake / BIPS_DENOMINATOR,
"BLSIndexRegistryCoordinator.registerOperatorWithCoordinator: operator to kick has more than kickBIPSOfTotalStake"
"BLSRegistryCoordinatorWithIndices.registerOperatorWithCoordinator: operator to kick has more than kickBIPSOfTotalStake"
);
}

Expand Down Expand Up @@ -289,13 +290,13 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
// );

// check that the sender is not already registered
require(_operators[operator].status != OperatorStatus.REGISTERED, "BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: operator already registered");
require(_operators[operator].status != OperatorStatus.REGISTERED, "BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: operator already registered");

// get the quorum bitmap from the quorum numbers
uint256 quorumBitmap = BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers);

require(quorumBitmap != 0, "BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap cannot be 0");
require(quorumBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size");
require(quorumBitmap != 0, "BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: quorumBitmap cannot be 0");
require(quorumBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size");

// register the operator with the BLSPubkeyRegistry and get the operatorId (in this case, the pubkeyHash) back
bytes32 operatorId = blsPubkeyRegistry.registerOperator(operator, quorumNumbers, pubkey);
Expand Down Expand Up @@ -332,27 +333,27 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
for (uint i = 0; i < numOperatorsPerQuorum.length; i++) {
require(
numOperatorsPerQuorum[i] <= _quorumOperatorSetParams[uint8(quorumNumbers[i])].maxOperatorCount,
"BLSIndexRegistryCoordinator._registerOperatorWithCoordinatorAndNoOverfilledQuorums: quorum is overfilled"
"BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinatorAndNoOverfilledQuorums: quorum is overfilled"
);
}
}

function _deregisterOperatorWithCoordinator(address operator, bytes calldata quorumNumbers, BN254.G1Point memory pubkey, bytes32[] memory operatorIdsToSwap) internal {
require(_operators[operator].status == OperatorStatus.REGISTERED, "BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: operator is not registered");
require(_operators[operator].status == OperatorStatus.REGISTERED, "BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: operator is not registered");

// get the operatorId of the operator
bytes32 operatorId = _operators[operator].operatorId;
require(operatorId == pubkey.hashG1Point(), "BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: operatorId does not match pubkey hash");
require(operatorId == pubkey.hashG1Point(), "BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: operatorId does not match pubkey hash");

// get the quorumNumbers of the operator
uint256 quorumsToRemoveBitmap = BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers);
require(quorumsToRemoveBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap exceeds of max bitmap size");
require(quorumsToRemoveBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap exceeds of max bitmap size");
uint256 operatorQuorumBitmapHistoryLengthMinusOne = _operatorIdToQuorumBitmapHistory[operatorId].length - 1;
uint192 quorumBitmapBeforeUpdate = _operatorIdToQuorumBitmapHistory[operatorId][operatorQuorumBitmapHistoryLengthMinusOne].quorumBitmap;
// check that the quorumNumbers of the operator matches the quorumNumbers passed in
require(
quorumBitmapBeforeUpdate & quorumsToRemoveBitmap == quorumsToRemoveBitmap,
"BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: cannot deregister operator for quorums that it is not a part of"
"BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: cannot deregister operator for quorums that it is not a part of"
);
// check if the operator is completely deregistering
bool completeDeregistration = quorumBitmapBeforeUpdate == quorumsToRemoveBitmap;
Expand Down
18 changes: 9 additions & 9 deletions src/test/unit/BLSRegistryCoordinatorWithIndicesUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {

function testRegisterOperatorWithCoordinator_EmptyQuorumNumbers_Reverts() public {
bytes memory emptyQuorumNumbers = new bytes(0);
cheats.expectRevert("BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap cannot be 0");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: quorumBitmap cannot be 0");
cheats.prank(defaultOperator);
registryCoordinator.registerOperatorWithCoordinator(emptyQuorumNumbers, defaultPubKey, defaultSocket);
}

function testRegisterOperatorWithCoordinator_QuorumNumbersTooLarge_Reverts() public {
bytes memory quorumNumbersTooLarge = new bytes(1);
quorumNumbersTooLarge[0] = 0xC0;
cheats.expectRevert("BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size");
registryCoordinator.registerOperatorWithCoordinator(quorumNumbersTooLarge, defaultPubKey, defaultSocket);
}

Expand Down Expand Up @@ -195,15 +195,15 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
stakeRegistry.setOperatorWeight(defaultQuorumNumber, operatorToRegister, defaultStake);

cheats.prank(operatorToRegister);
cheats.expectRevert("BLSIndexRegistryCoordinator._registerOperatorWithCoordinatorAndNoOverfilledQuorums: quorum is overfilled");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._registerOperatorWithCoordinatorAndNoOverfilledQuorums: quorum is overfilled");
registryCoordinator.registerOperatorWithCoordinator(quorumNumbers, operatorToRegisterPubKey, defaultSocket);
}

function testDeregisterOperatorWithCoordinator_NotRegistered_Reverts() public {
bytes memory quorumNumbers = new bytes(1);
quorumNumbers[0] = bytes1(defaultQuorumNumber);

cheats.expectRevert("BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: operator is not registered");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: operator is not registered");
cheats.prank(defaultOperator);
registryCoordinator.deregisterOperatorWithCoordinator(quorumNumbers, defaultPubKey, new bytes32[](0));
}
Expand All @@ -217,7 +217,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {

BN254.G1Point memory incorrectPubKey = BN254.hashToG1(bytes32(uint256(123)));

cheats.expectRevert("BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: operatorId does not match pubkey hash");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: operatorId does not match pubkey hash");
cheats.prank(defaultOperator);
registryCoordinator.deregisterOperatorWithCoordinator(quorumNumbers, incorrectPubKey, new bytes32[](0));
}
Expand All @@ -233,7 +233,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
quorumNumbers[0] = bytes1(defaultQuorumNumber);
quorumNumbers[1] = bytes1(uint8(192));

cheats.expectRevert("BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap exceeds of max bitmap size");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap exceeds of max bitmap size");
cheats.prank(defaultOperator);
registryCoordinator.deregisterOperatorWithCoordinator(quorumNumbers, defaultPubKey, new bytes32[](0));
}
Expand All @@ -249,7 +249,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
quorumNumbers[0] = bytes1(defaultQuorumNumber);
quorumNumbers[1] = bytes1(defaultQuorumNumber + 1);

cheats.expectRevert("BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: cannot deregister operator for quorums that it is not a part of");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices._deregisterOperatorWithCoordinator: cannot deregister operator for quorums that it is not a part of");
cheats.prank(defaultOperator);
registryCoordinator.deregisterOperatorWithCoordinator(quorumNumbers, defaultPubKey, new bytes32[](0));
}
Expand Down Expand Up @@ -591,7 +591,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {

cheats.prank(operatorToRegister);
cheats.roll(registrationBlockNumber);
cheats.expectRevert("BLSIndexRegistryCoordinator.registerOperatorWithCoordinator: registering operator has less than kickBIPsOfOperatorStake");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices.registerOperatorWithCoordinator: registering operator has less than kickBIPsOfOperatorStake");
registryCoordinator.registerOperatorWithCoordinator(quorumNumbers, operatorToRegisterPubKey, defaultSocket, operatorKickParams);
}

Expand Down Expand Up @@ -649,7 +649,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {

cheats.prank(operatorToRegister);
cheats.roll(registrationBlockNumber);
cheats.expectRevert("BLSIndexRegistryCoordinator.registerOperatorWithCoordinator: operator to kick has more than kickBIPSOfTotalStake");
cheats.expectRevert("BLSRegistryCoordinatorWithIndices.registerOperatorWithCoordinator: operator to kick has more than kickBIPSOfTotalStake");
registryCoordinator.registerOperatorWithCoordinator(quorumNumbers, operatorToRegisterPubKey, defaultSocket, operatorKickParams);
}
}

0 comments on commit c720404

Please sign in to comment.