Skip to content

Commit

Permalink
feat: abstract internally
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsanant committed Feb 8, 2025
1 parent 4f3852a commit 21e6f2d
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions src/SlashingRegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21e6f2d

Please sign in to comment.