forked from Layr-Labs/eigenlayer-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreRegistration.t.sol
221 lines (188 loc) · 8.56 KB
/
CoreRegistration.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;
import "../utils/MockAVSDeployer.sol";
import { AVSDirectory } from "eigenlayer-contracts/src/contracts/core/AVSDirectory.sol";
import { IAVSDirectory } from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import { DelegationManager } from "eigenlayer-contracts/src/contracts/core/DelegationManager.sol";
import { IDelegationManager } from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
contract Test_CoreRegistration is MockAVSDeployer {
// Contracts
DelegationManager public delegationManager;
// Operator info
uint256 operatorPrivateKey = 420;
address operator;
// Dummy vals used across tests
bytes32 emptySalt;
uint256 maxExpiry = type(uint256).max;
string emptyStringForMetadataURI;
function setUp() public {
_deployMockEigenLayerAndAVS();
// Deploy New DelegationManager
DelegationManager delegationManagerImplementation = new DelegationManager(strategyManagerMock, slasher, eigenPodManagerMock);
IStrategy[] memory initializeStrategiesToSetDelayBlocks = new IStrategy[](0);
uint256[] memory initializeWithdrawalDelayBlocks = new uint256[](0);
delegationManager = DelegationManager(
address(
new TransparentUpgradeableProxy(
address(delegationManagerImplementation),
address(proxyAdmin),
abi.encodeWithSelector(
DelegationManager.initialize.selector,
address(this),
pauserRegistry,
0, // 0 is initialPausedStatus
50400, // Initial withdrawal delay blocks
initializeStrategiesToSetDelayBlocks,
initializeWithdrawalDelayBlocks
)
)
)
);
// Deploy New AVS Directory
AVSDirectory avsDirectoryImplementation = new AVSDirectory(delegationManager);
avsDirectory = AVSDirectory(
address(
new TransparentUpgradeableProxy(
address(avsDirectoryImplementation),
address(proxyAdmin),
abi.encodeWithSelector(
AVSDirectory.initialize.selector,
address(this), // owner
pauserRegistry,
0 // 0 is initialPausedStatus
)
)
)
);
// Deploy New ServiceManager & RegistryCoordinator implementations
serviceManagerImplementation = new ServiceManagerMock(
avsDirectory,
registryCoordinator,
stakeRegistry
);
registryCoordinatorImplementation = new RegistryCoordinatorHarness(
serviceManager,
stakeRegistry,
blsApkRegistry,
indexRegistry
);
// Upgrade Registry Coordinator & ServiceManager
cheats.startPrank(proxyAdminOwner);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(registryCoordinator))),
address(registryCoordinatorImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(serviceManager))),
address(serviceManagerImplementation)
);
cheats.stopPrank();
// Set operator address
operator = cheats.addr(operatorPrivateKey);
blsApkRegistry.setBLSPublicKey(operator, defaultPubKey);
// Register operator to EigenLayer
cheats.prank(operator);
delegationManager.registerAsOperator(
IDelegationManager.OperatorDetails({
earningsReceiver: operator,
delegationApprover: address(0),
stakerOptOutWindowBlocks: 0
}),
emptyStringForMetadataURI
);
// Set operator weight in single quorum
bytes memory quorumNumbers = BitmapUtils.bitmapToBytesArray(MAX_QUORUM_BITMAP);
for (uint i = 0; i < quorumNumbers.length; i++) {
_setOperatorWeight(operator, uint8(quorumNumbers[i]), defaultStake);
}
}
function test_registerOperator_coreStateChanges() public {
bytes memory quorumNumbers = new bytes(1);
// Get operator signature
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = _getOperatorSignature(
operatorPrivateKey,
operator,
address(serviceManager),
emptySalt,
maxExpiry
);
// set operator as registered in Eigenlayer
delegationMock.setIsOperator(operator, true);
// Register operator
cheats.prank(operator);
registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, operatorSignature);
// Check operator is registered
IAVSDirectory.OperatorAVSRegistrationStatus operatorStatus = avsDirectory.avsOperatorStatus(address(serviceManager), operator);
assertEq(uint8(operatorStatus), uint8(IAVSDirectory.OperatorAVSRegistrationStatus.REGISTERED));
}
function test_deregisterOperator_coreStateChanges() public {
// Register operator
bytes memory quorumNumbers = new bytes(1);
_registerOperator(quorumNumbers);
// Deregister Operator
cheats.prank(operator);
registryCoordinator.deregisterOperator(quorumNumbers);
// Check operator is deregistered
IAVSDirectory.OperatorAVSRegistrationStatus operatorStatus = avsDirectory.avsOperatorStatus(address(serviceManager), operator);
assertEq(uint8(operatorStatus), uint8(IAVSDirectory.OperatorAVSRegistrationStatus.UNREGISTERED));
}
function test_deregisterOperator_notGloballyDeregistered() public {
// Register operator with all quorums
bytes memory quorumNumbers = BitmapUtils.bitmapToBytesArray(MAX_QUORUM_BITMAP);
emit log_named_bytes("quorumNumbers", quorumNumbers);
_registerOperator(quorumNumbers);
// Deregister Operator with single quorum
quorumNumbers = new bytes(1);
cheats.prank(operator);
registryCoordinator.deregisterOperator(quorumNumbers);
// Check operator is still registered
IAVSDirectory.OperatorAVSRegistrationStatus operatorStatus = avsDirectory.avsOperatorStatus(address(serviceManager), operator);
assertEq(uint8(operatorStatus), uint8(IAVSDirectory.OperatorAVSRegistrationStatus.REGISTERED));
}
function test_setMetadataURI_fail_notServiceManagerOwner() public {
require(operator != serviceManager.owner(), "bad test setup");
cheats.prank(operator);
cheats.expectRevert("Ownable: caller is not the owner");
serviceManager.updateAVSMetadataURI("Test MetadataURI");
}
event AVSMetadataURIUpdated(address indexed avs, string metadataURI);
function test_setMetadataURI() public {
address toPrankFrom = serviceManager.owner();
cheats.prank(toPrankFrom);
cheats.expectEmit(true, true, true, true);
emit AVSMetadataURIUpdated(address(serviceManager), "Test MetadataURI");
serviceManager.updateAVSMetadataURI("Test MetadataURI");
}
// Utils
function _registerOperator(bytes memory quorumNumbers) internal {
// Get operator signature
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = _getOperatorSignature(
operatorPrivateKey,
operator,
address(serviceManager),
emptySalt,
maxExpiry
);
// set operator as registered in Eigenlayer
delegationMock.setIsOperator(operator, true);
// Register operator
cheats.prank(operator);
registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, operatorSignature);
}
function _getOperatorSignature(
uint256 _operatorPrivateKey,
address operatorToSign,
address avs,
bytes32 salt,
uint256 expiry
) internal view returns (ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature) {
operatorSignature.salt = salt;
operatorSignature.expiry = expiry;
{
bytes32 digestHash = avsDirectory.calculateOperatorAVSRegistrationDigestHash(operatorToSign, avs, salt, expiry);
(uint8 v, bytes32 r, bytes32 s) = cheats.sign(_operatorPrivateKey, digestHash);
operatorSignature.signature = abi.encodePacked(r, s, v);
}
return operatorSignature;
}
}