Skip to content

Commit 26bfdb9

Browse files
committed
feat: refactor avs sync
1 parent 7e4d987 commit 26bfdb9

12 files changed

+302
-271
lines changed

src/BLSSignatureChecker.sol

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ contract BLSSignatureChecker is BLSSignatureCheckerStorage {
2020
/// MODIFIERS
2121

2222
modifier onlyCoordinatorOwner() {
23-
require(msg.sender == Ownable(address(registryCoordinator)).owner(), OnlyRegistryCoordinatorOwner());
23+
require(
24+
msg.sender == Ownable(address(registryCoordinator)).owner(),
25+
OnlyRegistryCoordinatorOwner()
26+
);
2427
_;
2528
}
2629

src/RegistryCoordinator.sol

+19-8
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ contract RegistryCoordinator is RegistryCoordinatorStorage {
4545
_socketRegistry,
4646
_allocationManager,
4747
_pauserRegistry
48-
)
48+
)
4949
{}
5050

5151
/**
@@ -62,10 +62,14 @@ contract RegistryCoordinator is RegistryCoordinatorStorage {
6262
SignatureWithSaltAndExpiry memory operatorSignature
6363
) external onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR) {
6464
require(!isM2QuorumRegistrationDisabled, M2QuorumRegistrationIsDisabled());
65-
require(quorumNumbers.orderedBytesArrayToBitmap().isSubsetOf(m2QuorumBitmap), OnlyM2QuorumsAllowed());
66-
65+
require(
66+
quorumNumbers.orderedBytesArrayToBitmap().isSubsetOf(m2QuorumBitmap),
67+
OnlyM2QuorumsAllowed()
68+
);
69+
6770
// Check if the operator has registered before
68-
bool operatorRegisteredBefore = _operatorInfo[msg.sender].status == OperatorStatus.REGISTERED;
71+
bool operatorRegisteredBefore =
72+
_operatorInfo[msg.sender].status == OperatorStatus.REGISTERED;
6973

7074
// register the operator with the registry coordinator
7175
_registerOperator({
@@ -92,10 +96,14 @@ contract RegistryCoordinator is RegistryCoordinatorStorage {
9296
SignatureWithSaltAndExpiry memory operatorSignature
9397
) external onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR) {
9498
require(!isM2QuorumRegistrationDisabled, M2QuorumRegistrationIsDisabled());
95-
require(quorumNumbers.orderedBytesArrayToBitmap().isSubsetOf(m2QuorumBitmap), OnlyM2QuorumsAllowed());
96-
99+
require(
100+
quorumNumbers.orderedBytesArrayToBitmap().isSubsetOf(m2QuorumBitmap),
101+
OnlyM2QuorumsAllowed()
102+
);
103+
97104
// Check if the operator has registered before
98-
bool operatorRegisteredBefore = _operatorInfo[msg.sender].status == OperatorStatus.REGISTERED;
105+
bool operatorRegisteredBefore =
106+
_operatorInfo[msg.sender].status == OperatorStatus.REGISTERED;
99107

100108
// register the operator with the registry coordinator with churn
101109
_registerOperatorWithChurn({
@@ -155,7 +163,10 @@ contract RegistryCoordinator is RegistryCoordinatorStorage {
155163
*/
156164

