# Incorrect earnings calculation in `removeValueSingle()` function causes partial user losses

In Burve's removeValueSingle, asset.remove() runs before closure update, so collect() reads stale earnings-per-value and users lose part of accrued earnings.

- Payout: Audit contest
- Severity: medium
- Program: Burve
- Found by: Drynooo
- Disclosed: 2025-04-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-04-burve-judging/issues/422
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-04-burve%3AM-6
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** ValueFacet.removeValueSingle / Asset.collect earnings accounting
**Root cause:** ValueFacet.removeValueSingle calls asset.remove() (which invokes collect()) before the closure's removeValueSingle updates earnings-per-value, so collect() uses an outdated earnings-per-value value.
**Steps:**
1. Deploy Burve diamond; user calls `valueFacet.addValue(user, cid, addValue, bgtValue)` to add liquidity.
2. Distribute vault rewards to closures so earnings-per-value should increase.
3. Without a prior trimBalances, user calls `valueFacet.removeValueSingle(user, cid, addValue, bgtValue, token, 0)`.
4. asset.remove() -> collect() reads stale earnings-per-value before closure update, under-crediting earnings.
5. Compare with a run where a random user's addValue triggers trimBalances first; collected earnings differ.
**How found:** Code reading of ValueFacet.removeValueSingle ordering: noticed asset.remove() precedes closure.removeValueSingle(), and that Asset.collect() pulls earnings-per-value from the closure, implying stale reads.
**Exploitation:** User simply calls removeValueSingle when earnings-per-value is stale (pool inactive); the premature collect() under-credits their earnings, causing >1% loss of accrued earnings.
**Insight:** When a facet mutates shared accounting state, check call ordering between asset-level collect() and closure-level state updates; stale reads of earnings-per-value silently underpay users.

