Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

rvierdiiev - assetState_.lastRewardGlobal is not cleared during deposit #26

Closed
sherlock-admin opened this issue Feb 16, 2024 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Feb 16, 2024

rvierdiiev

high

assetState_.lastRewardGlobal is not cleared during deposit

Summary

When new deposit is done to the stargate, then all earned rewards are sent to the caller. Because assetState_.lastRewardGlobal is not reset to 0 as it's done for other functions that work with balance, then rewards distribution becomes incorrect and broken.

Vulnerability Detail

User can claim rewards using burn, decreaseLiquidity and claimReward functions. All of them then set assetState_.lastRewardGlobal to 0. This variable tracks the increase of earned rewards fro the contract between rewards claiming. Once rewards are claimed, then it should be cleared.

AbstractStakingAM contract incorrectly assumes, that only withdrawing from LP_STAKING_TIME claims rewards. This is not true and when deposit occurs, then rewards are claimed as well.

When user deposits to AbstractStakingAM then rewards are claimed, but assetState_.lastRewardGlobal is not set to 0. As result, rewards distribution will be incorrect. Also for some time _getRewardBalances function will revert because of underflow as _getCurrentReward will likely return smaller value than assetState_.lastRewardGlobal. After some time function will continue working again.

Impact

Rewards accounting is corrupted, contract can be dosed for some time.

Code Snippet

Provided above

Tool used

Manual Review

Recommendation

As deposit also claims rewards, then you need to clear assetState_.lastRewardGlobal variable.

Duplicate of #38

@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Feb 21, 2024
@nevillehuang nevillehuang added Medium A valid Medium severity issue and removed High A valid High severity issue labels Feb 27, 2024
@sherlock-admin2 sherlock-admin2 changed the title Furry Midnight Unicorn - assetState_.lastRewardGlobal is not cleared during deposit rvierdiiev - assetState_.lastRewardGlobal is not cleared during deposit Feb 28, 2024
@sherlock-admin2 sherlock-admin2 added the Reward A payout will be made for this issue label Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

3 participants