# The way fees are accounted can break the sorted list order

eBTC's fee accounting lowers totalCollateralSnapshot without moving totalStakesSnapshot, inflating new CDP stakes and letting NICR ordering invert, breaking the sorted list.

- Payout: Contest reward
- Severity: medium
- Program: eBTC Protocol
- Credited: 0xBeirao
- Disclosed: 2024-02-13
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-10-badger-findings/issues/155
- Library page: https://bugbountylibrary.com/r/c4%3A2023-10-badger%3AM-04
- Tags: domain:web3 impact:dos impact:integrity kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:precision-loss

**Target:** CdpManager sorted CDP list / stake accounting
**Root cause:** Fees are allocated out of activePool reducing totalCollateralSnapshot while totalStakesSnapshot stays fixed, so stake = coll*totalStakesSnapshot/totalCollateralSnapshot makes newer CDPs' stakes higher than older ones, changing relative NICR drift.
**Steps:**
1. Open 100 CDPs with 10 ether collateral and 0.5 ether debt, applying +0.2% stETH index change each iteration.
2. Set the last CDP's debt so its NICR is just above the first CDP's NICR.
3. Apply a +40% stETH index change and open one more CDP.
4. Call `cdpManager.getSyncedNominalICR(firstCdpId)` and `getSyncedNominalICR(lastCdpId)`; assert first <= last fails, proving list order broken.
**How found:** Reading Liquity's corrected-stake paper and noticing eBTC's fee split reduces totalCollateralSnapshot without updating totalStakesSnapshot, hypothesizing newer CDPs get inflated stakes and faster NICR decline; confirmed with a Foundry PoC.
**Escalation:** Broken sorted list ordering can lead to non-unique insertion positions, cascading disorder, potential DOS and incorrect redemption ordering.
**Insight:** When porting Liquity's corrected-stake mechanism, check every path that mutates totalCollateralSnapshot or totalStakesSnapshot (fee splits, redistributions) for asymmetric updates that skew stake ratios between old and new troves.
