Skip to content

Commit 8e44822

Browse files
ypatil120xClandestine
authored andcommitted
chore: remove dm/alm code size optimizations (#1398)
**Motivation:** We have several code size optimizations in the DM/ALM. These are not needed anymore with the ownable deprecation. We can add in future upgrade if we want. **Modifications:** Remove all internal `_check` and modifiers. Make `slashOperatorShares` in the DM return to the original non-arrayified method. **Result:** Smaller code diff for redistribution.
1 parent 30cd7fc commit 8e44822

File tree

5 files changed

+163
-347
lines changed

5 files changed

+163
-347
lines changed

src/contracts/core/AllocationManager.sol

Lines changed: 29 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,11 @@ contract AllocationManager is
6363
function slashOperator(
6464
address avs,
6565
SlashingParams calldata params
66-
)
67-
external
68-
onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING)
69-
checkCanCall(avs)
70-
returns (uint256 slashId, uint256[] memory shares)
71-
{
66+
) external onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING) checkCanCall(avs) returns (uint256, uint256[] memory) {
7267
// Check that the operator set exists and the operator is registered to it
7368
OperatorSet memory operatorSet = OperatorSet(avs, params.operatorSetId);
74-
75-
_checkArrayLengthsMatch(params.strategies.length, params.wadsToSlash.length);
76-
_checkIsOperatorSet(operatorSet);
77-
69+
require(params.strategies.length == params.wadsToSlash.length, InputArrayLengthMismatch());
70+
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
7871
require(isOperatorSlashable(params.operator, operatorSet), OperatorNotSlashable());
7972

8073
return _slashOperator(params, operatorSet);
@@ -98,15 +91,15 @@ contract AllocationManager is
9891
}
9992

