Skip to content
Business logic Audit finding Intermediate

doesn’t calculate the current borrowing amount for the provider, including the provider’s borrowed shares and accumulated fees due to inconsistency in collateralRatio calculation

The collateral ratio calculation in the rigidRedemption function uses only the borrowed amount, ignoring borrowed shares and accumulated fees, unlike the liquidation function which uses getBorrowedOf. This inconsistency could allow a provider to redeem more than they should, potentially causing a loss to the protocol.

turvy_fuzz Follow with SpicyMeatball

Originally disclosed on Code4rena

Submitted by turvy_fuzz, also found by SpicyMeatball

Lines of code

https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/pools/base/LybraPeUSDVaultBase.sol#L127

Proof of Concept

Borrowers collateralRatio in the liquidation() function is calculated by:

uint256 onBehalfOfCollateralRatio = (depositedAsset[onBehalfOf] * assetPrice * 100) / getBorrowedOf(onBehalfOf);

Notice it calls the getBorrowedOf() function, which calculates the current borrowing amount for the borrower, including the borrowed shares and accumulated fees, not just the borrowed amount.

https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/pools/base/LybraPeUSDVaultBase.sol#L253

function getBorrowedOf(address user) public view returns (uint256) {
        return borrowed[user] + feeStored[user] + _newFee(user);
    }

However, the providers collateralRatio in the rigidRedemption() function is calculated by:

https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/pools/base/LybraPeUSDVaultBase.sol#L161

uint256 providerCollateralRatio = (depositedAsset[provider] * assetPrice * 100) / borrowed[provider];

Here, the deposit asset is divided by only the borrowed amount, missing out on the borrowed shares and accumulated fees.

Tools Used

Visual Studio Code

Recommended Mitigation Steps

Be consistent with collateralRatio calculation.

LybraFinance confirmed


The original report as published on Code4rena, by turvy_fuzz. 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

What the attacker needed

Provider has borrowed with accumulated fees

The fix

The collateral ratio calculation in rigidRedemption should use getBorrowedOf(provider) instead of borrowed[provider] to be consistent with the liquidation function.

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.

In a lending system, your collateral ratio shows how much you've borrowed compared to your deposit. This report found that one function calculates that ratio incorrectly by leaving out fees and shared borrowing, which could let someone take out more than they're allowed.

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 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.