No cooldown in `recoverUnstaking()`, opens up several possible attacks by abusing this functionality
The recoverUnstaking() function lacks a cooldown, allowing a user to unstake and restake to the same validator at any time. An attacker could abuse this to deny delegators from staking to a target validator or to steal staking rewards by front-running reward distribution.
Source: https://github.com/sherlock-audit/2023-11-covalent-judging/issues/52
Found by
PUSH0
Summary
The function recoverUnstaking() allows a user to recover any of their unstaking to the same validator.
However, the function has no cooldown, i.e. a user can unstake and restake to the same validator at any time they prefer.
We describe several attack vectors that may arise from this issue.
Vulnerability Detail
When a user unstakes, they must wait for a cooldown of 28 days (180 days if validator) before being able to withdraw. The user also has the choice to revert the action, and re-stake said amount back to the same validator by calling recoverUnstaking().
However, the function recoverUnstaking() has no cooldowns. In other words, a user can re-stake as many times as they like, at any time they prefer, without being subject to the unstaking cooldown.
This opens up several possible attack vectors by abusing the lack of cooldown of this functionality.
Next section we describe some of the possible attack vectors.
Denying delegators for any validators
An attacker with a large enough capital can do the following to deny a target validator from getting delegated stakings:
- Max stake to the target validator, up to
staked * maxCapMultiplier, but immediately unstake. - Whenever someone stakes, front-run them with a
recoverUnstaking(), re-staking their max stake. - The user's stake tx fails, as the attacker has taken up the maximum possible stake.
- The attacker then unstakes, able to repeat the attack when necessary.
The impact is that a validator can be denied from getting delegators.
Stealing of rewards
This attack vector builds upon a separate issue we have submitted, about unfair distribution of rewards for mid-epoch stakers.
An attacker can perform the following, while greatly de-risking themselves from staking.
- Stake an amount they want, but unstake.
- Listen to the staking manager's
rewardValidators()with the intent of front-running. - If the attacker choose to, front-run
rewardValidators()calls, unfairly taking a share of the rewards. - Unstake.
The attacker benefits from the following:
- While unstaking, their 28-day cooldown still counts. They greatly de-risk themselves by being able to choose whether or not to steal rewards (and reset countdown), or to take profits.
- Unstakings from frozen validators can still be withdrawn once the cooldown has passed. By keeping themselves in an unstaking state, they bypass the freezing mechanism.
- They eliminate the risk from other standard staking mechanism, should they be implemented in the future (e.g. slashing).
Impact
recoverUnstaking() can be abused, opens up several possible attack vectors, with varying impacts (shown above).
Code Snippet
Tool used
Manual Review
Recommendation
Implement a cooldown for recoverUnstaking(). A short cooldown (e.g. a few days) is sufficient.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
takarez commented:
invalid: the coolDown is in place for withdrawing tokens not for reStaking 'em
noslav
fixed by implement recoverUnstakingCoolDown period for recoverUnstaking levera…
noslav
supporting fixes by https://github.com/covalenthq/cqt-staking/commit/a609cca0426cb22cbf5064212341c14c288efeda
CergyK
Fix LGTM
sherlock-admin
The protocol team fixed this issue in PR/commit https://github.com/covalenthq/cqt-staking/pull/125/commits/e7ab9ab7eb89f47669dfc0c4ef175f6ca074328b.
sherlock-admin
The Lead Senior Watson signed off on the fix.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The recoverUnstaking() function does not enforce a cooldown, unlike the unstaking process.
Impact
A validator could be denied delegators, and an attacker could steal staking rewards by front-running reward distribution, while also bypassing validator freezing and avoiding slashing risks.
What the attacker needed
Large capital to stake up to max cap; ability to front-run transactions
The fix
The issue was fixed by implementing a cooldown period for recoverUnstaking().
How it was found
- Stake a large amount to the target validator, up to the maximum cap.
- Immediately unstake that amount.
- When someone else tries to stake to the validator, front-run their transaction with a call to recoverUnstaking() to re-stake the maximum amount.
- The victim's stake transaction fails because the attacker has taken up the maximum stake.
- The attacker then unstakes again, ready to repeat the attack.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you unstake tokens, you normally have to wait a cooldown period before you can withdraw them. This report says that a function meant to let you undo an unstaking has no such waiting period, so you can quickly unstake and restake. An attacker could use this to block others from staking to a validator or to unfairly grab rewards.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.