# Attacker can steal 100% of users deposits

First depositor donates large amount to inflate virtualTotal, causing subsequent depositors to mint 0 shares while attacker withdraws all funds.

- Payout: Audit contest
- Severity: medium
- Program: Allbridge Core Yield
- Found by: 0xEkko
- Disclosed: 2025-07-23
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-07-allbridge-core-yield-judging/issues/173
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-07-allbridge-core-yield%3AM-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:share-inflation

**Target:** PortfolioToken.sol deposit/mint share accounting
**Root cause:** _mintAfterTotalChanged returns silently when computed realAmount is 0 instead of reverting, and donated tokens are auto-deposited into rewards pool inflating totalVirtual, enabling share-price inflation.
**Steps:**
1. Attacker calls `deposit(1000 wei)` first to set realTotal=1 wei (pool deposit yields 1 wei).
2. Victim intends to deposit 10e6; attacker front-runs by transferring 10e6 directly to contract, triggering `_subDepositRewardsPoolCheck` which deposits it into pool, inflating totalVirtual to 10e3+1 while realTotal stays 1 wei.
3. Victim's deposit computes `out = (virtualAmount * realTotal) / totalVirtual = (10e3 * 1)/(10e3+1) = 0`, mint returns silently without revert.
4. Attacker calls `withdraw` computing `realTotal * (amount/totalVirtual) = 1 * (20e6/20e6) = 1`, draining donation plus victim funds.
5. Repeat donation on every victim transfer to keep minting 0 shares.
**How found:** Reviewer traced the deposit path into `_subDepositRewardsPoolCheck` and noticed direct transfers are treated as rewards, inflating totalVirtual; then checked `_mintAfterTotalChanged` and saw it returns instead of reverting on zero mint, enabling classic first-depositor share inflation.
**Exploitation:** Attacker seeds 1 wei share, front-runs each victim deposit with a direct token transfer that the contract auto-deposits into the rewards pool, inflating totalVirtual so victim mints round to zero; attacker then withdraws the entire balance with their single share.
**Escalation:** Repeated front-running on every user transfer lets attacker capture 100% of all deposits.
**Insight:** When a contract auto-credits direct token transfers as rewards, the share price can be inflated by any external transfer; check whether zero-share mints revert or silently succeed, since silent success turns donation-based inflation into full theft.

