-
Notifications
You must be signed in to change notification settings - Fork 84
/
IntegrationChecks.t.sol
421 lines (353 loc) · 17.6 KB
/
IntegrationChecks.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;
import "test/integration/IntegrationBase.t.sol";
import "test/integration/User.t.sol";
/// @notice Contract that provides utility functions to reuse common test blocks & checks
contract IntegrationChecks is IntegrationBase {
using BitmapUtils for *;
/*******************************************************************************
PRE-REGISTER CHECKS
*******************************************************************************/
function check_Never_Registered(
User operator
) internal {
_log("check_Never_Registered", operator);
// RegistryCoordinator
assert_HasNoOperatorInfo(operator,
"operator should have empty id and NEVER_REGISTERED status");
assert_EmptyQuorumBitmap(operator,
"operator already has bits in quorum bitmap");
// BLSApkRegistry
assert_NoRegisteredPubkey(operator,
"operator already has a registered pubkey");
// DelegationManager
assert_NotRegisteredToAVS(operator,
"operator should not be registered to the AVS");
}
/*******************************************************************************
POST-REGISTER CHECKS
*******************************************************************************/
function check_Register_State(
User operator,
bytes memory quorums
) internal {
_log("check_Register_State", operator);
// RegistryCoordinator
assert_HasOperatorInfoWithId(operator,
"operatorInfo should have operatorId");
assert_HasRegisteredStatus(operator,
"operatorInfo status should be REGISTERED");
assert_IsRegisteredForQuorums(operator, quorums,
"current operator bitmap should include quorums");
assert_Snap_Registered_ForQuorums(operator, quorums,
"operator did not register for all quorums");
// BLSApkRegistry
assert_HasRegisteredPubkey(operator,
"operator should have registered a pubkey");
assert_Snap_Added_QuorumApk(operator, quorums,
"operator pubkey should have been added to each quorum apk");
// StakeRegistry
assert_HasAtLeastMinimumStake(operator, quorums,
"operator should have at least the minimum stake in each quorum");
assert_Snap_Added_OperatorWeight(operator, quorums,
"failed to add operator weight to operator and total stake in each quorum");
// IndexRegistry
assert_Snap_Added_OperatorCount(quorums,
"total operator count should have increased for each quorum");
assert_Snap_Added_OperatorListEntry(operator, quorums,
"operator list should have one more entry");
// AVSDirectory
assert_IsRegisteredToAVS(operator,
"operator should be registered to AVS");
}
/// @dev Combines many checks of check_Register_State and check_Deregister_State
/// to account for quorums registered with churn
function check_Churned_State(
User incomingOperator,
User[] memory churnedOperators,
bytes memory churnedQuorums,
bytes memory standardQuorums
) internal {
_log("check_Churned_State", incomingOperator);
bytes memory combinedQuorums =
churnedQuorums
.orderedBytesArrayToBitmap()
.plus(standardQuorums.orderedBytesArrayToBitmap())
.bitmapToBytesArray();
// RegistryCoordinator
assert_HasOperatorInfoWithId(incomingOperator,
"operatorInfo should have operatorId");
assert_HasRegisteredStatus(incomingOperator,
"operatorInfo status should be REGISTERED");
assert_IsRegisteredForQuorums(incomingOperator, combinedQuorums,
"current operator bitmap should include quorums");
assert_Snap_Registered_ForQuorums(incomingOperator, combinedQuorums,
"operator did not register for all quorums");
// BLSApkRegistry
assert_HasRegisteredPubkey(incomingOperator,
"operator should have registered a pubkey");
assert_Snap_Added_QuorumApk(incomingOperator, standardQuorums,
"operator pubkey should have been added to standardQuorums apks");
assert_Snap_Churned_QuorumApk(incomingOperator, churnedOperators, churnedQuorums,
"operator pubkey should have been added and churned operator pubkeys should have been removed from apks");
// StakeRegistry
assert_HasAtLeastMinimumStake(incomingOperator, combinedQuorums,
"operator should have at least the minimum stake in each quorum");
assert_Snap_Added_OperatorWeight(incomingOperator, standardQuorums,
"failed to add operator weight to operator and total stake in standardQuorums");
assert_Snap_Churned_OperatorWeight(incomingOperator, churnedOperators, churnedQuorums,
"failed to add operator weight and remove churned weight from each quorum");
// IndexRegistry
assert_Snap_Added_OperatorCount(standardQuorums,
"total operator count should have increased for standardQuorums");
assert_Snap_Unchanged_OperatorCount(churnedQuorums,
"total operator count should be the same for churnedQuorums");
assert_Snap_Added_OperatorListEntry(incomingOperator, standardQuorums,
"operator list should have one more entry in standardQuorums");
assert_Snap_Replaced_OperatorListEntries(incomingOperator, churnedOperators, churnedQuorums,
"operator list should contain incoming operator and should not contain churned operators");
// AVSDirectory
assert_IsRegisteredToAVS(incomingOperator,
"operator should be registered to AVS");
// Check that churnedOperators are deregistered from churnedQuorums
for (uint i = 0; i < churnedOperators.length; i++) {
User churnedOperator = churnedOperators[i];
bytes memory churnedQuorum = new bytes(1);
churnedQuorum[0] = churnedQuorums[i];
// RegistryCoordinator
assert_HasOperatorInfoWithId(churnedOperator,
"churned operatorInfo should still have operatorId");
assert_NotRegisteredForQuorums(churnedOperator, churnedQuorum,
"churned operator bitmap should not include churned quorums");
assert_Snap_Deregistered_FromQuorums(churnedOperator, churnedQuorum,
"churned operator did not deregister from churned quorum");
// BLSApkRegistry
assert_HasRegisteredPubkey(churnedOperator,
"churned operator should still have a registered pubkey");
// StakeRegistry
assert_NoExistingStake(churnedOperator, churnedQuorum,
"operator should no longer have stake in any quorums");
}
}
/*******************************************************************************
BALANCE UPDATE CHECKS
*******************************************************************************/
/// @dev Validate state directly after the operator deposits into Eigenlayer core
/// We're mostly checking that nothing in the middleware contracts has changed,
/// except that the operator's weight shows a new value
function check_Deposit_State(
User operator,
bytes memory quorums,
IStrategy[] memory strategies,
uint[] memory tokenBalances
) internal {
_log("check_Deposit_State", operator);
// RegistryCoordinator
assert_Snap_Unchanged_OperatorInfo(operator,
"operator info should not have changed");
assert_Snap_Unchanged_QuorumBitmap(operator,
"operators quorum bitmap should not have changed");
// BLSApkRegistry
assert_Snap_Unchanged_QuorumApk(quorums,
"quorum apks should not have changed");
// StakeRegistry
assert_Snap_Increased_OperatorWeight(operator, quorums,
"operator weight should not have decreased after deposit");
assert_Snap_Unchanged_OperatorStake(operator, quorums,
"operator stake should be unchanged");
assert_Snap_Unchanged_TotalStake(quorums,
"total stake should be unchanged");
// IndexRegistry
assert_Snap_Unchanged_OperatorCount(quorums,
"operator counts should not have changed");
assert_Snap_Unchanged_OperatorListEntry(quorums,
"operator list should not have changed");
// Core
assert_Snap_Added_OperatorShares(operator, strategies, tokenBalances,
"operator should have additional stake");
}
/// @dev Checks that an operator's stake was successfully increased
/// NOTE: This method assumes (and checks) that the operator already
/// met the minimum stake before stake was added.
function check_DepositUpdate_State(
User operator,
bytes memory quorums,
uint96[] memory addedWeights
) internal {
_log("check_DepositUpdate_State", operator);
// RegistryCoordinator
assert_Snap_Unchanged_OperatorInfo(operator,
"operator info should not have changed");
assert_Snap_Unchanged_QuorumBitmap(operator,
"operators quorum bitmap should not have changed");
// BLSApkRegistry
assert_Snap_Unchanged_QuorumApk(quorums,
"quorum apks should not have changed");
// StakeRegistry
assert_HasAtLeastMinimumStake(operator, quorums,
"operator should have at least the minimum stake in each quorum");
assert_Snap_Unchanged_OperatorWeight(operator, quorums,
"updateOperators should not effect operator weight calculation");
assert_Snap_AddedWeightToStakes(operator, quorums, addedWeights,
"weights should have been added to operator and total stakes");
// IndexRegistry
assert_Snap_Unchanged_OperatorCount(quorums,
"total operator count should be unchanged for each quorum");
assert_Snap_Unchanged_OperatorListEntry(quorums,
"operator list should be unchanged for each quorum");
// AVSDirectory
assert_IsRegisteredToAVS(operator,
"operator should be registered to AVS");
}
/// @dev Validate state directly after the operator exits from Eigenlayer core (by queuing withdrawals)
function check_Withdraw_State(
User operator,
bytes memory quorums,
IStrategy[] memory strategies,
uint[] memory shares
) internal {
_log("check_Withdraw_State", operator);
// RegistryCoordinator
assert_Snap_Unchanged_OperatorInfo(operator,
"operator info should not have changed");
assert_Snap_Unchanged_QuorumBitmap(operator,
"operators quorum bitmap should not have changed");
// BLSApkRegistry
assert_Snap_Unchanged_QuorumApk(quorums,
"quorum apks should not have changed");
// StakeRegistry
assert_Snap_Decreased_OperatorWeight(operator, quorums,
"operator weight should not have increased after deposit");
assert_Snap_Unchanged_OperatorStake(operator, quorums,
"operator stake should be unchanged");
assert_Snap_Unchanged_TotalStake(quorums,
"total stake should be unchanged");
// IndexRegistry
assert_Snap_Unchanged_OperatorCount(quorums,
"operator counts should not have changed");
assert_Snap_Unchanged_OperatorListEntry(quorums,
"operator list should not have changed");
// Core
assert_Snap_Removed_OperatorShares(operator, strategies, shares,
"operator should have reduced stake");
}
/// @dev Validate state when, after exiting from the core contracts, updateOperators is called
/// We expect that the operator is completely deregistered.
/// NOTE: This is a combination of check_Deregister_State and check_CompleteDeregister_State
function check_WithdrawUpdate_State(
User operator,
bytes memory quorums
) internal {
_log("check_WithdrawUpdate_State", operator);
// RegistryCoordinator
assert_HasOperatorInfoWithId(operator,
"operatorInfo should still have operatorId");
assert_EmptyQuorumBitmap(operator,
"operator should not have any bits in bitmap");
assert_HasDeregisteredStatus(operator,
"operatorInfo status should be DEREGISTERED");
assert_Snap_Deregistered_FromQuorums(operator, quorums,
"operator did not deregister from all quorums");
// BLSApkRegistry
assert_HasRegisteredPubkey(operator,
"operator should still have a registered pubkey");
assert_Snap_Removed_QuorumApk(operator, quorums,
"operator pubkey should have been subtracted from each quorum apk");
// StakeRegistry
assert_NoExistingStake(operator, quorums,
"operator should no longer have stake in any quorums");
assert_Snap_Removed_TotalStake(operator, quorums,
"failed to remove operator weight from total stake for each quorum");
// IndexRegistry
assert_Snap_Reduced_OperatorCount(quorums,
"total operator count should have decreased for each quorum");
assert_Snap_Removed_OperatorListEntry(operator, quorums,
"operator list should have one fewer entry");
// AVSDirectory
assert_NotRegisteredToAVS(operator,
"operator should not be registered to the AVS");
}
/// @dev Used to validate a stake update after NO core balance changes occured
function check_NoUpdate_State(
User operator,
bytes memory quorums
) internal {
_log("check_NoChangeUpdate_State", operator);
// RegistryCoordinator
assert_Snap_Unchanged_OperatorInfo(operator,
"operator info should not have changed");
assert_Snap_Unchanged_QuorumBitmap(operator,
"operators quorum bitmap should not have changed");
// BLSApkRegistry
assert_Snap_Unchanged_QuorumApk(quorums,
"quorum apks should not have changed");
// StakeRegistry
assert_Snap_Unchanged_OperatorWeight(operator, quorums,
"operator weight should be unchanged");
assert_Snap_Unchanged_OperatorStake(operator, quorums,
"operator stake should be unchanged");
assert_Snap_Unchanged_TotalStake(quorums,
"total stake should be unchanged");
// IndexRegistry
assert_Snap_Unchanged_OperatorCount(quorums,
"total operator count should be unchanged for each quorum");
assert_Snap_Unchanged_OperatorListEntry(quorums,
"operator list should be unchanged for each quorum");
}
/*******************************************************************************
POST-DEREGISTER CHECKS
*******************************************************************************/
/// @dev Check that the operator correctly deregistered from some quorums
function check_Deregister_State(
User operator,
bytes memory quorums
) internal {
_log("check_Deregister_State", operator);
// RegistryCoordinator
assert_HasOperatorInfoWithId(operator,
"operatorInfo should still have operatorId");
assert_NotRegisteredForQuorums(operator, quorums,
"current operator bitmap should not include quorums");
assert_Snap_Deregistered_FromQuorums(operator, quorums,
"operator did not deregister from all quorums");
// BLSApkRegistry
assert_HasRegisteredPubkey(operator,
"operator should still have a registered pubkey");
assert_Snap_Removed_QuorumApk(operator, quorums,
"operator pubkey should have been subtracted from each quorum apk");
// StakeRegistry
assert_NoExistingStake(operator, quorums,
"operator should no longer have stake in any quorums");
assert_Snap_Removed_TotalStake(operator, quorums,
"failed to remove operator weight from total stake for each quorum");
// IndexRegistry
assert_Snap_Reduced_OperatorCount(quorums,
"total operator count should have decreased for each quorum");
assert_Snap_Removed_OperatorListEntry(operator, quorums,
"operator list should have one fewer entry");
}
/// @dev Check that the operator correctly deregistered from ALL their quorums
function check_CompleteDeregister_State(
User operator
) internal {
_log("check_CompleteDeregister_State", operator);
// RegistryCoordinator
assert_EmptyQuorumBitmap(operator,
"operator should not have any bits in bitmap");
assert_HasOperatorInfoWithId(operator,
"operatorInfo should still have operatorId");
assert_HasDeregisteredStatus(operator,
"operatorInfo status should be DEREGISTERED");
// AVSDirectory
assert_NotRegisteredToAVS(operator,
"operator should not be registered to the AVS");
}
/*******************************************************************************
UTIL METHODS
*******************************************************************************/
/// example output:
/// - check_Register_State(Operator0)
function _log(string memory s, User user) internal {
emit log(string.concat("- ", s, "(", user.NAME(), ")"));
}
}