157165
/// @dev override the _forceDeregisterOperator function to handle M2 quorum deregistration
158-
function _forceDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual override {
166+
function _forceDeregisterOperator(
167+
address operator,
168+
bytes memory quorumNumbers
169+
) internal virtual override {
159170
// filter out M2 quorums from the quorum numbers
160171
uint256 operatorSetBitmap = quorumNumbers.orderedBytesArrayToBitmap().minus(m2QuorumBitmap);
161172
if (!operatorSetBitmap.isEmpty()) {

src/RegistryCoordinatorStorage.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {ISocketRegistry} from "./interfaces/ISocketRegistry.sol";
1313

1414
import {SlashingRegistryCoordinator} from "./SlashingRegistryCoordinator.sol";
1515

16-
abstract contract RegistryCoordinatorStorage is IRegistryCoordinator, SlashingRegistryCoordinator {
16+
abstract contract RegistryCoordinatorStorage is
17+
IRegistryCoordinator,
18+
SlashingRegistryCoordinator
19+
{
1720
/**
1821
*
1922
* CONSTANTS AND IMMUTABLES
@@ -63,4 +66,4 @@ abstract contract RegistryCoordinatorStorage is IRegistryCoordinator, SlashingRe
6366
}
6467

6568
uint256[47] private __GAP;
66-
}
69+
}

src/SlashingRegistryCoordinator.sol

+28-59
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,6 @@ contract SlashingRegistryCoordinator is
225225
_deregisterOperator(operator, quorumNumbers);
226226
}
227227

228-
/// @inheritdoc ISlashingRegistryCoordinator
229-
function updateOperators(
230-
address[] memory operators
231-
) external onlyWhenNotPaused(PAUSED_UPDATE_OPERATOR) {
232-
for (uint256 i = 0; i < operators.length; i++) {
233-
address operator = operators[i];
234-
OperatorInfo memory operatorInfo = _operatorInfo[operator];
235-
bytes32 operatorId = operatorInfo.operatorId;
236-
237-
// Update the operator's stake for their active quorums
238-
uint192 currentBitmap = _currentOperatorBitmap(operatorId);
239-
bytes memory quorumsToUpdate = BitmapUtils.bitmapToBytesArray(currentBitmap);
240-
_updateOperator(operator, operatorInfo, quorumsToUpdate);
241-
}
242-
}
243-
244228
/// @inheritdoc ISlashingRegistryCoordinator
245229
function updateOperatorsForQuorum(
246230
address[][] memory operatorsPerQuorum,
@@ -264,6 +248,7 @@ contract SlashingRegistryCoordinator is
264248
QuorumOperatorCountMismatch()
265249
);
266250

251+
bytes32[] memory operatorIds = new bytes32[](currQuorumOperators.length);
267252
address prevOperatorAddress = address(0);
268253
// For each operator:
269254
// - check that they are registered for this quorum
@@ -272,11 +257,9 @@ contract SlashingRegistryCoordinator is
272257
for (uint256 j = 0; j < currQuorumOperators.length; ++j) {
273258
address operator = currQuorumOperators[j];
274259

275-
OperatorInfo memory operatorInfo = _operatorInfo[operator];
276-
bytes32 operatorId = operatorInfo.operatorId;
277-
260+
operatorIds[j] = _operatorInfo[operator].operatorId;
278261
{
279-
uint192 currentBitmap = _currentOperatorBitmap(operatorId);
262+
uint192 currentBitmap = _currentOperatorBitmap(operatorIds[j]);
280263
// Check that the operator is registered
281264
require(
282265
BitmapUtils.isSet(currentBitmap, quorumNumber), NotRegisteredForQuorum()
@@ -285,10 +268,17 @@ contract SlashingRegistryCoordinator is
285268
require(operator > prevOperatorAddress, NotSorted());
286269
}
287270

288-
// Update the operator
289-
_updateOperator(operator, operatorInfo, quorumNumbers[i:i + 1]);
290271
prevOperatorAddress = operator;
291272
}
273+
bytes memory quorumNumberBytes = new bytes(1);
274+
quorumNumberBytes[0] = bytes1(quorumNumber);
275+
bool[] memory shouldBeDeregistered =
276+
stakeRegistry.updateOperatorsStake(currQuorumOperators, operatorIds, quorumNumber);
277+
for (uint256 j = 0; j < currQuorumOperators.length; ++j) {
278+
if (shouldBeDeregistered[j]) {
279+
_deregisterOperator(currQuorumOperators[j], quorumNumberBytes);
280+
}
281+
}
292282

293283
// Update timestamp that all operators in quorum have been updated all at once
294284
quorumUpdateBlockNumber[quorumNumber] = block.number;
@@ -439,7 +429,10 @@ contract SlashingRegistryCoordinator is
439429
if (checkMaxOperatorCount) {
440430
for (uint256 i = 0; i < quorumNumbers.length; i++) {
441431
OperatorSetParam memory operatorSetParams = _quorumParams[uint8(quorumNumbers[i])];
442-
require(results.numOperatorsPerQuorum[i] <= operatorSetParams.maxOperatorCount, MaxQuorumsReached());
432+
require(
433+
results.numOperatorsPerQuorum[i] <= operatorSetParams.maxOperatorCount,
434+
MaxQuorumsReached()
435+
);
443436
}
444437
}
445438

@@ -469,14 +462,13 @@ contract SlashingRegistryCoordinator is
469462

470463
// Register the operator in each of the registry contracts and update the operator's
471464
// quorum bitmap and registration status
472-
RegisterResults memory results =
473-
_registerOperator({
474-
operator: operator,
475-
operatorId: operatorId,
476-
quorumNumbers: quorumNumbers,
477-
socket: socket,
478-
checkMaxOperatorCount: false
479-
});
465+
RegisterResults memory results = _registerOperator({
466+
operator: operator,
467+
operatorId: operatorId,
468+
quorumNumbers: quorumNumbers,
469+
socket: socket,
470+
checkMaxOperatorCount: false
471+
});
480472

481473
// Check that each quorum's operator count is below the configured maximum. If the max
482474
// is exceeded, use `operatorKickParams` to deregister an existing operator to make space
@@ -563,7 +555,10 @@ contract SlashingRegistryCoordinator is
563555
* @param operator The operator to deregister
564556
* @param quorumNumbers The quorum numbers the operator is force-deregistered from
565557
*/
566-
function _forceDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {
558+
function _forceDeregisterOperator(
559+
address operator,
560+
bytes memory quorumNumbers
561+
) internal virtual {
567562
allocationManager.deregisterFromOperatorSets(
568563
IAllocationManagerTypes.DeregisterParams({
569564
operator: operator,
@@ -660,32 +655,6 @@ contract SlashingRegistryCoordinator is
660655
);
661656
}
662657

663-
/**
664-
* @notice Updates the StakeRegistry's view of the operator's stake in one or more quorums.
665-
* For any quorums where the StakeRegistry finds the operator is under the configured minimum
666-
* stake, `quorumsToRemove` is returned and used to deregister the operator from those quorums
667-
* @dev does nothing if operator is not registered for any quorums.
668-
*/
669-
function _updateOperator(
670-
address operator,
671-
OperatorInfo memory operatorInfo,
672-
bytes memory quorumsToUpdate
673-
) internal {
674-
if (operatorInfo.status != OperatorStatus.REGISTERED) {
675-
return;
676-
}
677-
bytes32 operatorId = operatorInfo.operatorId;
678-
uint192 quorumsToRemove =
679-
stakeRegistry.updateOperatorStake(operator, operatorId, quorumsToUpdate);
680-
681-
if (!quorumsToRemove.isEmpty()) {
682-
_deregisterOperator({
683-
operator: operator,
684-
quorumNumbers: BitmapUtils.bitmapToBytesArray(quorumsToRemove)
685-
});
686-
}
687-
}
688-
689658
/**
690659
* @notice Returns the stake threshold required for an incoming operator to replace an existing operator
691660
* The incoming operator must have more stake than the return value.
@@ -898,7 +867,7 @@ contract SlashingRegistryCoordinator is
898867
function _afterCreateQuorum(
899868
uint8 quorumNumber
900869
) internal virtual {}
901-
870+
902871
/// @dev Hook to allow for any pre-register logic in `_registerOperator`
903872
function _beforeRegisterOperator(
904873
address operator,

0 commit comments

Comments
 (0)