# `_computeClosingFactor` function will return incorrect values, lower than needed, because it uses `collateralizationRate` to calculate the denominator

Tapioca's _computeClosingFactor used collateralizationRate (75%) instead of liquidationCollateralizationRate (80%) in the denominator, under-computing liquidation amounts and leaving users still liquidatable.

- Payout: Contest reward
- Severity: high
- Program: Tapioca
- Credited: cergyk
- Disclosed: 2024-02-14
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/53
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-02-tapioca%3AH-5
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:business-logic vuln:liquidation

**Target:** Market contract _computeClosingFactor (BigBang/Singularity lending markets)
**Root cause:** The denominator uses collateralizationRate (75%) while the liquidation threshold and numerator use liquidationCollateralizationRate (80%), so the computed closing factor is smaller than the amount actually needed to restore solvency.
**Steps:**
1. Note _isSolvent() uses liquidationCollateralizationRate (80%) as the liquidation threshold.
2. Read _computeClosingFactor: liquidationStartsAt = collateralPartInAsset * _liquidationCollateralizationRate / ratesPrecision.
3. numerator = borrowPart - liquidationStartsAt.
4. denominator = (1e18 - collateralizationRate*(1e18+_liquidationMultiplier)/1e18) * 1e13, using collateralizationRate=75% and multiplier=12%.
5. Result x = numerator / 16%, but the true amount to restore solvency with liquidationBonusAmount=10% is numerator / 12%.
6. Partial liquidation therefore leaves the position still undercollateralized and liquidatable again.
**How found:** Code reading: compared the rate used in _isSolvent() (liquidationCollateralizationRate) against the rate used in the _computeClosingFactor denominator (collateralizationRate) and recomputed the algebra with default parameters.
**Exploitation:** A liquidator performs a partial liquidation; because the closing factor is under-computed, the user remains below the solvency threshold and can be liquidated repeatedly until fully liquidated, causing excess loss to the borrower.
**Insight:** When a protocol has two similar rate parameters (collateralizationRate vs liquidationCollateralizationRate), check every formula that mixes them; recompute the closing-factor algebra with actual default bonus values to confirm the liquidation actually restores solvency.
