Skip to content
Business logic Audit finding Intermediate

Borrower can obtain principle tokens without paying collateral tokens

A borrower could obtain principal tokens without paying any collateral because the collateral calculation rounds down to zero for small loan amounts. By exploiting this rounding error, an attacker could repeatedly borrow small amounts and drain the protocol's funds.

xiaoming90 Follow

Originally disclosed on Sherlock

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

Found by

xiaoming90

Summary

No response

Root Cause

No response

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

Assume that the ratio/price is 1e18 (1 XYZ per ABC => Principle per Collateral). XYZ is 18 decimals while ABC is 6 decimals.

Assume that Bob (malicious borrower) calls the permissionless DebitaV3Aggregator.matchOffersV3 function. The amount of collateral deducted from Bob's borrow offer is calculated via the following:

Solidity
userUsedCollateral = (lendAmountPerOrder[i] * (10 ** decimalsCollateral)) / ratio;
userUsedCollateral = (lendAmountPerOrder[i] * 1e6) / 1e18;

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

Solidity
File: DebitaV3Aggregator.sol
274:     function matchOffersV3(
..SNIP..
466:             // calculate the amount of collateral used by the lender
467:             uint userUsedCollateral = (lendAmountPerOrder[i] *
468:                 (10 ** decimalsCollateral)) / ratio;

For lendAmountPerOrder, he uses a value that is small enough to trigger a rounding to zero error. The range of lendAmountPerOrder that will cause userUsedCollateral to round down to zero is:

$0≤lendAmountPerOrder<10^{12}$

Thus, for each offer, Bob will specify the lendAmountPerOrder[i] to be 1e12 - 1. Thus, for each offer, he will be able to obtain 1e12 - 1 XYZ tokens without paying a single ABC tokens as collateral.

This attack is profitable because each matchOffersV3 transaction can execute up to 100 offers, and the protocol is intended to be deployed on L2 chains where gas fees are extremely cheap or even negligible.

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

Solidity
File: DebitaV3Aggregator.sol
274:     function matchOffersV3(
..SNIP..
289:         // check lendOrder length is less than 100
290:         require(lendOrders.length <= 100, "Too many lend orders");

Following is the extract from Contest's README showing that the protocol will be deployed to following L2 chains.

Q: On what chains are the smart contracts going to be deployed?

Sonic (Prev. Fantom), Base, Arbitrum & OP

Impact

High. Loss of assets.

PoC

No response

Mitigation

This issue can be easily mitigated by implementing the following changes to prevent the above attack.

Diff
// calculate the amount of collateral used by the lender
uint userUsedCollateral = (lendAmountPerOrder[i] * (10 ** decimalsCollateral)) / ratio;
+ require(userUsedCollateral > 0, "userUsedCollateral is zero")

Discussion

sherlock-admin2

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

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

The collateral calculation uses integer division that truncates to zero for small loan amounts, and there is no check to ensure the result is greater than zero.

Impact

The attacker could drain the protocol's assets by repeatedly borrowing small amounts without collateral, and the low gas fees on L2 chains make this economically viable.

What the attacker needed

None

The fix

The issue was fixed by adding a check that the calculated collateral is greater than zero.

How it was found

  1. Call the permissionless matchOffersV3 function with a borrow offer.
  2. Set lendAmountPerOrder to a value just below the threshold that causes rounding to zero.
  3. Receive principal tokens without any collateral being deducted.

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.

When you borrow, the system calculates how much collateral you must lock up. If that calculation rounds down to zero because the loan amount is very small, you get the loan for free. An attacker can repeat this many times to steal funds.

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 xiaoming90

View all

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