Skip to content
Business logic Audit finding Intermediate

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.

T1MOH Follow with devival, KupiaSec and 3 others

Originally disclosed on Code4rena

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%:

https://github.com/code-423n4/2023-06-lybra/blob/5d70170f2c68dbd3f7b8c0c8fd6b0b2218784ea6/contracts/lybra/configuration/LybraConfigurator.sol#L127

    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

LybraFinance confirmed


The original report as published on Code4rena, by T1MOH. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by T1MOH

View all

11 more disclosed reports, best first.

More from Lybra Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.