60151 sc high double reduction of effective stake can lead to stuck delegations
Description
Brief / Intro
Vulnerability Details
function requestDelegationExit(
uint256 _tokenId
) external whenNotPaused onlyTokenOwner(_tokenId) nonReentrant {
StargateStorage storage $ = _getStargateStorage();
uint256 delegationId = $.delegationIdByTokenId[_tokenId];
if (delegationId == 0) {
revert DelegationNotFound(_tokenId);
}
Delegation memory delegation = _getDelegationDetails($, _tokenId);
if (delegation.status == DelegationStatus.PENDING) {
// if the delegation is pending, we can exit it immediately
// by withdrawing the VET from the protocol
$.protocolStakerContract.withdrawDelegation(delegationId);
emit DelegationWithdrawn(
_tokenId,
delegation.validator,
delegationId,
delegation.stake,
$.stargateNFTContract.getTokenLevel(_tokenId)
);
// and reset the mappings in storage regarding this delegation
_resetDelegationDetails($, _tokenId);
} else if (delegation.status == DelegationStatus.ACTIVE) {
// If the delegation is active, we need to signal the exit to the protocol and wait for the end of the period
// We do not allow the user to request an exit multiple times
if (delegation.endPeriod != type(uint32).max) {
revert DelegationExitAlreadyRequested();
}
$.protocolStakerContract.signalDelegationExit(delegationId);
} else {
revert InvalidDelegationStatus(_tokenId, delegation.status);
}
// decrease the effective stake
// Get the latest completed period of the validator
(, , , uint32 completedPeriods) = $.protocolStakerContract.getValidationPeriodDetails(
delegation.validator
);
(, uint32 exitBlock) = $.protocolStakerContract.getDelegationPeriodDetails(delegationId);
// decrease the effective stake
@1> _updatePeriodEffectiveStake($, delegation.validator, _tokenId, completedPeriods + 2, false);
emit DelegationExitRequested(_tokenId, delegation.validator, delegationId, exitBlock);
}Impact Details
References
Proof of Concept
Mitigation / Notes
Previous60150 sc high off by one in claim window lets exited delegations harvest post exit rewardsNext60154 sc high exited delegations can continue claiming vtho rewards for future periods
Was this helpful?