Skip to content

Commit 4fc9f21

Browse files
wadealexcMichael
authored andcommitted
test: slash invariants (#1083)
**Motivation:** Improve slashing invariants in integration tests **Modifications:** Adds `check_Base_Slashing_State`, and implements several checks used within **Result:** Slashing invariants check all manner of state changes in the ALM and delegation. --------- Co-authored-by: Michael <[email protected]>
1 parent ffda98f commit 4fc9f21

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/test/integration/IntegrationChecks.t.sol

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,18 +451,6 @@ contract IntegrationCheckUtils is IntegrationBase {
451451
assert_Snap_Unchanged_AllocatableMagnitude(operator, allStrats, "should not have updated allocatable magnitude");
452452
}
453453

454-
// /// @dev Checks invariants for registration for a variety of allocation states
455-
// ///
456-
// function check_Registration_State(
457-
// User operator,
458-
// OperatorSet memory operatorSet,
459-
// IStrategy[] memory unallocated,
460-
// AllocateParams memory pending,
461-
// AllocateParams memory active
462-
// ) internal {
463-
// check_Base_Registration_State(operator, operatorSet);
464-
// }
465-
466454
/// @dev Check invariants for registerForOperatorSets given a set of strategies
467455
/// for which NO allocation exists (currentMag/pendingDiff are 0)
468456
/// @param unallocated For the given operatorSet, a list of strategies for which NO allocation exists
@@ -839,6 +827,37 @@ contract IntegrationCheckUtils is IntegrationBase {
839827
check_ActiveModification_State(operator, deallocateParams);
840828
}
841829

830+
/*******************************************************************************
831+
ALM - SLASHING
832+
*******************************************************************************/
833+
834+
function check_Base_Slashing_State(
835+
User operator,
836+
AllocateParams memory allocateParams,
837+
SlashingParams memory slashParams
838+
) internal {
839+
OperatorSet memory operatorSet = allocateParams.operatorSet;
840+
841+
check_MaxMag_Invariants(operator);
842+
check_IsSlashable_State(operator, operatorSet, allocateParams.strategies);
843+
844+
// Slashing SHOULD change max magnitude and current allocation
845+
assert_Snap_Slashed_MaxMagnitude(operator, slashParams, "slash should lower max magnitude");
846+
assert_Snap_Slashed_EncumberedMagnitude(operator, slashParams, "slash should lower max magnitude");
847+
assert_Snap_Slashed_AllocatedStake(operator, operatorSet, slashParams, "slash should lower allocated stake");
848+
assert_Snap_Slashed_SlashableStake(operator, operatorSet, slashParams, "slash should lower slashable stake");
849+
assert_Snap_Slashed_OperatorShares(operator, slashParams, "slash should remove operator shares");
850+
assert_Snap_Slashed_Allocation(operator, operatorSet, slashParams, "slash should reduce current magnitude");
851+
assert_Snap_Increased_BurnableShares(operator, slashParams, "slash should increase burnable shares");
852+
853+
// Slashing SHOULD NOT change allocatable magnitude, registration, and slashability status
854+
assert_Snap_Unchanged_AllocatableMagnitude(operator, allStrats, "slashing should not change allocatable magnitude");
855+
assert_Snap_Unchanged_Registration(operator, operatorSet, "slash should not change registration status");
856+
assert_Snap_Unchanged_Slashability(operator, operatorSet, "slash should not change slashability status");
857+
assert_Snap_Unchanged_AllocatedSets(operator, "should not have updated allocated sets");
858+
assert_Snap_Unchanged_AllocatedStrats(operator, operatorSet, "should not have updated allocated strategies");
859+
}
860+
842861
// TODO: improvement needed
843862

844863
/// @dev Run a method as if the user's allocation delay had passed

src/test/integration/tests/SlashingWithdrawals.t.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ contract Integration_ALMSlashBase is IntegrationCheckUtils {
1515
uint[] initTokenBalances;
1616
uint[] initDepositShares;
1717

18-
1918
/// Shared setup:
2019
///
2120
/// 1. Generate staker, operator, and AVS
@@ -129,6 +128,7 @@ contract Integration_InitSlash is Integration_ALMSlashBase {
129128
}
130129

131130
contract Integration_SlashingWithdrawals is Integration_ALMSlashBase {
131+
<<<<<<< HEAD
132132

133133
function testFuzz_slash_undelegate_completeAsTokens(
134134
uint24 _random
@@ -244,6 +244,8 @@ contract Integration_SlashingWithdrawals is Integration_ALMSlashBase {
244244
assert_Snap_Allocations_Modified(
245245
operator, allocateParams, true, "operator allocations should be updated after delay"
246246
);
247+
=======
248+
>>>>>>> b6c49a95 (test: slash invariants (#1083))
247249

248250
function testFuzz_slash_undelegate_completeAsTokens(
249251
uint24 _random

0 commit comments

Comments
 (0)