Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slashing: fully slashed strategies #850

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

8sunyuan
Copy link
Collaborator

@8sunyuan 8sunyuan commented Oct 22, 2024

This handles edge cases of 100% slashed scenarios where an operator is fully slashed for a strategy(maxMagnitude = 0)
and also when a native restaker has had enough accrued delta decreases in their beacon chain shares to the point where their beaconChainScalingFactor is 0. Either of these situations will result in a divide by 0 and has more transparent error revert checks when this occurs.

Changes:

  • Undelegation from a fully slashed operator is also fixed now as the queue withdrawal is ignored and deposit shares are fully decreased.
  • Delegated deposits (increaseDelegatedShares) to an operator for a strategy that is fully slashed will revert
  • Queue withdrawals for a strategy that is fully slashed will revert

Note: Complete queued withdrawals are unchanged but perhaps should revert if they were slashed during queue delay. It would avoid wasted gas for withdrawing 0 shares.

Tests:

  • As staker delegating to an operator who is slashed 100% for a strategy will revert
  • As existing staker delegated to an operator who is slashed 100% for a strategy, depositing more shares(increaseDelegatedShares) will revert
  • As existing staker with withdrawable shares delegated to an operator, after the operator was slashed 100%, the staker no longer has withdrawable shares
  • As staker delegated to operator who was slashed 100% for a strategy, the staker can still increaseDelegatedShares for other strategies with non-zero maxMagnitude for the operator.
  • Staker can undelegate even when slashed 100% (strategy that is 100% slashed is not queue withdrawn)
  • Staker cannot queue withdrawal for strategy slashed 100%

Copy link

Reading tracefile ./lcov.info.pruned
                                        |Lines       |Functions  |Branches    
Filename                                  |Rate     Num|Rate    Num|Rate     Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                     |96.4%    112|93.8%    32|    -      0
core/AllocationManager.sol                |90.1%    151|90.0%    20|    -      0
core/DelegationManager.sol                |91.7%    193|82.1%    39|    -      0
core/RewardsCoordinator.sol               |94.3%    123|87.1%    31|    -      0
core/StrategyManager.sol                  |97.0%     67|90.9%    22|    -      0
libraries/BeaconChainProofs.sol           | 100%     22| 100%    11|    -      0
libraries/BytesLib.sol                    | 0.0%    156| 0.0%    14|    -      0
libraries/Endian.sol                      | 100%      2| 100%     1|    -      0
libraries/Merkle.sol                      | 100%     38| 100%     5|    -      0
libraries/SlashingLib.sol                 | 100%     19| 100%    12|    -      0
libraries/Snapshots.sol                   |88.0%     25|85.7%     7|    -      0
mixins/SignatureUtils.sol                 | 100%      6| 100%     5|    -      0
permissions/Pausable.sol                  |95.7%     23|90.9%    11|    -      0
permissions/PauserRegistry.sol            | 100%     12| 100%     6|    -      0
pods/EigenPod.sol                         |96.2%    131|96.2%    26|    -      0
pods/EigenPodManager.sol                  |80.3%     66|93.3%    15|    -      0
strategies/EigenStrategy.sol              | 0.0%     10| 0.0%     5|    -      0
strategies/StrategyBase.sol               |90.9%     44|78.9%    19|    -      0
strategies/StrategyBaseTVLLimits.sol      | 100%     12| 100%     6|    -      0
strategies/StrategyFactory.sol            | 100%     32| 100%     8|    -      0
token/BackingEigen.sol                    |83.3%     30|69.2%    13|    -      0
token/Eigen.sol                           |45.0%     40|61.5%    13|    -      0
================================================================================
                                  Total:|80.0%   1314|83.5%   321|    -      0

Base automatically changed from slashing-cleanup to slashing-magnitudes October 23, 2024 21:01
Copy link

Reading tracefile ./lcov.info.pruned
                                        |Lines       |Functions  |Branches    
