# Users can be liquidated prematurely because calculation understates value of underlying position

Blueberry's getPositionRisk values collateral using stale underlyingAmount that ignores accrued interest, undervaluing positions and enabling premature liquidation of users.

- Payout: Contest reward
- Severity: high
- Program: Blueberry
- Credited: obront
- Disclosed: 2023-02-01
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/126
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-02-blueberry%3AH-7
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:liquidation

**Target:** BlueBerryBank lending/risk engine (getPositionRisk, CoreOracle.getUnderlyingValue)
**Root cause:** pos.underlyingAmount is only set at lend() time and never incremented for interest earned, so getUnderlyingValue understates collateral value in the liquidation health check.
**Steps:**
1. Call lend() to deposit underlying tokens; pos.underlyingAmount is set to the deposited amount.
2. Interest accrues on the deposit but pos.underlyingAmount is never updated.
3. getPositionRisk() computes cv = oracle.getUnderlyingValue(pos.underlyingToken, pos.underlyingAmount) using the stale amount.
4. Liquidation check ((borrowsValue - collateralValue) / underlyingValue) >= underlyingLiqThreshold triggers earlier than it should.
5. Attacker/liquidator liquidates the position prematurely, seizing collateral.
**How found:** Code reading: traced where pos.underlyingAmount is written and observed lend() is the only place it increases, never accounting for interest, then connected that to the liquidation health formula.
**Exploitation:** A liquidator monitors positions whose true value (including accrued interest) keeps them healthy but whose stale underlyingAmount makes them appear underwater, then calls the liquidation path to seize collateral at a discount.
**Insight:** In lending protocols, audit every field used in the health-factor formula and verify it tracks the true economic value (vault shares/interest) rather than a snapshot stored at deposit time; stale accounting fields are a recurring premature-liquidation vector.
