Skip to content

Commit

Permalink
fix tests and make revert messages better
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsanant committed Jul 17, 2023
1 parent 7815293 commit 40533cf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface IBLSRegistryCoordinatorWithIndices is IRegistryCoordinator {

// EVENTS

event OperatorSocketUpdate(bytes32 operatorId, string socket);
event OperatorSocketUpdate(bytes32 indexed operatorId, string socket);

event OperatorSetParamsUpdated(uint8 indexed quorumNumber, OperatorSetParam operatorSetParams);

Expand Down
11 changes: 5 additions & 6 deletions src/contracts/middleware/BLSRegistryCoordinatorWithIndices.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
return _operatorIdToQuorumBitmapHistory[operatorId][index];
}

/// @notice Returns the current quorum bitmap for the given `operatorId`
/// @notice Returns the current quorum bitmap for the given `operatorId` or 0 if the operator is not registered for any quorum
function getCurrentQuorumBitmapByOperatorId(bytes32 operatorId) external view returns (uint192) {
uint256 quorumBitmapHistoryLength = _operatorIdToQuorumBitmapHistory[operatorId].length;
if (quorumBitmapHistoryLength == 0) {
revert("BLSRegistryCoordinator.getCurrentQuorumBitmapByOperatorId: no quorum bitmap history for operatorId");
if (quorumBitmapHistoryLength == 0 || _operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].nextUpdateBlockNumber != 0) {
return 0;
}
require(_operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].nextUpdateBlockNumber == 0, "BLSRegistryCoordinator.getCurrentQuorumBitmapByOperatorId: operator is not registered");
return _operatorIdToQuorumBitmapHistory[operatorId][quorumBitmapHistoryLength - 1].quorumBitmap;
}

Expand Down Expand Up @@ -296,7 +295,7 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin
uint256 quorumBitmap = BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers);

require(quorumBitmap != 0, "BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap cannot be 0");
require(quorumBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap cant have more than 192 set bits");
require(quorumBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSIndexRegistryCoordinator._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 @@ -347,7 +346,7 @@ contract BLSRegistryCoordinatorWithIndices is Initializable, IBLSRegistryCoordin

// get the quorumNumbers of the operator
uint256 quorumsToRemoveBitmap = BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers);
require(quorumsToRemoveBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap cant have more than 192 set bits");
require(quorumsToRemoveBitmap <= MiddlewareUtils.MAX_QUORUM_BITMAP, "BLSIndexRegistryCoordinator._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
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/middleware/IndexRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ contract IndexRegistry is IIndexRegistry {
}


/// @notice Returns the index of the `operatorId` at the given `blockNumber` for the given `quorumNumber`, or max uint32 if the operator is not active in the quorum
/// @notice Returns the index of the `operatorId` at the given `blockNumber` for the given `quorumNumber`, or `OPERATOR_DEREGISTERED_INDEX` if the operator was not registered for the `quorumNumber` at blockNumber
function _getIndexOfOperatorForQuorumAtBlockNumber(bytes32 operatorId, uint8 quorumNumber, uint32 blockNumber) internal view returns(uint32) {
uint256 operatorIndexHistoryLength = _operatorIdToIndexHistory[operatorId][quorumNumber].length;
// loop backward through index history to find the index of the operator at the given block number
Expand All @@ -252,7 +252,7 @@ contract IndexRegistry is IIndexRegistry {
}

// the operator is still active or not in the quorum, so we return the latest index or the default max uint32
// this will be hit if `blockNumber` is before when the operator registered or has not registered for the given quorum
// this will be hit if `blockNumber` is before when the operator registered or the operator has never registered for the given quorum
return OPERATOR_DEREGISTERED_INDEX;
}
}
15 changes: 6 additions & 9 deletions src/test/unit/BLSRegistryCoordinatorWithIndicesUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {

uint8 maxQuorumsToRegisterFor = 4;

event OperatorSocketUpdate(bytes32 operatorId, string socket);
event OperatorSocketUpdate(bytes32 indexed operatorId, string socket);

/// @notice emitted whenever the stake of `operator` is updated
event StakeUpdate(
Expand Down Expand Up @@ -64,7 +64,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
function testRegisterOperatorWithCoordinator_QuorumNumbersTooLarge_Reverts() public {
bytes memory quorumNumbersTooLarge = new bytes(1);
quorumNumbersTooLarge[0] = 0xC0;
cheats.expectRevert("BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap cant have more than 192 set bits");
cheats.expectRevert("BLSIndexRegistryCoordinator._registerOperatorWithCoordinator: quorumBitmap exceeds of max bitmap size");
registryCoordinator.registerOperatorWithCoordinator(quorumNumbersTooLarge, defaultPubKey, defaultSocket);
}

Expand Down Expand Up @@ -233,7 +233,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
quorumNumbers[0] = bytes1(defaultQuorumNumber);
quorumNumbers[1] = bytes1(uint8(192));

cheats.expectRevert("BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap cant have more than 192 set bits");
cheats.expectRevert("BLSIndexRegistryCoordinator._deregisterOperatorWithCoordinator: quorumsToRemoveBitmap exceeds of max bitmap size");
cheats.prank(defaultOperator);
registryCoordinator.deregisterOperatorWithCoordinator(quorumNumbers, defaultPubKey, new bytes32[](0));
}
Expand Down Expand Up @@ -293,8 +293,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
status: IRegistryCoordinator.OperatorStatus.DEREGISTERED
})))
);
cheats.expectRevert("BLSRegistryCoordinator.getCurrentQuorumBitmapByOperatorId: operator is not registered");
registryCoordinator.getCurrentQuorumBitmapByOperatorId(defaultOperatorId);
assertEq(registryCoordinator.getCurrentQuorumBitmapByOperatorId(defaultOperatorId), 0);
assertEq(
keccak256(abi.encode(registryCoordinator.getQuorumBitmapUpdateByOperatorIdByIndex(defaultOperatorId, 0))),
keccak256(abi.encode(IRegistryCoordinator.QuorumBitmapUpdate({
Expand Down Expand Up @@ -350,8 +349,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
status: IRegistryCoordinator.OperatorStatus.DEREGISTERED
})))
);
cheats.expectRevert("BLSRegistryCoordinator.getCurrentQuorumBitmapByOperatorId: operator is not registered");
registryCoordinator.getCurrentQuorumBitmapByOperatorId(defaultOperatorId);
assertEq(registryCoordinator.getCurrentQuorumBitmapByOperatorId(defaultOperatorId), 0);
assertEq(
keccak256(abi.encode(registryCoordinator.getQuorumBitmapUpdateByOperatorIdByIndex(defaultOperatorId, 0))),
keccak256(abi.encode(IRegistryCoordinator.QuorumBitmapUpdate({
Expand Down Expand Up @@ -433,8 +431,7 @@ contract BLSRegistryCoordinatorWithIndicesUnit is MockAVSDeployer {
status: IRegistryCoordinator.OperatorStatus.DEREGISTERED
})))
);
cheats.expectRevert("BLSRegistryCoordinator.getCurrentQuorumBitmapByOperatorId: operator is not registered");
registryCoordinator.getCurrentQuorumBitmapByOperatorId(operatorToDerigisterId);
assertEq(registryCoordinator.getCurrentQuorumBitmapByOperatorId(defaultOperatorId), 0);
assertEq(
keccak256(abi.encode(registryCoordinator.getQuorumBitmapUpdateByOperatorIdByIndex(operatorToDerigisterId, 0))),
keccak256(abi.encode(IRegistryCoordinator.QuorumBitmapUpdate({
Expand Down

0 comments on commit 40533cf

Please sign in to comment.