# rounding error due to internal accounting and can steal some portion of the first depositors  funds

First depositor can manipulate share price via rounding in Sentiment V2 pool, causing subsequent depositors to lose up to 33% of funds.

- Payout: Audit contest
- Severity: high
- Program: Sentiment
- Found by: Obsidian
- Disclosed: 2024-08-07
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-08-sentiment-v2-judging/issues/597
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-sentiment-v2%3AH-3
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high technique:source-review vuln:accounting-error vuln:share-inflation

**Target:** Pool contract deposit/withdraw share accounting
**Root cause:** Pool uses balanceOf(address(this)) for total assets and rounds down when minting shares, allowing an attacker to inflate share price by repeatedly depositing and withdrawing tiny amounts while total shares remain 1.
**Steps:**
1. Attacker mints and deposits some collateral sufficient to borrow assets.
2. Borrows a few assets, waits ~100 seconds for >1 wei interest, repays all.
3. Directly transfers assets to pool to make totalAssets > totalDepositAssets.
4. Withdraws all but 2 wei of shares, leaving totalDepositShares=1 and totalDepositAssets=2.
5. Loops: deposit totalDeposits+1 assets, receive 1 share (due to rounding down), then withdraw 1 share. Total shares stays 1, totalDeposits grows exponentially.
6. Victim deposits assets, receives shares based on inflated price, losing up to 33% of their assets.
**How found:** Researcher noticed that total assets are calculated via balanceOf(address(this)) and that share minting rounds down. They hypothesized that with totalShares=1, depositing totalDeposits+1 would mint only 1 share, allowing repeated deposits to inflate share price.
**Exploitation:** Attacker first deposits minimal amount, then uses borrow/repay to accrue interest and direct transfers to set totalAssets=2, totalShares=1. Then repeatedly deposits increasing amounts (2^i+1) and withdraws 1 share, each time receiving only 1 share due to rounding, exponentially increasing totalAssets while shares stay 1. When victim deposits, they get fewer shares than fair, and attacker can withdraw inflated value.
**Insight:** When a pool's total assets are derived from token balance and share minting rounds down, an attacker can keep total shares at 1 and repeatedly deposit just over the current total assets to mint 1 share, exponentially inflating share price. Check for this pattern in first-depositor scenarios.

