diff --git a/src/contracts/core/AllocationManager.sol b/src/contracts/core/AllocationManager.sol index 8d4ede44e..db7ab4c1c 100644 --- a/src/contracts/core/AllocationManager.sol +++ b/src/contracts/core/AllocationManager.sol @@ -57,20 +57,21 @@ contract AllocationManager is require(0 < params.wadToSlash && params.wadToSlash <= WAD, InvalidWadToSlash()); OperatorSet memory operatorSet = OperatorSet({avs: msg.sender, operatorSetId: params.operatorSetId}); + IStrategy[] memory strategies = avsDirectory.getStrategiesInOperatorSet(operatorSet); // Assert that the provided strategies are all whitelisted for the given operator set. - require(avsDirectory.isOperatorSetStrategyBatch(operatorSet, params.strategies), InvalidStrategy()); + require(avsDirectory.isOperatorSetStrategyBatch(operatorSet, strategies), InvalidStrategy()); // Assert that the operator is slashable for the given operator set. require(avsDirectory.isOperatorSlashable(params.operator, operatorSet), InvalidOperator()); bytes32 operatorSetKey = _encodeOperatorSet(operatorSet); + uint256 strategiesLength = strategies.length; // Record the proportion of 1e18 that the operator's total shares that are being slashed - uint256[] memory wadSlashed = new uint256[](params.strategies.length); + uint256[] memory wadSlashed = new uint256[](strategiesLength); - for (uint256 i = 0; i < params.strategies.length; ++i) { - PendingMagnitudeInfo memory info = - _getPendingMagnitudeInfo(params.operator, params.strategies[i], operatorSetKey); + for (uint256 i = 0; i < strategiesLength; ++i) { + PendingMagnitudeInfo memory info = _getPendingMagnitudeInfo(params.operator, strategies[i], operatorSetKey); require(info.currentMagnitude > 0, OperatorNotAllocated()); @@ -88,7 +89,7 @@ contract AllocationManager is emit OperatorSetMagnitudeUpdated( params.operator, operatorSet, - params.strategies[i], + strategies[i], _addInt128(info.currentMagnitude, info.pendingDiff), info.effectTimestamp ); @@ -97,28 +98,28 @@ contract AllocationManager is // 3. Update the operator's allocation in storage _updateMagnitudeInfo({ operator: params.operator, - strategy: params.strategies[i], + strategy: strategies[i], operatorSetKey: operatorSetKey, info: info }); emit OperatorSetMagnitudeUpdated( - params.operator, operatorSet, params.strategies[i], info.currentMagnitude, uint32(block.timestamp) + params.operator, operatorSet, strategies[i], info.currentMagnitude, uint32(block.timestamp) ); // 4. Reduce the operator's max magnitude - uint64 maxMagnitudeBeforeSlash = _maxMagnitudeHistory[params.operator][params.strategies[i]].latest(); + uint64 maxMagnitudeBeforeSlash = _maxMagnitudeHistory[params.operator][strategies[i]].latest(); uint64 maxMagnitudeAfterSlash = maxMagnitudeBeforeSlash - slashedMagnitude; - _maxMagnitudeHistory[params.operator][params.strategies[i]].push({ + _maxMagnitudeHistory[params.operator][strategies[i]].push({ key: uint32(block.timestamp), value: maxMagnitudeAfterSlash }); - emit MaxMagnitudeUpdated(params.operator, params.strategies[i], maxMagnitudeAfterSlash); + emit MaxMagnitudeUpdated(params.operator, strategies[i], maxMagnitudeAfterSlash); // 5. Decrease operators shares in the DelegationManager delegation.decreaseOperatorShares({ operator: params.operator, - strategy: params.strategies[i], + strategy: strategies[i], previousTotalMagnitude: maxMagnitudeBeforeSlash, newTotalMagnitude: maxMagnitudeAfterSlash }); @@ -127,7 +128,7 @@ contract AllocationManager is wadSlashed[i] = uint256(slashedMagnitude).divWad(maxMagnitudeBeforeSlash); } - emit OperatorSlashed(params.operator, operatorSet, params.strategies, wadSlashed, params.description); + emit OperatorSlashed(params.operator, operatorSet, strategies, wadSlashed, params.description); } /// @inheritdoc IAllocationManager diff --git a/src/contracts/interfaces/IAllocationManager.sol b/src/contracts/interfaces/IAllocationManager.sol index cdaaa9369..f146d3d75 100644 --- a/src/contracts/interfaces/IAllocationManager.sol +++ b/src/contracts/interfaces/IAllocationManager.sol @@ -88,7 +88,6 @@ interface IAllocationManagerTypes { * @notice Struct containing parameters to slashing * @param operator the address to slash * @param operatorSetId the ID of the operatorSet the operator is being slashed on behalf of - * @param strategies the set of strategies to slash * @param wadToSlash the parts in 1e18 to slash, this will be proportional to the operator's * slashable stake allocation for the operatorSet * @param description the description of the slashing provided by the AVS for legibility @@ -96,7 +95,6 @@ interface IAllocationManagerTypes { struct SlashingParams { address operator; uint32 operatorSetId; - IStrategy[] strategies; uint256 wadToSlash; string description; } diff --git a/src/test/DevnetLifecycle.t.sol b/src/test/DevnetLifecycle.t.sol index 9f51c7476..86ed226de 100644 --- a/src/test/DevnetLifecycle.t.sol +++ b/src/test/DevnetLifecycle.t.sol @@ -213,13 +213,9 @@ contract Devnet_Lifecycle_Test is Test { } function _slashOperator() public { - // Get slashing params - IStrategy[] memory strategies = new IStrategy[](1); - strategies[0] = wethStrategy; IAllocationManagerTypes.SlashingParams memory slashingParams = IAllocationManagerTypes.SlashingParams({ operator: operator, operatorSetId: 1, - strategies: strategies, wadToSlash: 5e17, description: "test" }); diff --git a/src/test/unit/AllocationManagerUnit.t.sol b/src/test/unit/AllocationManagerUnit.t.sol index 520cda5b6..1a08524a6 100644 --- a/src/test/unit/AllocationManagerUnit.t.sol +++ b/src/test/unit/AllocationManagerUnit.t.sol @@ -173,13 +173,9 @@ contract AllocationManagerUnitTests is EigenLayerUnitTestSetup, IAllocationManag ) internal view returns (IAllocationManagerTypes.SlashingParams memory) { r = uint256(keccak256(abi.encodePacked(r, salt))); - IStrategy[] memory strategies = new IStrategy[](1); - strategies[0] = strategyMock; - return IAllocationManagerTypes.SlashingParams({ operator: operator, operatorSetId: uint32(r), - strategies: strategies, wadToSlash: bound(r, 1, 1e18), description: "test" }); @@ -193,13 +189,9 @@ contract AllocationManagerUnitTests is EigenLayerUnitTestSetup, IAllocationManag ) internal view returns (IAllocationManagerTypes.SlashingParams memory) { r = uint256(keccak256(abi.encodePacked(r, salt))); - IStrategy[] memory strategies = new IStrategy[](1); - strategies[0] = strategyMock; - return IAllocationManagerTypes.SlashingParams({ operator: operator, operatorSetId: operatorSetId, - strategies: strategies, wadToSlash: bound(r, 1, 1e18), description: "test" }); @@ -608,7 +600,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 1e18, description: "test" }); @@ -643,7 +634,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 25e16, description: "test" }); @@ -664,7 +654,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests emit OperatorSlashed( slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), - slashingParams.strategies, + _strategyMockArray(), wadSlashed, slashingParams.description ); @@ -730,7 +720,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests emit OperatorSlashed( slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), - slashingParams.strategies, + _strategyMockArray(), wadSlashed, slashingParams.description ); @@ -782,7 +772,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 50e16, description: "test" }); @@ -801,7 +790,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests cheats.expectEmit(true, true, true, true, address(allocationManager)); emit MaxMagnitudeUpdated(defaultOperator, strategyMock, maxMagnitudeAfterSlash); cheats.expectEmit(true, true, true, true, address(allocationManager)); - emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description); + emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId),_strategyMockArray(), wadSlashed, slashingParams.description); cheats.prank(defaultAVS); allocationManager.slashOperator(slashingParams); @@ -852,7 +841,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 25e16, description: "test" }); @@ -875,7 +863,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests cheats.expectEmit(true, true, true, true, address(allocationManager)); uint256[] memory wadSlashed = new uint256[](1); wadSlashed[0] = 25e16; - emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description); + emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description); cheats.prank(defaultAVS); allocationManager.slashOperator(slashingParams); @@ -911,7 +899,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 1e18, description: "test" }); @@ -951,7 +938,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 1e18, description: "test" }); @@ -969,7 +955,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests cheats.expectEmit(true, true, true, true, address(allocationManager)); uint256[] memory wadSlashed = new uint256[](1); wadSlashed[0] = 1e18; - emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description); + emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description); cheats.prank(defaultAVS); allocationManager.slashOperator(slashingParams); @@ -1016,7 +1002,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 25e16, description: "test" }); @@ -1035,7 +1020,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests cheats.expectEmit(true, true, true, true, address(allocationManager)); uint256[] memory wadSlashed = new uint256[](1); wadSlashed[0] = 125e15; - emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description); + emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description); cheats.prank(defaultAVS); allocationManager.slashOperator(slashingParams); @@ -1102,7 +1087,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 5e17, description: "test" }); @@ -1168,7 +1152,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: strategiesToSlash, wadToSlash: 6e17, description: "test" }); @@ -1201,7 +1184,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests wadSlashed[0] = 3e17; wadSlashed[1] = 6e17; cheats.expectEmit(true, true, true, true, address(allocationManager)); - emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description); + emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description); // Slash Operator cheats.prank(defaultAVS); @@ -1252,7 +1235,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests SlashingParams memory slashingParams = SlashingParams({ operator: defaultOperator, operatorSetId: allocations[0].operatorSets[0].operatorSetId, - strategies: _strategyMockArray(), wadToSlash: 5e17, description: "test" });