Skip to content

Commit 0801b19

Browse files
committed
feat: refactor avs sync
1 parent 15c5636 commit 0801b19

12 files changed

+302
-276
lines changed

Diff for: 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

Diff for: 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()) {

Diff for: 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+
}

Diff for: src/SlashingRegistryCoordinator.sol

+28-64
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,6 @@ contract SlashingRegistryCoordinator is
232232
_deregisterOperator(operator, quorumNumbers);
233233
}
234234

235-
/**
236-
* @notice Updates the StakeRegistry's view of one or more operators' stakes. If any operator
237-
* is found to be below the minimum stake for the quorum, they are deregistered.
238-
* @dev stakes are queried from the Eigenlayer core DelegationManager contract
239-
* @param operators a list of operator addresses to update
240-
*/
241-
function updateOperators(
242-
address[] memory operators
243-
) external onlyWhenNotPaused(PAUSED_UPDATE_OPERATOR) {
244-
for (uint256 i = 0; i < operators.length; i++) {
245-
address operator = operators[i];
246-
OperatorInfo memory operatorInfo = _operatorInfo[operator];
247-
bytes32 operatorId = operatorInfo.operatorId;
248-
249-
// Update the operator's stake for their active quorums
250-
uint192 currentBitmap = _currentOperatorBitmap(operatorId);
251-
bytes memory quorumsToUpdate = BitmapUtils.bitmapToBytesArray(currentBitmap);
252-
_updateOperator(operator, operatorInfo, quorumsToUpdate);
253-
}
254-
}
255-
256235
/**
257236
* @notice For each quorum in `quorumNumbers`, updates the StakeRegistry's view of ALL its registered operators' stakes.
258237
* Each quorum's `quorumUpdateBlockNumber` is also updated, which tracks the most recent block number when ALL registered
@@ -289,6 +268,7 @@ contract SlashingRegistryCoordinator is
289268
QuorumOperatorCountMismatch()
290269
);
291270

271+
bytes32[] memory operatorIds = new bytes32[](currQuorumOperators.length);
292272
address prevOperatorAddress = address(0);
293273
// For each operator:
294274
// - check that they are registered for this quorum
@@ -297,11 +277,9 @@ contract SlashingRegistryCoordinator is
297277
for (uint256 j = 0; j < currQuorumOperators.length; ++j) {
298278
address operator = currQuorumOperators[j];
299279

300-
OperatorInfo memory operatorInfo = _operatorInfo[operator];
301-
bytes32 operatorId = operatorInfo.operatorId;
302-
280+
operatorIds[j] = _operatorInfo[operator].operatorId;
303281
{
304-
uint192 currentBitmap = _currentOperatorBitmap(operatorId);
282+
uint192 currentBitmap = _currentOperatorBitmap(operatorIds[j]);
305283
// Check that the operator is registered
306284
require(
307285
BitmapUtils.isSet(currentBitmap, quorumNumber), NotRegisteredForQuorum()
@@ -310,10 +288,17 @@ contract SlashingRegistryCoordinator is
310288
require(operator > prevOperatorAddress, NotSorted());
311289
}
312290

313-
// Update the operator
314-
_updateOperator(operator, operatorInfo, quorumNumbers[i:i + 1]);
315291
prevOperatorAddress = operator;
316292
}
293+
bytes memory quorumNumberBytes = new bytes(1);
294+
quorumNumberBytes[0] = bytes1(quorumNumber);
295+
bool[] memory shouldBeDeregistered =
296+
stakeRegistry.updateOperatorsStake(currQuorumOperators, operatorIds, quorumNumber);
297+
for (uint256 j = 0; j < currQuorumOperators.length; ++j) {
298+
if (shouldBeDeregistered[j]) {
299+
_deregisterOperator(currQuorumOperators[j], quorumNumberBytes);
300+
}
301+
}
317302

318303
// Update timestamp that all operators in quorum have been updated all at once
319304
quorumUpdateBlockNumber[quorumNumber] = block.number;
@@ -491,7 +476,10 @@ contract SlashingRegistryCoordinator is
491476
if (checkMaxOperatorCount) {
492477
for (uint256 i = 0; i < quorumNumbers.length; i++) {
493478
OperatorSetParam memory operatorSetParams = _quorumParams[uint8(quorumNumbers[i])];
494-
require(results.numOperatorsPerQuorum[i] <= operatorSetParams.maxOperatorCount, MaxQuorumsReached());
479+
require(
480+
results.numOperatorsPerQuorum[i] <= operatorSetParams.maxOperatorCount,
481+
MaxQuorumsReached()
482+
);
495483
}
496484
}
497485

@@ -521,14 +509,13 @@ contract SlashingRegistryCoordinator is
521509

522510
// Register the operator in each of the registry contracts and update the operator's
523511
// quorum bitmap and registration status
524-
RegisterResults memory results =
525-
_registerOperator({
526-
operator: operator,
527-
operatorId: operatorId,
528-
quorumNumbers: quorumNumbers,
529-
socket: socket,
530-
checkMaxOperatorCount: false
531-
});
512+
RegisterResults memory results = _registerOperator({
513+
operator: operator,
514+
operatorId: operatorId,
515+
quorumNumbers: quorumNumbers,
516+
socket: socket,
517+
checkMaxOperatorCount: false
518+
});
532519

533520
// Check that each quorum's operator count is below the configured maximum. If the max
534521
// is exceeded, use `operatorKickParams` to deregister an existing operator to make space
@@ -615,7 +602,10 @@ contract SlashingRegistryCoordinator is
615602
* @param operator The operator to deregister
616603
* @param quorumNumbers The quorum numbers the operator is force-deregistered from
617604
*/
618-
function _forceDeregisterOperator(address operator, bytes memory quorumNumbers) internal virtual {
605+
function _forceDeregisterOperator(
606+
address operator,
607+
bytes memory quorumNumbers
608+
) internal virtual {
619609
allocationManager.deregisterFromOperatorSets(
620610
IAllocationManagerTypes.DeregisterParams({
621611
operator: operator,
@@ -712,32 +702,6 @@ contract SlashingRegistryCoordinator is
712702
);
713703
}
714704

715-
/**
716-
* @notice Updates the StakeRegistry's view of the operator's stake in one or more quorums.
717-
* For any quorums where the StakeRegistry finds the operator is under the configured minimum
718-
* stake, `quorumsToRemove` is returned and used to deregister the operator from those quorums
719-
* @dev does nothing if operator is not registered for any quorums.
720-
*/
721-
function _updateOperator(
722-
address operator,
723-
OperatorInfo memory operatorInfo,
724-
bytes memory quorumsToUpdate
725-
) internal {
726-
if (operatorInfo.status != OperatorStatus.REGISTERED) {
727-
return;
728-
}
729-
bytes32 operatorId = operatorInfo.operatorId;
730-
uint192 quorumsToRemove =
731-
stakeRegistry.updateOperatorStake(operator, operatorId, quorumsToUpdate);
732-
733-
if (!quorumsToRemove.isEmpty()) {
734-
_deregisterOperator({
735-
operator: operator,
736-
quorumNumbers: BitmapUtils.bitmapToBytesArray(quorumsToRemove)
737-
});
738-
}
739-
}
740-
741705
/**
742706
* @notice Returns the stake threshold required for an incoming operator to replace an existing operator
743707
* The incoming operator must have more stake than the return value.
@@ -950,7 +914,7 @@ contract SlashingRegistryCoordinator is
950914
function _afterCreateQuorum(
951915
uint8 quorumNumber
952916
) internal virtual {}
953-
917+
954918
/// @dev Hook to allow for any pre-register logic in `_registerOperator`
955919
function _beforeRegisterOperator(
956920
address operator,

0 commit comments

Comments
 (0)