# The collateral remainder cap is incorrectly calculated during liquidation

Size liquidation caps the collateral remainder at crLiquidation (130%) instead of the excess (crLiquidation - 100%), so higher-CR borrowers lose more to protocol fees.

- Payout: Audit contest
- Severity: high
- Program: Size
- Found by: ether\_sky
- Disclosed: 2024-09-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-06-size-findings/issues/70
- Library page: https://bugbountylibrary.com/r/c4%3A2024-06-size%3AH-03
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:liquidation

**Target:** Solidity lending protocol liquidation logic (executeLiquidate)
**Root cause:** The collateral remainder cap is computed as debtInCollateralToken * crLiquidation / PERCENT, but the remainder should only cover the excess over the debt, i.e. crLiquidation - PERCENT. The cap therefore equals the full liquidation CR rather than the 30% excess, so it never binds and the protocol fee is taken on the entire remainder.
**Steps:**
1. Deploy Size, set crLiquidation = 130%, overdueCollateralProtocolPercent as configured.
2. Open two overdue debt positions with equal debt (60e6) but different collateral: Bob 100e18 (140% CR), Candy 120e18 (150% CR).
3. Warp past maturity and set price 1:1.
4. Call liquidate on both positions.
5. Observe collateralRemainderCap = debtInCollateralToken * 130% = 78e18 for both, exceeding both remainders (40e18, 60e18), so the cap never applies.
6. Protocol profit = remainder * collateralProtocolPercent, so Candy (higher CR) pays more fee than Bob.
**How found:** Code review of executeLiquidate: noticed the cap uses crLiquidation directly rather than the excess over 100%, then built a differential PoC comparing two borrowers with different CRs to show the cap never binds and higher CR loses more.
**Exploitation:** No attacker profit; the flaw is an accounting error that penalizes higher-collateral borrowers during overdue liquidation, transferring excess collateral to the protocol fee recipient proportionally to their excess collateral rather than capping it at the 30% excess.
**Insight:** When a formula caps a 'remainder' or 'excess' against a ratio that already includes the base (e.g. 130% CR), check whether the base must be subtracted; differential tests across two collateral ratios expose caps that never bind.

