From 21e6f2d7a76644415b257a014c925cec153a8477 Mon Sep 17 00:00:00 2001 From: gpsanant Date: Sat, 8 Feb 2025 14:35:45 -0800 Subject: [PATCH] feat: abstract internally --- src/SlashingRegistryCoordinator.sol | 74 +++++++++++++++-------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/SlashingRegistryCoordinator.sol b/src/SlashingRegistryCoordinator.sol index 75af45b0..22fafcfe 100644 --- a/src/SlashingRegistryCoordinator.sol +++ b/src/SlashingRegistryCoordinator.sol @@ -244,31 +244,11 @@ contract SlashingRegistryCoordinator is bytes memory quorumNumbers = currentBitmap.bitmapToBytesArray(); for (uint256 j = 0; j < quorumNumbers.length; j++) { // update the operator's stake for each quorum - uint8 quorumNumber = uint8(quorumNumbers[j]); - bool[] memory shouldBeDeregistered = stakeRegistry.updateOperatorsStake( - singleOperator, singleOperatorId, quorumNumber + _updateStakesAndDeregisterLoiterers( + singleOperator, + singleOperatorId, + uint8(quorumNumbers[j]) ); - - // whether the operator is registered in the core EigenLayer contract AllocationManager - bool registeredInCore = allocationManager.isMemberOfOperatorSet( - operators[i], OperatorSet({avs: accountIdentifier, id: uint32(quorumNumber)}) - ); - - // If the operator does not have the minimum stake, they need to be force deregistered. - // Additionally, it is possible for an operator to have deregistered from an OperatorSet - // in the core EigenLayer contract AllocationManager but not have the deregistration - // callback succeed here in `deregisterOperator` due to out of gas errors. If that is the case, - // we need to deregister the operator from the OperatorSet in this contract - if (shouldBeDeregistered[0] || !registeredInCore) { - // The operator should be deregistered from this quorum - bytes memory singleQuorumNumber = new bytes(1); - singleQuorumNumber[0] = quorumNumbers[j]; - _deregisterOperator({ - operator: operators[i], - quorumNumbers: singleQuorumNumber, - shouldForceDeregister: registeredInCore - }); - } } } } @@ -319,17 +299,11 @@ contract SlashingRegistryCoordinator is prevOperatorAddress = operator; } - bool[] memory shouldBeDeregistered = - stakeRegistry.updateOperatorsStake(currQuorumOperators, operatorIds, quorumNumber); - for (uint256 j = 0; j < currQuorumOperators.length; ++j) { - if (shouldBeDeregistered[j]) { - _deregisterOperator({ - operator: currQuorumOperators[j], - quorumNumbers: quorumNumbers[i:i + 1], - shouldForceDeregister: true - }); - } - } + _updateStakesAndDeregisterLoiterers( + currQuorumOperators, + operatorIds, + quorumNumber + ); // Update timestamp that all operators in quorum have been updated all at once quorumUpdateBlockNumber[quorumNumber] = block.number; @@ -658,6 +632,36 @@ contract SlashingRegistryCoordinator is ); } + function _updateStakesAndDeregisterLoiterers( + address[] memory operators, + bytes32[] memory operatorIds, + uint8 quorumNumber + ) internal { + bytes memory singleQuorumNumber = new bytes(1); + singleQuorumNumber[0] = bytes1(quorumNumber); + bool[] memory doesNotMeetStakeThreshold = + stakeRegistry.updateOperatorsStake(operators, operatorIds, quorumNumber); + for (uint256 j = 0; j < operators.length; ++j) { + // whether the operator is registered in the core EigenLayer contract AllocationManager + bool registeredInCore = allocationManager.isMemberOfOperatorSet( + operators[j], OperatorSet({avs: accountIdentifier, id: uint32(quorumNumber)}) + ); + + // If the operator does not have the minimum stake, they need to be force deregistered. + // Additionally, it is possible for an operator to have deregistered from an OperatorSet + // in the core EigenLayer contract AllocationManager but not have the deregistration + // callback succeed here in `deregisterOperator` due to out of gas errors. If that is the case, + // we need to deregister the operator from the OperatorSet in this contract + if (doesNotMeetStakeThreshold[j] || !registeredInCore) { + _deregisterOperator({ + operator: operators[j], + quorumNumbers: singleQuorumNumber, + shouldForceDeregister: true + }); + } + } + } + /** * @notice Checks if the caller is the ejector * @dev Reverts if the caller is not the ejector