Inefficient Cooldown Process Due to userLastStakeTime Not Being Updated in unstake Function
Summary
Vulnerability Detail
In the StakingRewardsV2 contract, the userLastStakeTime is updated in the _stakeEscrow function but not in the unstake function. This design requires users to stake tokens to initiate the 7-day cooldown period before they can unstake their tokens. This approach is inefficient and user-unfriendly, as it forces users to perform an additional staking operation just to start the cooldown period for unstaking.
Updating userLastStakeTime in the unstake function would streamline the process, allowing users to directly initiate the cooldown period when they intend to unstake their tokens, thereby improving the overall user experience and efficiency of the protocol.
Example Scenario
Current Process:
User stakes tokens, and userLastStakeTime is set to the current block timestamp.
User's userLastStakeTime is now T1.
User wants to unstake tokens but must wait for the 7-day cooldown period.
User stakes additional tokens to reset userLastStakeTime and start the cooldown period.
User's userLastStakeTime is now T2.
After 7 days from T2, the user can unstake tokens.
Proposed Process:
User stakes tokens, and userLastStakeTime is set to the current block timestamp.
User's userLastStakeTime is now T1.
User wants to unstake tokens and initiates the unstake operation.
userLastStakeTime is updated to the current block timestamp during unstaking.
User's userLastStakeTime is now T2.
After 7 days from T2, the user can unstake tokens without needing an additional staking operation.
Impact
Updating userLastStakeTime during unstaking allows users to directly initiate the cooldown period when they intend to unstake their tokens. This eliminates the need for an additional staking operation just to start the cooldown period.
AresAudits
Medium
Inefficient
Cooldown
Process Due touserLastStakeTime
Not Being Updated inunstake
FunctionSummary
Vulnerability Detail
In the
StakingRewardsV2
contract, theuserLastStakeTime
is updated in the_stakeEscrow
function but not in theunstake
function. This design requires users to stake tokens to initiate the 7-day cooldown period before they can unstake their tokens. This approach is inefficient and user-unfriendly, as it forces users to perform an additional staking operation just to start the cooldown period for unstaking.Updating
userLastStakeTime
in theunstake
function would streamline the process, allowing users to directly initiate the cooldown period when they intend to unstake their tokens, thereby improving the overall user experience and efficiency of the protocol.Example Scenario
userLastStakeTime
is set to the current block timestamp.userLastStakeTime
is nowT1
.userLastStakeTime
and start the cooldown period.userLastStakeTime
is nowT2
.T2
, the user can unstake tokens.userLastStakeTime
is set to the current block timestamp.userLastStakeTime
is nowT1
.userLastStakeTime
is updated to the current block timestamp during unstaking.userLastStakeTime
is nowT2
.T2
, the user can unstake tokens without needing an additional staking operation.Impact
Updating
userLastStakeTime
during unstaking allows users to directly initiate the cooldown period when they intend to unstake their tokens. This eliminates the need for an additional staking operation just to start the cooldown period.Code Snippet
https://github.com/sherlock-audit/2024-07-kwenta-staking-contracts/blob/0527fb7425206a3338c23177416436c6286cedf9/token/contracts/StakingRewardsV2.sol#L252C5-L271C6
Tool used
Manual Review
Recommendation