Liquidation won’t work when bad and safe collateral ratio are set to default values
The function that computes the bad collateral ratio subtracts a fixed value from the safe collateral ratio, but the safe ratio can be zero when default values are used, causing an underflow and a revert. This blocks the liquidation flow when default ratios are in effect.
Submitted by T1MOH, also found by devival, KupiaSec, kenta, RedTiger, and y51r
getBadCollateralRatio() will revert because of underflow, if vaultBadCollateralRatio[pool] and vaultSafeCollateralRatio[pool] are set to 0 (i.e. using default ratios 150% and 130% accordingly). It blocks liquidation flow.
Proof of Concept
1e19 is decremented from value vaultSafeCollateralRatio[pool]:
function getBadCollateralRatio(address pool) external view returns(uint256) {
if(vaultBadCollateralRatio[pool] == 0) return vaultSafeCollateralRatio[pool] - 1e19;
return vaultBadCollateralRatio[pool];
}
However, vaultSafeCollateralRatio[pool] can be set to 0, which should mean 160%:
function getSafeCollateralRatio(
address pool
) external view returns (uint256) {
if (vaultSafeCollateralRatio[pool] == 0) return 160 * 1e18;
return vaultSafeCollateralRatio[pool];
}
As a result, incorrect accounting block liquidation when using default values.
Also, I think this is similar issue, but different impact; therefore, described in this issue. BadCollateralRatio can’t be set when SafeCollateralRatio is default, as newRatio must be less than 10%:
function setBadCollateralRatio(address pool, uint256 newRatio) external onlyRole(DAO) {
require(newRatio >= 130 * 1e18 && newRatio <= 150 * 1e18 && newRatio <= vaultSafeCollateralRatio[pool] + 1e19, "LNA");
...
}
Tools Used
Manual Review
Recommended Mitigation Steps
Instead of internal accessing variables, use functions getSafeCollateralRatio() and getBadCollateralRatio() in all the occurences because variables can be zero.
Assessed type
Invalid Validation
0xean (judge) decreased severity to Medium
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the getBadCollateralRatio function reads the raw storage variable instead of the getter that substitutes the default value, so a zero safe ratio causes an underflow.
Impact
Liquidation is blocked when the default collateral ratios are used, which could leave bad debt unaddressed.
What the attacker needed
Default ratios in use (stored values zero)
The fix
The code should use the getter functions getSafeCollateralRatio and getBadCollateralRatio everywhere instead of reading the raw variables, so defaults are applied.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract stores collateral ratios for a lending pool. When the stored safe ratio is zero, the code is supposed to treat it as a default value, but one function forgets this and subtracts from zero, which makes the transaction fail. As a result, liquidations cannot happen while the defaults are in use.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.