Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash - New depositors can loose their assets due to existing shares when totalAssets is 0 following a bad debt rebalance #584

Closed
sherlock-admin2 opened this issue Aug 24, 2024 · 8 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected Medium A Medium severity issue. Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Aug 24, 2024

hash

Medium

New depositors can loose their assets due to existing shares when totalAssets is 0 following a bad debt rebalance

Summary

New depositors can loose their assets due to existing shares even when totalAssets is 0

Vulnerability Detail

Having 0 totalAssets and non-zero shares is a possible scenario due to rebalacne

    function rebalanceBadDebt(uint256 poolId, address position) external {
        
        ....
        //@auidt decreases totalDepositAssets while shares can be non-zero
        uint256 totalDepositAssets = pool.totalDepositAssets;
        pool.totalDepositAssets = (totalDepositAssets > borrowAssets) ? totalDepositAssets - borrowAssets : 0;

In such a case, if a new user deposits, it will not revert but instead mint shares 1:1 with the assets. But as soon as it is minted, the value of the user's share will decrease because of the already existing shares

    function deposit(uint256 poolId, uint256 assets, address receiver) public returns (uint256 shares) {
        
        ....

        shares = _convertToShares(assets, pool.totalDepositAssets, pool.totalDepositShares, Math.Rounding.Down);
    function _convertToShares(
        uint256 assets,
        uint256 totalAssets,
        uint256 totalShares,
        Math.Rounding rounding
    ) internal pure returns (uint256 shares) {
        if (totalAssets == 0) return assets;
        shares = assets.mulDiv(totalShares, totalAssets, rounding);
    }

Eg:
deposit shares = 100, deposit assets = 100, borrow assets = 100
borrow position becomes bad debt and rebalance bad debt is invoked
now deposit shares = 100, deposit assets = 0
new user calls deposit with 100 assets
they get 100 shares in return but share value is now 0.5 and they can withdraw only 50

This can occur if a large position undergoes a rebalance and the others manage to withdraw their assets right before the rebalance (superpool dominated pools can higher chances of such occurence)

Impact

Users can loose their assets when depositing to pools that have freshly undergone rebalanceBadDebt

Code Snippet

https://github.com/sherlock-audit/2024-08-sentiment-v2/blob/0b472f4bffdb2c7432a5d21f1636139cc01561a5/protocol-v2/src/Pool.sol#L275

https://github.com/sherlock-audit/2024-08-sentiment-v2/blob/0b472f4bffdb2c7432a5d21f1636139cc01561a5/protocol-v2/src/Pool.sol#L547

Tool used

Manual Review

Recommendation

If totalShares is non-zero and totalAssets is zero, revert for deposits

Duplicate of #319

@github-actions github-actions bot added Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A Medium severity issue. labels Sep 5, 2024
@sherlock-admin4 sherlock-admin4 changed the title Flat Tawny Haddock - New depositors can loose their assets due to existing shares when totalAssets is 0 following a bad debt rebalance hash - New depositors can loose their assets due to existing shares when totalAssets is 0 following a bad debt rebalance Sep 15, 2024
@sherlock-admin4 sherlock-admin4 added the Reward A payout will be made for this issue label Sep 15, 2024
@samuraii77
Copy link

#319 is a duplicate of this issue

@AtanasDimulski
Copy link

Escalate,
Per the above comment

@sherlock-admin3
Copy link

Escalate,
Per the above comment

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin4 sherlock-admin4 added the Escalated This issue contains a pending escalation label Sep 16, 2024
@elhajin
Copy link

elhajin commented Sep 16, 2024

#209 is also duplicate

@sherlock-admin3 sherlock-admin3 added Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed labels Sep 17, 2024
@cvetanovv
Copy link
Collaborator

I agree with the comments that #584, #381, #598, and #209 are duplicates of #319.

Planning to accept the escalation and duplicate these issues with #319.

@WangSecurity WangSecurity added Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label and removed Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Sep 23, 2024
@WangSecurity
Copy link

WangSecurity commented Sep 23, 2024

Result:
Medium
Duplicate of #319

@sherlock-admin2
Copy link
Contributor Author

sherlock-admin2 commented Sep 23, 2024

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin3 sherlock-admin3 removed the Escalated This issue contains a pending escalation label Sep 23, 2024
@sherlock-admin4 sherlock-admin4 added the Escalation Resolved This issue's escalations have been approved/rejected label Sep 23, 2024
@sherlock-admin2
Copy link
Contributor Author

The protocol team fixed this issue in the following PRs/commits:
sentimentxyz/protocol-v2#332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected Medium A Medium severity issue. Reward A payout will be made for this issue Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

8 participants