Skip to content
Business logic Audit finding Intermediate

An attacker can steal the entire borrow and lending incentive of an epoch with FLASHLOAN in a single transaction

The report describes a flaw in a lending protocol where an attacker can use a flash loan to create a huge lend offer and a borrow offer with dust collateral, self-match them, repay in the same block, and then claim nearly all epoch incentives. The attacker profits by stealing a larger share of the borrow and lending incentives.

BengalCatBalu Follow with CL001, Feder and 10 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-10-debita-judging/issues/708

Found by

BengalCatBalu, CL001, Feder, KaplanLabs, KlosMitSoss, Pablo, bbl4de, dimulski, lanrebayode77, mike-watson, pashap9990, tjonair, xiaoming90

Summary

An attacker, with the aid of flash-loan can steal the entire borrow and lending incentives.

This involves the attacker creating a huge lend offer with funds from flash-loan, creating a borrow offer with dust amount as collateral, self-matching the offer, paying back the loan in the same block(with zero interest) and having extra principle to payback flash-loan fees, then claim the entire incentive after the epoch has ended.

Root Cause

  1. Same address can be the borrower, lender and connector, there is no check against this.
  2. DebitaV3Loan.payDebt() allows repayment of loan in the same block it was taken. (Allows the use of flash-loan to access huge funds!)
  3. Lender can set ratio high enough to allow borrower take huge loan with dust collateral(1wei).(this reduced flash-loan needed as 1wei can be used as collateral to get unlimited principle amount reduce fees(flash-loan) and make attack more feasible/profitable).

Internal pre-conditions

Incentive is huge enough to cover attack expenses(flash-loan fees, loan disbursement fee and off-cus gasFee!)

External pre-conditions

  1. Attacker has extra principle to cover flash-loan fees(0.05% in Aave V3)
  2. Attack capital becomes lower when the borrow/lend inn the current epoch is low

Attack Path

  1. Attacker takes in account the amount of incentives and total borrow/lent of the current epoch to determine profitability and also to know if there is capital(flash-loan fee).
  2. Attacker takes flash-loan, in the flash loan call-back,
  3. A block to the end of an epoch, creates a lend offer with HUGE ratio!(100e24 for instance) allowing borrowing huge amount with 1wei, no check/limit for this
  4. creates a borrow offer using 1wei as collateral
  5. calls matchOfferV3(), matching the offers, min fee of 0.2% is deducted in which 15% of it goes back to attacker, so only 0.17% net paid as fees
  6. pays back by calling payDebt(), offcus no fee on interest since Apr is set to zero
  7. pays back flash-loan and fees
  8. epoch ends, and attacker claims almost all incentives(borrow + lend) in the next block(after the end of the epoch), since lent and borrow will be almost 100%, thanks to FLASH-LOAN!

Impact

Attacker steals larger share of incentives

PoC

Repayment is possible in the same block! the only tiime check is for deadline

Solidity
        // check next deadline
        require(
            nextDeadline() >= block.timestamp,
            "Deadline passed to pay Debt"
        );

https://github.com/sherlock-audit/2024-11-debita-finance-v3/blob/main/Debita-V3-Contracts/contracts/DebitaV3Loan.sol#L186-L257

Solidity
  } else {
                maxRatio = lendInfo.maxRatio[collateralIndex]; //@audit attacker set this to be large to allow the use of dust collateral
            }
            // calculate ratio based on porcentage of the lend order
            uint ratio = (maxRatio * porcentageOfRatioPerLendOrder[i]) / 10000;
            uint m_amountCollateralPerPrinciple = amountCollateralPerPrinciple[
                principleIndex
            ];
            // calculate the amount of collateral used by the lender
            uint userUsedCollateral = (lendAmountPerOrder[i] *
                (10 ** decimalsCollateral)) / ratio; //@audit collateral required for large loan becomes dust!
Solidity
   // check ratio for each principle and check if the ratios are within the limits of the borrower
        for (uint i = 0; i < principles.length; i++) {
            require(
                weightedAverageRatio[i] >= //@audit attacker set both, so this aligns!
                    ((ratiosForBorrower[i] * 9800) / 10000) &&
                    weightedAverageRatio[i] <=
                    (ratiosForBorrower[i] * 10200) / 10000,
                "Invalid ratio"
            );
Solidity
// check if the apr is within the limits of the borrower
            require(weightedAverageAPR[i] <= borrowInfo.maxApr, "Invalid APR"); //@audit Apr is set to zero, so no fee on interest!

Mitigation

  1. Prevent repayment in the same block
  2. It might be helpful to prevent lender == borrower == connector

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/DebitaFinance/Debita-V3-Contracts/commit/bc889a3d624b8376c9be43f5421a78448bdaca20

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

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 lack of checks preventing the same address from acting as lender, borrower, and connector, combined with allowing repayment in the same block and no limit on the collateral ratio, enables the attack.

Impact

The attacker could steal a larger share of the incentives, potentially the entire epoch's borrow and lending incentives, as the text claims.

What the attacker needed

Incentives large enough to cover costs; Attacker has extra principal for flash loan fees; Flash loan available (e.g., Aave V3)

The fix

The protocol team fixed this issue by preventing repayment in the same block and possibly preventing the same address from being lender, borrower, and connector.

How it was found

  1. Attacker calculates profitability based on current epoch incentives and total borrow/lend amounts.
  2. Attacker takes a flash loan and in the callback creates a lend offer with a huge ratio.
  3. Attacker creates a borrow offer using 1 wei as collateral.
  4. Attacker calls matchOfferV3() to match the offers, paying a small fee.
  5. Attacker repays the loan immediately by calling payDebt(), with zero interest.
  6. Attacker repays the flash loan and after the epoch ends claims almost all incentives.

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.

This is about a lending platform that rewards people for lending and borrowing. An attacker can use a temporary large loan (flash loan) to pretend to lend and borrow a lot, then quickly repay and collect almost all the rewards meant for everyone. The platform did not stop someone from being both the lender and borrower, or from repaying immediately.

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 BengalCatBalu

View all

3 more disclosed reports, best first.

More from Debita Finance V3

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.