Skip to content

Commit b5ed8be

Browse files
committed
refactor: remove sm calls
1 parent c016fd4 commit b5ed8be

12 files changed

+238
-203
lines changed

src/RegistryCoordinator.sol

+88-20
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,14 @@
22
pragma solidity ^0.8.27;
33

44
import {IPauserRegistry} from "eigenlayer-contracts/src/contracts/interfaces/IPauserRegistry.sol";
5-
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
6-
import {IStrategy } from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
7-
import {IAllocationManager, OperatorSet, IAllocationManagerTypes} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
8-
import {ISocketUpdater} from "./interfaces/ISocketUpdater.sol";
5+
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
96
import {IBLSApkRegistry} from "./interfaces/IBLSApkRegistry.sol";
10-
import {IStakeRegistry, StakeType} from "./interfaces/IStakeRegistry.sol";
7+
import {IStakeRegistry} from "./interfaces/IStakeRegistry.sol";
118
import {IIndexRegistry} from "./interfaces/IIndexRegistry.sol";
129
import {IServiceManager} from "./interfaces/IServiceManager.sol";
1310
import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";
1411

1512
import {BitmapUtils} from "./libraries/BitmapUtils.sol";
16-
import {BN254} from "./libraries/BN254.sol";
17-
import {SignatureCheckerLib} from "./libraries/SignatureCheckerLib.sol";
18-
import {QuorumBitmapHistoryLib} from "./libraries/QuorumBitmapHistoryLib.sol";
19-
import {AVSRegistrar} from "./AVSRegistrar.sol";
20-
21-
import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
22-
import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
23-
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
24-
25-
import {Pausable} from "eigenlayer-contracts/src/contracts/permissions/Pausable.sol";
26-
import {IAVSRegistrar} from "eigenlayer-contracts/src/contracts/interfaces/IAVSRegistrar.sol";
27-
2813
import {SlashingRegistryCoordinator} from "./SlashingRegistryCoordinator.sol";
2914

3015
/**
@@ -37,7 +22,9 @@ import {SlashingRegistryCoordinator} from "./SlashingRegistryCoordinator.sol";
3722
*/
3823
contract RegistryCoordinator is SlashingRegistryCoordinator, IRegistryCoordinator {
3924
using BitmapUtils for *;
40-
using BN254 for BN254.G1Point;
25+
26+
/// @notice the ServiceManager for this AVS, which forwards calls onto EigenLayer's core contracts
27+
IServiceManager public immutable serviceManager;
4128

4229
constructor(
4330
IServiceManager _serviceManager,
@@ -48,14 +35,15 @@ contract RegistryCoordinator is SlashingRegistryCoordinator, IRegistryCoordinato
4835
IPauserRegistry _pauserRegistry
4936
)
5037
SlashingRegistryCoordinator(
51-
_serviceManager,
5238
_stakeRegistry,
5339
_blsApkRegistry,
5440
_indexRegistry,
5541
_allocationManager,
5642
_pauserRegistry
5743
)
58-
{}
44+
{
45+
serviceManager = _serviceManager;
46+
}
5947

6048
/**
6149
*
@@ -192,4 +180,84 @@ contract RegistryCoordinator is SlashingRegistryCoordinator, IRegistryCoordinato
192180
// Enable operator sets mode
193181
isOperatorSetAVS = true;
194182
}
183+
184+
/**
185+
*
186+
* INTERNAL FUNCTIONS
187+
*
188+
*/
189+
190+
/**
191+
* @notice Register the operator for one or more quorums. This method updates the
192+
* operator's quorum bitmap, socket, and status, then registers them with each registry.
193+
*/
194+
function _registerOperator(
195+
address operator,
196+
bytes32 operatorId,
197+
bytes memory quorumNumbers,
198+
string memory socket,
199+
SignatureWithSaltAndExpiry memory operatorSignature
200+
) internal virtual returns (RegisterResults memory results) {
201+
/**
202+
* Get bitmap of quorums to register for and operator's current bitmap. Validate that:
203+
* - we're trying to register for at least 1 quorum
204+
* - the quorums we're registering for exist (checked against `quorumCount` in orderedBytesArrayToBitmap)
205+
* - the operator is not currently registered for any quorums we're registering for
206+
* Then, calculate the operator's new bitmap after registration
207+
*/
208+
uint192 quorumsToAdd =
209+
uint192(BitmapUtils.orderedBytesArrayToBitmap(quorumNumbers, quorumCount));
210+
uint192 currentBitmap = _currentOperatorBitmap(operatorId);
211+
require(
212+
!quorumsToAdd.isEmpty(), BitmapEmpty()
213+
);
214+
require(
215+
quorumsToAdd.noBitsInCommon(currentBitmap),
216+
AlreadyRegisteredForQuorums()
217+
);
218+
uint192 newBitmap = uint192(currentBitmap.plus(quorumsToAdd));
219+
220+
// Check that the operator can reregister if ejected
221+
require(
222+
lastEjectionTimestamp[operator] + ejectionCooldown < block.timestamp,
223+
CannotReregisterYet()
224+
);
225+
226+
/**
227+
* Update operator's bitmap, socket, and status. Only update operatorInfo if needed:
228+
* if we're `REGISTERED`, the operatorId and status are already correct.
229+
*/
230+
_updateOperatorBitmap({operatorId: operatorId, newBitmap: newBitmap});
231+
232+
emit OperatorSocketUpdate(operatorId, socket);
233+
234+
// If the operator wasn't registered for any quorums, update their status
235+
// and register them with this AVS in EigenLayer core (DelegationManager)
236+
if (_operatorInfo[operator].status != OperatorStatus.REGISTERED) {
237+
_operatorInfo[operator] =
238+
OperatorInfo({operatorId: operatorId, status: OperatorStatus.REGISTERED});
239+
240+
serviceManager.registerOperatorToAVS(operator, operatorSignature);
241+
emit OperatorRegistered(operator, operatorId);
242+
}
243+
244+
// Register the operator with the BLSApkRegistry, StakeRegistry, and IndexRegistry
245+
blsApkRegistry.registerOperator(operator, quorumNumbers);
246+
(results.operatorStakes, results.totalStakes) =
247+
stakeRegistry.registerOperator(operator, operatorId, quorumNumbers);
248+
results.numOperatorsPerQuorum = indexRegistry.registerOperator(operatorId, quorumNumbers);
249+
250+
return results;
251+
}
252+
253+
/// @dev Hook to allow for any post-deregister logic
254+
function _afterDeregisterOperator(address operator, bytes32 operatorId, bytes memory quorumNumbers, uint192 newBitmap) internal virtual override {
255+
// If the operator is no longer registered for any quorums, update their status and deregister
256+
// them from the AVS via the EigenLayer core contracts
257+
if (newBitmap.isEmpty()) {
258+
_operatorInfo[operator].status = OperatorStatus.DEREGISTERED;
259+
serviceManager.deregisterOperatorFromAVS(operator);
260+
emit OperatorDeregistered(operator, operatorId);
261+
}
262+
}
195263
}

0 commit comments

Comments
 (0)