10093
for (uint256 i = 0; i < params.length; i++) {
101-
_checkArrayLengthsMatch(params[i].strategies.length, params[i].newMagnitudes.length);
94+
require(params[i].strategies.length == params[i].newMagnitudes.length, InputArrayLengthMismatch());
10295

10396
// Check that the operator set exists and get the operator's registration status
10497
// Operators do not need to be registered for an operator set in order to allocate
10598
// slashable magnitude to the set. In fact, it is expected that operators will
10699
// allocate magnitude before registering, as AVS's will likely only accept
107100
// registrations from operators that are already slashable.
108101
OperatorSet memory operatorSet = params[i].operatorSet;
109-
_checkIsOperatorSet(operatorSet);
102+
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
110103

111104
bool _isOperatorSlashable = isOperatorSlashable(operator, operatorSet);
112105

@@ -161,7 +154,7 @@ contract AllocationManager is
161154
_updateAllocationInfo(operator, operatorSet.key(), strategy, info, allocation);
162155

163156
// 6. Emit an event for the updated allocation
164-
_emitAllocationUpdated(
157+
emit AllocationUpdated(
165158
operator,
166159
operatorSet,
167160
strategy,
@@ -178,7 +171,7 @@ contract AllocationManager is
178171
IStrategy[] calldata strategies,
179172
uint16[] calldata numToClear
180173
) external onlyWhenNotPaused(PAUSED_MODIFY_ALLOCATIONS) {
181-
_checkArrayLengthsMatch(strategies.length, numToClear.length);
174+
require(strategies.length == numToClear.length, InputArrayLengthMismatch());
182175
for (uint256 i = 0; i < strategies.length; ++i) {
183176
_clearDeallocationQueue({operator: operator, strategy: strategies[i], numToClear: numToClear[i]});
184177
}
@@ -190,12 +183,12 @@ contract AllocationManager is
190183
RegisterParams calldata params
191184
) external onlyWhenNotPaused(PAUSED_OPERATOR_SET_REGISTRATION_AND_DEREGISTRATION) checkCanCall(operator) {
192185
// Check if the operator has registered.
193-
_checkIsOperator(operator);
186+
require(delegation.isOperator(operator), InvalidOperator());
194187

195188
for (uint256 i = 0; i < params.operatorSetIds.length; i++) {
196189
// Check the operator set exists and the operator is not currently registered to it
197190
OperatorSet memory operatorSet = OperatorSet(params.avs, params.operatorSetIds[i]);
198-
_checkIsOperatorSet(operatorSet);
191+
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
199192
require(!isOperatorSlashable(operator, operatorSet), AlreadyMemberOfSet());
200193

201194
// Add operator to operator set
@@ -221,7 +214,7 @@ contract AllocationManager is
221214
for (uint256 i = 0; i < params.operatorSetIds.length; i++) {
222215
// Check the operator set exists and the operator is registered to it
223216
OperatorSet memory operatorSet = OperatorSet(params.avs, params.operatorSetIds[i]);
224-
_checkIsOperatorSet(operatorSet);
217+
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
225218
require(registrationStatus[params.operator][operatorSet.key()].registered, NotMemberOfSet());
226219

227220
// Remove operator from operator set
@@ -245,7 +238,7 @@ contract AllocationManager is
245238
function setAllocationDelay(address operator, uint32 delay) external {
246239
if (msg.sender != address(delegation)) {
247240
_checkCanCall(operator);
248-
_checkIsOperator(operator);
241+
require(delegation.isOperator(operator), InvalidOperator());
249242
}
250243
_setAllocationDelay(operator, delay);
251244
}
@@ -267,7 +260,7 @@ contract AllocationManager is
267260

268261
/// @inheritdoc IAllocationManager
269262
function createOperatorSets(address avs, CreateSetParams[] calldata params) external checkCanCall(avs) {
270-
_checkAVSExists(avs);
263+
require(_avsRegisteredMetadata[avs], NonexistentAVSMetadata());
271264
for (uint256 i = 0; i < params.length; i++) {
272265
_createOperatorSet(avs, params[i], DEFAULT_BURN_ADDRESS);
273266
}
@@ -279,8 +272,8 @@ contract AllocationManager is
279272
CreateSetParams[] calldata params,
280273
address[] calldata redistributionRecipients
281274
) external checkCanCall(avs) {
282-
_checkArrayLengthsMatch(params.length, redistributionRecipients.length);
283-
_checkAVSExists(avs);
275+
require(params.length == redistributionRecipients.length, InputArrayLengthMismatch());
276+
require(_avsRegisteredMetadata[avs], NonexistentAVSMetadata());
284277
for (uint256 i = 0; i < params.length; i++) {
285278
require(redistributionRecipients[i] != address(0), InputAddressZero());
286279
_createOperatorSet(avs, params[i], redistributionRecipients[i]);
@@ -294,7 +287,7 @@ contract AllocationManager is
294287
IStrategy[] calldata strategies
295288
) external checkCanCall(avs) {
296289
OperatorSet memory operatorSet = OperatorSet(avs, operatorSetId);
297-
_checkIsOperatorSet(operatorSet);
290+
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
298291
for (uint256 i = 0; i < strategies.length; i++) {
299292
_addStrategyToOperatorSet(
300293
operatorSet, strategies[i], isRedistributingOperatorSet(OperatorSet(avs, operatorSetId))
@@ -309,7 +302,7 @@ contract AllocationManager is
309302
IStrategy[] calldata strategies
310303
) external checkCanCall(avs) {
311304
OperatorSet memory operatorSet = OperatorSet(avs, operatorSetId);
312-
_checkIsOperatorSet(operatorSet);
305+
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
313306
bytes32 operatorSetKey = operatorSet.key();
314307
for (uint256 i = 0; i < strategies.length; i++) {
315308
require(_operatorSetStrategies[operatorSetKey].remove(address(strategies[i])), StrategyNotInOperatorSet());
@@ -327,13 +320,11 @@ contract AllocationManager is
327320
OperatorSet memory operatorSet
328321
) internal returns (uint256 slashId, uint256[] memory shares) {
329322
uint256[] memory wadSlashed = new uint256[](params.strategies.length);
323+
shares = new uint256[](params.strategies.length);
330324

331325
// Increment the slash count for the operator set.
332326
slashId = ++_slashCount[operatorSet.key()];
333327

334-
uint64[] memory prevMaxMagnitudes = new uint64[](params.strategies.length);
335-
uint64[] memory newMaxMagnitudes = new uint64[](params.strategies.length);
336-
337328
// For each strategy in the operator set, slash any existing allocation
338329
for (uint256 i = 0; i < params.strategies.length; i++) {
339330
// Check that `strategies` is in ascending order.
@@ -378,7 +369,7 @@ contract AllocationManager is
378369
uint64(uint256(uint128(-allocation.pendingDiff)).mulWadRoundUp(params.wadsToSlash[i]));
379370
allocation.pendingDiff += int128(uint128(slashedPending));
380371

381-
_emitAllocationUpdated(
372+
emit AllocationUpdated(
382373
params.operator,
383374
operatorSet,
384375
params.strategies[i],
@@ -390,26 +381,24 @@ contract AllocationManager is
390381
// 5. Update state
391382
_updateAllocationInfo(params.operator, operatorSet.key(), params.strategies[i], info, allocation);
392383

393-
_emitAllocationUpdated(
384+
// Emit an event for the updated allocation
385+
emit AllocationUpdated(
394386
params.operator, operatorSet, params.strategies[i], allocation.currentMagnitude, uint32(block.number)
395387
);
396388

397389
_updateMaxMagnitude(params.operator, params.strategies[i], info.maxMagnitude);
398390

399-
prevMaxMagnitudes[i] = prevMaxMagnitude;
400-
newMaxMagnitudes[i] = info.maxMagnitude;
391+
// 6. Slash operators shares in the DelegationManager
392+
shares[i] = delegation.slashOperatorShares({
393+
operator: params.operator,
394+
operatorSet: operatorSet,
395+
slashId: slashId,
396+
strategy: params.strategies[i],
397+
prevMaxMagnitude: prevMaxMagnitude,
398+
newMaxMagnitude: info.maxMagnitude
399+
});
401400
}
402401

403-
// 6. Slash operators shares in the DelegationManager
404-
shares = delegation.slashOperatorShares({
405-
operator: params.operator,
406-
operatorSet: operatorSet,
407-
slashId: slashId,
408-
strategies: params.strategies,
409-
prevMaxMagnitudes: prevMaxMagnitudes,
410-
newMaxMagnitudes: newMaxMagnitudes
411-
});
412-
413402
emit OperatorSlashed(params.operator, operatorSet, params.strategies, wadSlashed, params.description);
414403
}
415404

@@ -673,41 +662,6 @@ contract AllocationManager is
673662
return uint256(int256(int128(uint128(a)) + b)).toUint64();
674663
}
675664

676-
/// @dev Reverts if the operator set does not exist.
677-
function _checkIsOperatorSet(
678-
OperatorSet memory operatorSet
679-
) internal view {
680-
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
681-
}
682-
683-
/// @dev Reverts if the provided arrays have different lengths.
684-
function _checkArrayLengthsMatch(uint256 left, uint256 right) internal pure {
685-
require(left == right, InputArrayLengthMismatch());
686-
}
687-
688-
/// @dev Reverts if the operator is not registered.
689-
function _checkIsOperator(
690-
address operator
691-
) internal view {
692-
require(delegation.isOperator(operator), InvalidOperator());
693-
}
694-
695-
function _checkAVSExists(
696-
address avs
697-
) internal view {
698-
require(_avsRegisteredMetadata[avs], NonexistentAVSMetadata());
699-
}
700-
701-
function _emitAllocationUpdated(
702-
address operator,
703-
OperatorSet memory operatorSet,
704-
IStrategy strategy,
705-
uint64 currentMagnitude,
706-
uint32 effectBlock
707-
) internal {
708-
emit AllocationUpdated(operator, operatorSet, strategy, currentMagnitude, effectBlock);
709-
}
710-
711665
/**
712666
* @notice Helper function to check if an operator is redistributable from a list of operator sets
713667
* @param operator The operator to check

0 commit comments

Comments
 (0)