Filename                                  |Rate     Num|Rate    Num|Rate     Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                     |96.4%    112|93.8%    32|    -      0
core/AllocationManager.sol                |88.9%    153|85.7%    21|    -      0
core/DelegationManager.sol                |91.7%    193|82.1%    39|    -      0
core/RewardsCoordinator.sol               |94.3%    123|87.1%    31|    -      0
core/StrategyManager.sol                  |97.0%     67|90.9%    22|    -      0
libraries/BeaconChainProofs.sol           | 100%     22| 100%    11|    -      0
libraries/BytesLib.sol                    | 0.0%    156| 0.0%    14|    -      0
libraries/Endian.sol                      | 100%      2| 100%     1|    -      0
libraries/Merkle.sol                      | 100%     38| 100%     5|    -      0
libraries/SlashingLib.sol                 | 100%     19| 100%    12|    -      0
libraries/Snapshots.sol                   |88.0%     25|85.7%     7|    -      0
mixins/SignatureUtils.sol                 | 100%      6| 100%     5|    -      0
permissions/Pausable.sol                  |95.7%     23|90.9%    11|    -      0
permissions/PauserRegistry.sol            | 100%     12| 100%     6|    -      0
pods/EigenPod.sol                         |96.2%    131|96.2%    26|    -      0
pods/EigenPodManager.sol                  |80.3%     66|93.3%    15|    -      0
strategies/EigenStrategy.sol              | 0.0%     10| 0.0%     5|    -      0
strategies/StrategyBase.sol               |90.9%     44|78.9%    19|    -      0
strategies/StrategyBaseTVLLimits.sol      | 100%     12| 100%     6|    -      0
strategies/StrategyFactory.sol            | 100%     32| 100%     8|    -      0
token/BackingEigen.sol                    |83.3%     30|69.2%    13|    -      0
token/Eigen.sol                           |45.0%     40|61.5%    13|    -      0
================================================================================
                                  Total:|79.9%   1316|83.2%   322|    -      0

Copy link
Collaborator

@ypatil12 ypatil12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good for strategies, will need to figure out the EP edge cases in separate PR

* if this is the beaconChain strategy
* @return bool True if the maxMagnitude is not 0 and the staker's beaconChainScalingFactor is not 0
*/
function _verifyMaxMagnitudeAndScalingFactor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Perhaps call this hasNonZeroScalingFactors since it returns a bool

/// Slashing

/// @dev Thrown when an operator has been fully slashed(maxMagnitude is 0) for a strategy.
/// or if the staker has had been natively slashed to the point of their beaconChainScalingFactor equalling 0.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add to documentation somewhere that:

  1. A staker can always redelegate for any strategy if the maxMagnitude is 0
  2. A staker can never delegate for beacon chain strategy if they are fully slashed on the beacon chain.

@8sunyuan 8sunyuan merged commit b30e1c7 into slashing-magnitudes Oct 28, 2024
10 of 11 checks passed
@8sunyuan 8sunyuan deleted the fully-slashed-strategies branch October 28, 2024 14:33
Copy link

Reading tracefile ./lcov.info.pruned
                                        |Lines       |Functions  |Branches    
Filename                                  |Rate     Num|Rate    Num|Rate     Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                     |96.4%    112|93.8%    32|    -      0
core/AllocationManager.sol                |88.9%    153|85.7%    21|    -      0
core/DelegationManager.sol                |91.7%    193|82.1%    39|    -      0
core/RewardsCoordinator.sol               |94.3%    123|87.1%    31|    -      0
core/StrategyManager.sol                  |97.0%     67|90.9%    22|    -      0
libraries/BeaconChainProofs.sol           | 100%     22| 100%    11|    -      0
libraries/BytesLib.sol                    | 0.0%    156| 0.0%    14|    -      0
libraries/Endian.sol                      | 100%      2| 100%     1|    -      0
libraries/Merkle.sol                      | 100%     38| 100%     5|    -      0
libraries/SlashingLib.sol                 | 100%     19| 100%    12|    -      0
libraries/Snapshots.sol                   |88.0%     25|85.7%     7|    -      0
mixins/SignatureUtils.sol                 | 100%      6| 100%     5|    -      0
permissions/Pausable.sol                  |95.7%     23|90.9%    11|    -      0
permissions/PauserRegistry.sol            | 100%     12| 100%     6|    -      0
pods/EigenPod.sol                         |96.2%    131|96.2%    26|    -      0
pods/EigenPodManager.sol                  |80.3%     66|93.3%    15|    -      0
strategies/EigenStrategy.sol              | 0.0%     10| 0.0%     5|    -      0
strategies/StrategyBase.sol               |90.9%     44|78.9%    19|    -      0
strategies/StrategyBaseTVLLimits.sol      | 100%     12| 100%     6|    -      0
strategies/StrategyFactory.sol            | 100%     32| 100%     8|    -      0
token/BackingEigen.sol                    |83.3%     30|69.2%    13|    -      0
token/Eigen.sol                           |45.0%     40|61.5%    13|    -      0
================================================================================
                                  Total:|79.9%   1316|83.2%   322|    -      0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants