60028 sc high a delegator who has requested an exit continues to accumulate rewards
#60028 [SC-High] A delegator who has requested an exit continues to accumulate rewards
Description
Brief/Intro
Vulnerability Details
function _claimableDelegationPeriods(
StargateStorage storage $,
uint256 _tokenId
) private view returns (uint32, uint32) {
// get the delegation
uint256 delegationId = $.delegationIdByTokenId[_tokenId];
// if the token does not have a delegation, return 0
if (delegationId == 0) {
return (0, 0);
}
(address validator, , , ) = $.protocolStakerContract.getDelegation(delegationId);
if (validator == address(0)) {
return (0, 0);
}
(uint32 startPeriod, uint32 endPeriod) = $
.protocolStakerContract
.getDelegationPeriodDetails(delegationId);
(, , , uint32 completedPeriods) = $.protocolStakerContract.getValidationPeriodDetails(
validator
);
// current validator period is the next period because
// the current period is the one that is not completed yet
uint32 currentValidatorPeriod = completedPeriods + 1;
// next claimable period is the last claimed period + 1
uint32 nextClaimablePeriod = $.lastClaimedPeriod[_tokenId] + 1;
// if the next claimable period is before the start period, set it to the start period
if (nextClaimablePeriod < startPeriod) {
nextClaimablePeriod = startPeriod;
}
// check first for delegations that ended
// endPeriod is not max if the delegation is exited or requested to exit
// if the endPeriod is before the current validator period, it means the delegation ended
// because if its equal it means they requested to exit but the current period is not over yet
if (
endPeriod != type(uint32).max &&
endPeriod < currentValidatorPeriod &&
@> endPeriod > nextClaimablePeriod
) {
return (nextClaimablePeriod, endPeriod);
}
// check that the start period is before the current validator period
// and if it is, return the start period and the current validator period.
// we use "less than" because if we use "less than or equal", even
// if the delegation started, the current period rewards are not claimable
if (nextClaimablePeriod < currentValidatorPeriod) {
return (nextClaimablePeriod, completedPeriods);
}
// the rest are either pending, non existing or are active but have no claimable periods
return (0, 0);
}Impact Details
References
Proof of Concept
Previous60027 sc high stuck funds for the later delegators due to an edge case led to double decreasing effective stakesNext60049 sc high double effective stake decrement locks delegators unstake reverts due to duplicate effectivestake decrements in exit flow
Was this helpful?